csutil/thread.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2002 by Norman Kraemer 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_CSSYS_THREAD_H__ 00020 #define __CS_CSSYS_THREAD_H__ 00021 00026 #include "csutil/ref.h" 00027 #include "csutil/refcount.h" 00028 00030 enum 00031 { 00032 CS_THREAD_NO_ERROR = 0, 00033 CS_THREAD_UNKNOWN_ERROR, 00034 CS_THREAD_OUT_OF_RESOURCES, 00035 CS_THREAD_ERR_ATTRIBUTE, 00036 CS_THREAD_NO_PERMISSION, 00037 CS_THREAD_UNKNOWN_THREAD, 00038 CS_THREAD_DEADLOCK, 00039 CS_THREAD_OPERATION_PENDING, 00040 CS_THREAD_MUTEX_NOT_INITIALIZED, 00041 CS_THREAD_MUTEX_BUSY, 00042 CS_THREAD_MUTEX_UNKNOWN, 00043 CS_THREAD_CONDITION_TIMEOUT, 00044 CS_THREAD_CONDITION_BUSY, 00045 CS_THREAD_CONDITION_WAIT_INTERRUPTED, 00046 CS_THREAD_SIGNAL_UNKNOWN, 00047 CS_THREAD_SEMA_VALUE_TOO_LARGE, 00048 CS_THREAD_SEMA_BUSY 00049 }; 00050 00051 /* Priority values indicate how frequently a thread runs compared to other threads. 00052 * 00053 * Thread scheduling is handled by the underlying OS, and so the true meaning of these 00054 * values will vary depending on platform. A minimal set of values is defined for CS 00055 * so that chances of support of the full range of values by the platform are greater. 00056 */ 00057 typedef enum 00058 { 00059 // IDLE priority is the lowest priority. Threads with this priority are scheduled to 00060 // run only when no other thread would be running anyway - or as close as the platform 00061 // allows. 00062 CS_THREAD_PRIORITY_IDLE=0, 00063 // NORMAL priority is the default priority. 00064 CS_THREAD_PRIORITY_NORMAL, 00065 // TIMECRITICAL is the highest priority. 00066 CS_THREAD_PRIORITY_TIMECRITICAL 00067 } csThreadPriority; 00068 00069 00074 class csRunnable 00075 { 00076 protected: 00081 virtual ~csRunnable() {} 00082 public: 00084 virtual void Run () = 0; 00085 00086 /* maybe we could add those for smoother exit/cancel/detroy operations 00087 virtual void PrepareExit () = 0; 00088 virtual void PrepareJoin () = 0; 00089 virtual void PrepareKill () = 0; 00090 virtual void PrepareCancel () = 0; 00091 virtual void PrepareDestroy () = 0; 00092 */ 00093 00095 virtual void IncRef() = 0; 00097 virtual void DecRef() = 0; 00099 virtual int GetRefCount() = 0; 00100 }; 00101 00102 00106 class CS_CRYSTALSPACE_EXPORT csThread : public csRefCount 00107 { 00108 public: 00113 static csRef<csThread> Create (csRunnable*, uint32 options = 0); 00114 00119 virtual bool Start () = 0; 00120 00129 virtual bool Stop () = 0; 00130 00134 virtual bool Wait () = 0; 00135 00142 virtual void Yield () = 0; 00143 00148 virtual csThreadPriority GetPriority() = 0; 00149 00155 virtual bool SetPriority(csThreadPriority Priority) = 0; 00156 00160 virtual char const* GetLastError () const = 0; 00161 }; 00162 00163 00171 class CS_CRYSTALSPACE_EXPORT csMutex : public csRefCount 00172 { 00173 public: 00187 static csRef<csMutex> Create (bool recursive = false); 00188 00195 virtual bool LockWait() = 0; 00196 00203 virtual bool LockTry () = 0; 00204 00211 virtual bool Release () = 0; 00212 00216 virtual char const* GetLastError () const = 0; 00217 00221 virtual bool IsRecursive () const = 0; 00222 }; 00223 00224 00228 class CS_CRYSTALSPACE_EXPORT csSemaphore : public csRefCount 00229 { 00230 public: 00232 static csRef<csSemaphore> Create (uint32 value = 0); 00233 00240 virtual bool LockWait () = 0; 00241 00248 virtual bool LockTry () = 0; 00249 00256 virtual bool Release () = 0; 00257 00259 virtual uint32 Value () = 0; 00260 00264 virtual char const* GetLastError () const = 0; 00265 }; 00266 00267 00271 class CS_CRYSTALSPACE_EXPORT csCondition : public csRefCount 00272 { 00273 public: 00275 static csRef<csCondition> Create (uint32 conditionAttributes = 0); 00276 00285 virtual void Signal (bool WakeAll = false) = 0; 00286 00312 virtual bool Wait (csMutex* mutex, csTicks timeout = 0) = 0; 00313 00317 virtual char const* GetLastError () const = 0; 00318 }; 00319 00320 #endif // __CS_CSSYS_THREAD_H__
Generated for Crystal Space by doxygen 1.4.7