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

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

parent f2402ac2
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#define ThreadCreator_h_ #define ThreadCreator_h_
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
#include <cc++/thread.h> #include <cc++/thread.h>
#include <sys/resource.h>
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
/*! \class ThreadCreator /*! \class ThreadCreator
* Шаблон для создания потоков с указанием функции вызова. * Шаблон для создания потоков с указанием функции вызова.
...@@ -93,11 +94,24 @@ class ThreadCreator: ...@@ -93,11 +94,24 @@ class ThreadCreator:
ThreadCreator( ThreadMaster* m, Action a ); ThreadCreator( ThreadMaster* m, Action a );
~ThreadCreator(); ~ThreadCreator();
inline pid_t getTID(){ return pid; }
/*! \return 0 - sucess */
int setPriority( int prior );
/*! \return < 0 - fail */
int getPriority();
void stop(); 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 ) inline void setCancel( ost::Thread::Cancel mode )
...@@ -133,6 +147,8 @@ class ThreadCreator: ...@@ -133,6 +147,8 @@ class ThreadCreator:
private: private:
ThreadCreator(); ThreadCreator();
pid_t pid;
ThreadMaster* m; ThreadMaster* m;
Action act; Action act;
...@@ -147,6 +163,7 @@ class ThreadCreator: ...@@ -147,6 +163,7 @@ class ThreadCreator:
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
template <class ThreadMaster> template <class ThreadMaster>
ThreadCreator<ThreadMaster>::ThreadCreator( ThreadMaster* m, Action a ): ThreadCreator<ThreadMaster>::ThreadCreator( ThreadMaster* m, Action a ):
pid(-1),
m(m), m(m),
act(a), act(a),
finm(0), finm(0),
...@@ -159,6 +176,7 @@ ThreadCreator<ThreadMaster>::ThreadCreator( ThreadMaster* m, Action a ): ...@@ -159,6 +176,7 @@ ThreadCreator<ThreadMaster>::ThreadCreator( ThreadMaster* m, Action a ):
template <class ThreadMaster> template <class ThreadMaster>
void ThreadCreator<ThreadMaster>::run() void ThreadCreator<ThreadMaster>::run()
{ {
pid = getpid();
if(m) if(m)
(m->*act)(); (m->*act)();
// PosixThread::stop() // PosixThread::stop()
...@@ -172,6 +190,7 @@ void ThreadCreator<ThreadMaster>::stop() ...@@ -172,6 +190,7 @@ void ThreadCreator<ThreadMaster>::stop()
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
template <class ThreadMaster> template <class ThreadMaster>
ThreadCreator<ThreadMaster>::ThreadCreator(): ThreadCreator<ThreadMaster>::ThreadCreator():
pid(-1),
m(0), m(0),
act(0), act(0),
finm(0), finm(0),
...@@ -186,4 +205,16 @@ ThreadCreator<ThreadMaster>::~ThreadCreator() ...@@ -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_ #endif // ThreadCreator_h_
...@@ -262,7 +262,7 @@ void ObjectsActivator::work() ...@@ -262,7 +262,7 @@ void ObjectsActivator::work()
try try
{ {
if(orbthr) if(orbthr)
thpid = orbthr->getId(); thpid = orbthr->getTID();
else else
thpid = getpid(); thpid = getpid();
......
...@@ -874,7 +874,7 @@ void UniSetObject::work() ...@@ -874,7 +874,7 @@ void UniSetObject::work()
if( unideb.debugging(Debug::INFO) ) if( unideb.debugging(Debug::INFO) )
unideb[Debug::INFO] << myname << ": thread processing messages run..." << endl; unideb[Debug::INFO] << myname << ": thread processing messages run..." << endl;
if( thr ) if( thr )
msgpid = thr->getId(); msgpid = thr->getTID();
while( isActive() ) while( isActive() )
{ {
callback(); callback();
......
...@@ -347,7 +347,7 @@ SimpleInfo* SystemGuard::getInfo() ...@@ -347,7 +347,7 @@ SimpleInfo* SystemGuard::getInfo()
SimpleInfo_var si = ObjectsManager::getInfo(); SimpleInfo_var si = ObjectsManager::getInfo();
info << si->info; info << si->info;
if( thr ) if( thr )
info << "\texTID= " << thr->getId(); info << "\texTID= " << thr->getTID();
else else
info << "\texpid= " << expid; 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