CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

csutil/thread.h

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 
00022 #include "ref.h"
00023 #include "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:
00055   virtual void Run () = 0;
00056 
00057   /* maybe we could add those for smoother exit/cancel/detroy operations
00058   virtual void PrepareExit () = 0;
00059   virtual void PrepareJoin () = 0;
00060   virtual void PrepareKill () = 0;
00061   virtual void PrepareCancel () = 0;
00062   virtual void PrepareDestroy () = 0;
00063   */
00064 
00066   virtual void IncRef() = 0;
00068   virtual void DecRef() = 0;
00069 };
00070 
00071 
00075 class csThread : public csRefCount
00076 {
00077 public:
00082   static csRef<csThread> Create (csRunnable*, uint32 options = 0);
00083 
00088   virtual bool Start () = 0;
00089 
00098   virtual bool Stop () = 0;
00099 
00103   virtual bool Wait () = 0;
00104 
00108   virtual void Yield () = 0;
00109 
00113   virtual char const* GetLastError () = 0;
00114 };
00115 
00116 
00124 class csMutex : public csRefCount
00125 {
00126 public:
00135   static csRef<csMutex> Create (bool needrecursive = false);
00136 
00143   virtual bool LockWait() = 0;
00144 
00151   virtual bool LockTry () = 0;
00152 
00159   virtual bool Release () = 0;
00160 
00164   virtual char const* GetLastError () = 0;
00165 };
00166 
00167 
00171 class csSemaphore : public csRefCount
00172 {
00173 public:
00175   static csRef<csSemaphore> Create (uint32 value = 0);
00176 
00183   virtual bool LockWait () = 0;
00184 
00191   virtual bool LockTry () = 0;
00192 
00199   virtual bool Release () = 0;
00200 
00202   virtual uint32 Value () = 0;
00203 
00207   virtual char const* GetLastError () = 0;
00208 };
00209 
00210 
00214 class csCondition : public csRefCount
00215 {
00216 public:
00218   static csRef<csCondition> Create (uint32 conditionAttributes = 0);
00219 
00228   virtual void Signal (bool WakeAll = false) = 0;
00229 
00240   virtual bool Wait (csMutex*, csTicks timeout = 0) = 0;
00241 
00245   virtual char const* GetLastError () = 0;
00246 };
00247 
00248 #endif // __CS_CSSYS_THREAD_H__

Generated for Crystal Space by doxygen 1.2.18