CrystalSpace

Public API Reference

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 
00029 #include "csutil/win32/msvc_deprecated_warn_off.h"
00030 
00032 enum
00033 {
00034   CS_THREAD_NO_ERROR = 0,
00035   CS_THREAD_UNKNOWN_ERROR,
00036   CS_THREAD_OUT_OF_RESOURCES,
00037   CS_THREAD_ERR_ATTRIBUTE,
00038   CS_THREAD_NO_PERMISSION,
00039   CS_THREAD_UNKNOWN_THREAD,
00040   CS_THREAD_DEADLOCK,
00041   CS_THREAD_OPERATION_PENDING,
00042   CS_THREAD_MUTEX_NOT_INITIALIZED,
00043   CS_THREAD_MUTEX_BUSY,
00044   CS_THREAD_MUTEX_UNKNOWN,
00045   CS_THREAD_CONDITION_TIMEOUT,
00046   CS_THREAD_CONDITION_BUSY,
00047   CS_THREAD_CONDITION_WAIT_INTERRUPTED,
00048   CS_THREAD_SIGNAL_UNKNOWN,
00049   CS_THREAD_SEMA_VALUE_TOO_LARGE,
00050   CS_THREAD_SEMA_BUSY
00051 };
00052 
00053 /* Priority values indicate how frequently a thread runs compared to other threads.
00054  *
00055  * Thread scheduling is handled by the underlying OS, and so the true meaning of these
00056  *  values will vary depending on platform.  A minimal set of values is defined for CS
00057  *  so that chances of support of the full range of values by the platform are greater.
00058 */
00059 typedef enum
00060 {
00061   // IDLE priority is the lowest priority.  Threads with this priority are scheduled to
00062   //  run only when no other thread would be running anyway - or as close as the platform
00063   //  allows.
00064   CS_THREAD_PRIORITY_IDLE=0,
00065   // NORMAL priority is the default priority.
00066   CS_THREAD_PRIORITY_NORMAL,
00067   // TIMECRITICAL is the highest priority.
00068   CS_THREAD_PRIORITY_TIMECRITICAL
00069 } csThreadPriority;
00070 
00071 
00077 class CS_DEPRECATED_TYPE_MSG("csRunnable is deprecated. Use new subsystem in CS::Threading instead") 
00078   csRunnable
00079 {
00080 protected:
00085   virtual ~csRunnable() {}
00086 public:
00088   virtual void Run () = 0;
00089 
00090   /* maybe we could add those for smoother exit/cancel/detroy operations
00091   virtual void PrepareExit () = 0;
00092   virtual void PrepareJoin () = 0;
00093   virtual void PrepareKill () = 0;
00094   virtual void PrepareCancel () = 0;
00095   virtual void PrepareDestroy () = 0;
00096   */
00097 
00099   virtual void IncRef() = 0;
00101   virtual void DecRef() = 0;
00103   virtual int GetRefCount() = 0;
00104 };
00105 
00106 
00111 class CS_CRYSTALSPACE_EXPORT 
00112   CS_DEPRECATED_TYPE_MSG("csThread is deprecated. Use CS::Threading::Thread instead")
00113   csThread : public csRefCount
00114 {
00115 public:
00120   static csRef<csThread> Create (csRunnable*, uint32 options = 0);
00121 
00126   virtual bool Start () = 0;
00127 
00136   virtual bool Stop () = 0;
00137 
00141   virtual bool Wait () = 0;
00142 
00149   virtual void Yield () = 0;
00150 
00155   virtual csThreadPriority GetPriority() = 0;
00156 
00162   virtual bool SetPriority(csThreadPriority Priority) = 0;
00163 
00167   virtual char const* GetLastError () const = 0;
00168 };
00169 
00170 
00179 class CS_CRYSTALSPACE_EXPORT 
00180   CS_DEPRECATED_TYPE_MSG("csMutex is deprecated. Use new subsystem in CS::Threading instead") 
00181   csMutex : public csRefCount
00182 {
00183 public:
00197   static csRef<csMutex> Create (bool recursive = false);
00198 
00205   virtual bool LockWait() = 0;
00206 
00213   virtual bool LockTry () = 0;
00214 
00221   virtual bool Release () = 0;
00222 
00226   virtual char const* GetLastError () const = 0;
00227 
00231   virtual bool IsRecursive () const = 0;
00232 };
00233 
00234 
00239 class CS_CRYSTALSPACE_EXPORT 
00240   CS_DEPRECATED_TYPE_MSG("csSemaphore is deprecated. Use new subsystem in CS::Threading instead") 
00241   csSemaphore : public csRefCount
00242 {
00243 public:
00245   static csRef<csSemaphore> Create (uint32 value = 0);
00246 
00253   virtual bool LockWait () = 0;
00254 
00261   virtual bool LockTry () = 0;
00262 
00269   virtual bool Release () = 0;
00270 
00272   virtual uint32 Value () = 0;
00273 
00277   virtual char const* GetLastError () const = 0;
00278 };
00279 
00280 
00285 class CS_CRYSTALSPACE_EXPORT
00286   CS_DEPRECATED_TYPE_MSG("csCondition is deprecated. Use new subsystem in CS::Threading instead") 
00287   csCondition : public csRefCount
00288 {
00289 public:
00291   static csRef<csCondition> Create (uint32 conditionAttributes = 0);
00292 
00301   virtual void Signal (bool WakeAll = false) = 0;
00302 
00328   virtual bool Wait (csMutex* mutex, csTicks timeout = 0) = 0;
00329 
00333   virtual char const* GetLastError () const = 0;
00334 };
00335 
00336 #include "csutil/win32/msvc_deprecated_warn_on.h"
00337 
00338 #endif // __CS_CSSYS_THREAD_H__

Generated for Crystal Space 1.2.1 by doxygen 1.5.3