added: gc for sessions (another thread)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@693 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -12,11 +12,11 @@
|
||||
#include "log.h"
|
||||
|
||||
|
||||
BaseThread::BaseThread()
|
||||
BaseThread::BaseThread() : thread_signal(PTHREAD_COND_INITIALIZER)
|
||||
{
|
||||
synchro = 0;
|
||||
thread_signal = 0;
|
||||
thread_id = 0;
|
||||
work_mode = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,11 @@ void BaseThread::SetSynchro(Synchro * psynchro)
|
||||
synchro = psynchro;
|
||||
}
|
||||
|
||||
void BaseThread::SetSignal(pthread_cond_t * psignal)
|
||||
|
||||
|
||||
void BaseThread::Mode(int mode)
|
||||
{
|
||||
thread_signal = psignal;
|
||||
work_mode = mode;
|
||||
}
|
||||
|
||||
|
||||
@@ -117,12 +119,19 @@ void BaseThread::BaseDo()
|
||||
// use it with Lock and Unlock
|
||||
bool BaseThread::WaitForSignal()
|
||||
{
|
||||
return pthread_cond_wait(thread_signal, &synchro->mutex) == 0;
|
||||
return pthread_cond_wait(&thread_signal, &synchro->mutex) == 0;
|
||||
}
|
||||
|
||||
|
||||
void BaseThread::WakeUpThread()
|
||||
{
|
||||
// you should use it with: synchro->Lock() and Unlock()
|
||||
pthread_cond_signal(&thread_signal);
|
||||
}
|
||||
|
||||
|
||||
// use it with Lock and Unlock
|
||||
// it breaks only if there was a stop signal a the time has expired
|
||||
// it breaks only if there was a stop signal or the time has expired
|
||||
bool BaseThread::WaitForSignalSleep(time_t second)
|
||||
{
|
||||
timespec t;
|
||||
@@ -133,7 +142,7 @@ int res;
|
||||
|
||||
do
|
||||
{
|
||||
res = pthread_cond_timedwait(thread_signal, &synchro->mutex, &t);
|
||||
res = pthread_cond_timedwait(&thread_signal, &synchro->mutex, &t);
|
||||
}
|
||||
while( res == 0 && !synchro->was_stop_signal );
|
||||
// above condition means there was a signal
|
||||
@@ -149,7 +158,7 @@ void BaseThread::WaitForThread()
|
||||
}
|
||||
|
||||
|
||||
void BaseThread::StartRoutine()
|
||||
void BaseThread::SignalLoop()
|
||||
{
|
||||
bool make_do;
|
||||
|
||||
@@ -177,11 +186,15 @@ void * BaseThread::StartRoutine(void * this_object)
|
||||
{
|
||||
BaseThread * base = reinterpret_cast<BaseThread*>(this_object);
|
||||
|
||||
if( base->synchro && base->thread_signal )
|
||||
if( base->synchro )
|
||||
{
|
||||
if( base->BaseInit() )
|
||||
{
|
||||
base->StartRoutine();
|
||||
if( base->work_mode == 0 )
|
||||
base->SignalLoop();
|
||||
else
|
||||
base->Work();
|
||||
|
||||
base->BaseUninit();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user