00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CS_CSSYS_THREAD_H__
00020 #define __CS_CSSYS_THREAD_H__
00021
00022 #include "csutil/ref.h"
00023 #include "csutil/refcount.h"
00024
00026 enum
00027 {
00028 CS_THREAD_NO_ERROR = 0,
00029 CS_THREAD_UNKNOWN_ERROR,
00030 CS_THREAD_OUT_OF_RESOURCES,
00031 CS_THREAD_ERR_ATTRIBUTE,
00032 CS_THREAD_NO_PERMISSION,
00033 CS_THREAD_UNKNOWN_THREAD,
00034 CS_THREAD_DEADLOCK,
00035 CS_THREAD_OPERATION_PENDING,
00036 CS_THREAD_MUTEX_NOT_INITIALIZED,
00037 CS_THREAD_MUTEX_BUSY,
00038 CS_THREAD_MUTEX_UNKNOWN,
00039 CS_THREAD_CONDITION_TIMEOUT,
00040 CS_THREAD_CONDITION_BUSY,
00041 CS_THREAD_CONDITION_WAIT_INTERRUPTED,
00042 CS_THREAD_SIGNAL_UNKNOWN,
00043 CS_THREAD_SEMA_VALUE_TOO_LARGE,
00044 CS_THREAD_SEMA_BUSY
00045 };
00046
00051 class csRunnable
00052 {
00053 public:
00057 virtual void Run () = 0;
00058
00059
00060
00061
00062
00063
00064
00065
00066
00068 virtual void IncRef() = 0;
00070 virtual void DecRef() = 0;
00071 };
00072
00073
00077 class csThread : public csRefCount
00078 {
00079 public:
00084 static csRef<csThread> Create (csRunnable*, uint32 options = 0);
00085
00090 virtual bool Start () = 0;
00091
00100 virtual bool Stop () = 0;
00101
00105 virtual bool Wait () = 0;
00106
00110 virtual char const* GetLastError () = 0;
00111 };
00112
00113
00117 class csMutex : public csRefCount
00118 {
00119 public:
00128 static csRef<csMutex> Create (bool needrecursive = false);
00129 virtual bool LockWait() = 0;
00130 virtual bool LockTry () = 0;
00131 virtual bool Release () = 0;
00132 virtual char const* GetLastError () = 0;
00133 };
00134
00135
00139 class csSemaphore : public csRefCount
00140 {
00141 public:
00142 static csRef<csSemaphore> Create (uint32 value);
00143 virtual bool LockWait () = 0;
00144 virtual bool LockTry () = 0;
00145 virtual bool Release () = 0;
00146 virtual uint32 Value () = 0;
00147 virtual char const* GetLastError () = 0;
00148 };
00149
00150
00154 class csCondition : public csRefCount
00155 {
00156 public:
00157 static csRef<csCondition> Create (uint32 conditionAttributes = 0);
00158 virtual void Signal (bool WakeAll = false) = 0;
00159 virtual bool Wait (csMutex*, csTicks timeout = 0) = 0;
00160 virtual char const* GetLastError () = 0;
00161 };
00162
00163 #endif // __CS_CSSYS_THREAD_H__