123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- #ifndef Thread_H
- #define Thread_H
- #include <condition_variable>
- #include "Array.h"
- #include "ReferenceCounter.h"
- namespace Framework
- {
- class Thread;
- class Critical;
-
- class Thread : public virtual ReferenceCounter
- {
- private:
- pthread_t* threadHandleSys;
- int lockCount;
- const char* name;
- protected:
- unsigned long threadId;
- pthread_t threadHandle;
- bool run;
- public:
-
- DLLEXPORT Thread();
-
- DLLEXPORT virtual ~Thread();
-
- DLLEXPORT void start();
- #ifdef WIN32
-
- DLLEXPORT void pause();
-
- DLLEXPORT void fortsetzen();
- #endif
-
- DLLEXPORT void ende();
-
- DLLEXPORT virtual void thread();
-
-
- DLLEXPORT virtual void threadEnd();
-
-
-
-
- DLLEXPORT bool isRunning() const;
-
-
-
- DLLEXPORT int warteAufThread(int zeit);
-
-
-
-
- DLLEXPORT void setSystemHandlePointer(pthread_t* ths);
-
- DLLEXPORT pthread_t getThreadHandle() const;
-
- DLLEXPORT void setName(const char* name);
-
- DLLEXPORT const char* getName() const;
- private:
- void addCriticalLock();
- void removeCriticalLock();
- friend Critical;
- };
- #ifdef WIN32
-
-
- DLLEXPORT unsigned long __stdcall threadStart(void* param);
- #else
-
-
- void* threadStart(void* param);
- #endif
-
- class ThreadRegister
- {
- private:
- Array<Framework::Thread*> threads;
- CRITICAL_SECTION cs;
- Array<pthread_t> closedThreads;
- public:
-
- ThreadRegister();
-
- ~ThreadRegister();
-
-
- void add(Thread* t);
-
-
- void remove(Thread* t);
-
-
-
- bool isThread(Thread* t);
-
-
- Thread* zThread(pthread_t handle);
-
-
-
- void addClosedThread(pthread_t handle);
-
- void lock();
-
- void unlock();
-
-
- DLLEXPORT void cleanUpClosedThreads();
- };
- }
- #endif
|