X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=manager%2Fthread_util.h;fp=manager%2Fthread_util.h;h=0000000000000000000000000000000000000000;hb=e3b15cd5dea739f7523920d83bda592db95a7b93;hp=95a16e0b78fac3c4aa04a49c93dfa5f2daf01b41;hpb=7f7bc05439b70b3139086086608996de3c9ae2ed;p=progcomp2012.git diff --git a/manager/thread_util.h b/manager/thread_util.h deleted file mode 100644 index 95a16e0..0000000 --- a/manager/thread_util.h +++ /dev/null @@ -1,115 +0,0 @@ -#ifndef THREAD_UTIL_H -#define THREAD_UTIL_H - -#include -#include - -#include -#include -#include //Needed for threading -#include //Needed for killing the threads (why not in pthread.h?) - -#include - - -class Thread -{ - public: - Thread() : finished(false), thread(0), started(false) - { - - } - - virtual void Start() = 0; - protected: - void Start(void* (ThreadFunction)(void*)) - { - assert(!started); - started = true; - pthread_create(&(thread), NULL, ThreadFunction, (void*)(this)); - pthread_setcancelstate(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); - } - - public: - void Stop() - { - assert(started); - if (!finished) - pthread_cancel(thread); - - pthread_join(thread, NULL); - started = false; - } - - virtual ~Thread() - { - if (started) - Stop(); - } - - bool Finished() const {return finished;} - protected: - - bool finished; - - private: - pthread_t thread; - protected: - bool started; -}; - -class GetterThread : public Thread -{ - public: - GetterThread(FILE * newStream, std::string & newBuffer) : Thread(), stream(newStream), buffer(newBuffer) - { - - } - - virtual ~GetterThread() - { - - } - - virtual void Start() {assert(&buffer != NULL); Thread::Start(GetMessage);} - - private: - FILE * stream; - public: - std::string & buffer; - - pthread_t thread; - static pthread_mutex_t mutex; - static void * GetMessage(void * p); - -}; - - -class TimerThread : public Thread -{ - public: - TimerThread(int newCount) : Thread(), count(newCount) - { - - } - - virtual ~TimerThread() - { - - } - - virtual void Start() {Thread::Start(Timeout);} - - private: - int count; - - static void * Timeout(void * p); - -}; - -#endif //THREAD_UTIL_H - -//EOF - - -