Files
winix/core/basethread.h
Tomasz Sowa 4d87359aca added: Export plugin (not finished yet)
added:   ThreadManager
         all threads are connected to the ThreadManager
         they are started/stopped by the manager
changed: FunctionParser
         now we are parsing directly what is in URI
         (we were using GetParser beforehand)
         we are able to recognize ordinary URI scheme (with '?' and '#' characters)
         sample:
         http://domain.com/dir1/dir2/item/function?par1=val2&par2=val2#htmlanchor
         is the same as:
         http://domain.com/dir1/dir2/item/function/par1:val2/par2:val2#htmlanchor
         'htmlanchor' is put in Request::anchor field,
         and the default function can be used like this:
         http://domain.com/dir1/dir2/item?par1=val2&par2=val2#htmlanchor
         but there is not an equivalent in winix form
         e.g. http://domain.com/dir1/dir2/item/par1:val2/par2:val2#htmlanchor
         because 'par1:val2' would be treated as a function name
removed: GetParser
         now we don't have Request::get_tab structure
removed: CKEditorGetParser
         it is not needed now



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@752 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-07-28 22:18:10 +00:00

127 lines
3.0 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010-2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_core_basethread
#define headerfile_winix_core_basethread
#include <pthread.h>
#include "synchro.h"
class BaseThread
{
public:
BaseThread();
// synchro object (must be set)
void SetSynchro(Synchro * psynchro);
// work mode
// we have two modes:
// 0 - there is a loop with SignalReceived() and Do()
// if SignalReceived() returns true then Do() is called
// 1 - only Work() method is called
// the thread exits after Work() has finished
// default: 0
void Mode(int mode);
// starting the second thread
bool StartThread();
// wake up the second thread
// (if it waits for the signal)
// you should use it with: synchro->Lock() and Unlock()
// if the thread doesn't wait on a signal then nothing is done
void WakeUpThread();
// waiting until the thread exits
// you should call WakeUpThread() before
void WaitForThread();
// virtual methods which should/can be inherited by your class
// the methods will be called from the other thread
// initialize the thread
// (global objects are locked)
// if it returns false then the thread immediately exits
// default: true
virtual bool Init() { return true; }
// uninitialize the thread
// this is called before the thread is prepare to detach
// (global objects are locked)
// it's called only if Init() returned true
virtual void Uninit() {}
// returns the thread id
// this identifier is set by StartThread() metdhod
pthread_t ThreadId();
protected:
// signal came (work mode = 0 - default)
// signal comes when an other thread calls WakeUpThread() method
// check specific job and return true to call Do() next
// (global objects are locked -- copy some global objects to local variables)
virtual bool SignalReceived() { return false; };
// if SignalReceived() returned true then this method is called
// global objects are *not* locked -- use only your local variables
// if you have to do something on global objects use synchro->Lock() and synchro->Unlock()
virtual void Do() {}
// this method is called after Init() when Mode(1) is used
// this is for long-time job
// this method is called only once
// global objects are *not* locked
virtual void Work() {}
protected:
Synchro * synchro;
pthread_t thread_id; // thread id - set by StartThread()
pthread_cond_t thread_signal;
int work_mode;
bool wake_up_was_called;
void SignalLoop();
static void * StartRoutine(void *);
bool BaseInit();
void BaseUninit();
bool BaseSignalReceived();
void BaseDo();
bool WaitForSignal();
bool WaitForSignalSleep(time_t second);
bool Lock();
void Unlock();
// if the work done by Do() is long time consuming you should periodically check
// wheter there was a signal for exiting, and if it was just simply return from Do()
// (it's checking with locking and unlocking)
bool IsExitSignal();
};
#endif