Commit 1ccb0aa5 authored by Pavel Vainerman's avatar Pavel Vainerman

(Thread): рефакторинг класса ThreadCreator

parent f2402ac2
......@@ -26,6 +26,7 @@
#define ThreadCreator_h_
//----------------------------------------------------------------------------------------
#include <cc++/thread.h>
#include <sys/resource.h>
//----------------------------------------------------------------------------------------
/*! \class ThreadCreator
* Шаблон для создания потоков с указанием функции вызова.
......@@ -93,11 +94,24 @@ class ThreadCreator:
ThreadCreator( ThreadMaster* m, Action a );
~ThreadCreator();
inline pid_t getTID(){ return pid; }
/*! \return 0 - sucess */
int setPriority( int prior );
/*! \return < 0 - fail */
int getPriority();
void stop();
inline void setPriority( int ptior )
inline void setName( const std::string& name )
{
ost::PosixThread::setName( name.c_str() );
}
inline void setName( const char* name )
{
#warning ThreadCreator::setPriority NOT REALIZED YET
ost::PosixThread::setName( name );
}
inline void setCancel( ost::Thread::Cancel mode )
......@@ -134,6 +148,8 @@ class ThreadCreator:
private:
ThreadCreator();
pid_t pid;
ThreadMaster* m;
Action act;
......@@ -147,6 +163,7 @@ class ThreadCreator:
//----------------------------------------------------------------------------------------
template <class ThreadMaster>
ThreadCreator<ThreadMaster>::ThreadCreator( ThreadMaster* m, Action a ):
pid(-1),
m(m),
act(a),
finm(0),
......@@ -159,6 +176,7 @@ ThreadCreator<ThreadMaster>::ThreadCreator( ThreadMaster* m, Action a ):
template <class ThreadMaster>
void ThreadCreator<ThreadMaster>::run()
{
pid = getpid();
if(m)
(m->*act)();
// PosixThread::stop()
......@@ -172,6 +190,7 @@ void ThreadCreator<ThreadMaster>::stop()
//----------------------------------------------------------------------------------------
template <class ThreadMaster>
ThreadCreator<ThreadMaster>::ThreadCreator():
pid(-1),
m(0),
act(0),
finm(0),
......@@ -186,4 +205,16 @@ ThreadCreator<ThreadMaster>::~ThreadCreator()
{
}
//----------------------------------------------------------------------------------------
template <class ThreadMaster>
int ThreadCreator<ThreadMaster>::setPriority( int prior )
{
return setpriority(PRIO_PROCESS, pid, prior );
}
//----------------------------------------------------------------------------------------
template <class ThreadMaster>
int ThreadCreator<ThreadMaster>::getPriority()
{
return getpriority(PRIO_PROCESS, pid);
}
//----------------------------------------------------------------------------------------
#endif // ThreadCreator_h_
......@@ -262,7 +262,7 @@ void ObjectsActivator::work()
try
{
if(orbthr)
thpid = orbthr->getId();
thpid = orbthr->getTID();
else
thpid = getpid();
......
......@@ -874,7 +874,7 @@ void UniSetObject::work()
if( unideb.debugging(Debug::INFO) )
unideb[Debug::INFO] << myname << ": thread processing messages run..." << endl;
if( thr )
msgpid = thr->getId();
msgpid = thr->getTID();
while( isActive() )
{
callback();
......
......@@ -347,7 +347,7 @@ SimpleInfo* SystemGuard::getInfo()
SimpleInfo_var si = ObjectsManager::getInfo();
info << si->info;
if( thr )
info << "\texTID= " << thr->getId();
info << "\texTID= " << thr->getTID();
else
info << "\texpid= " << expid;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment