CrystalSpace

Public API Reference

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

thread.h

00001 /*
00002     Copyright (C) 2002 by Norman Krämer
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 "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   /* maybe we could add those for smoother exit/cancel/detroy operations
00060   virtual void PrepareExit () = 0;
00061   virtual void PrepareJoin () = 0;
00062   virtual void PrepareKill () = 0;
00063   virtual void PrepareCancel () = 0;
00064   virtual void PrepareDestroy () = 0;
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__

Generated for Crystal Space by doxygen 1.2.14