SysThread.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005 Palmsource, Inc.
00003  * 
00004  * This software is licensed as described in the file LICENSE, which
00005  * you should have received as part of this distribution. The terms
00006  * are also available at http://www.openbinder.org/license.html.
00007  * 
00008  * This software consists of voluntary contributions made by many
00009  * individuals. For the exact contribution history, see the revision
00010  * history and logs, available at http://www.openbinder.org
00011  */
00012 
00019 #ifndef _SYSTHREAD_H_
00020 #define _SYSTHREAD_H_
00021 
00035 // Include elementary types
00036 #include <PalmTypes.h>
00037 
00038 #ifdef __cplusplus
00039 extern "C" {
00040 #endif
00041 
00042 // -------------------------------------------------------
00043 // THREAD CONSTANTS
00044 // -------------------------------------------------------
00045 
00047 
00049 enum {
00050     sysThreadPriorityLowered        = 100,      
00051     sysThreadPriorityNormal         = 80,       
00052     sysThreadPriorityBestApp        = 80,       
00053     sysThreadPriorityRaised         = 70,       
00054     sysThreadPriorityTransaction    = 65,       
00055     sysThreadPriorityDisplay        = 60,       
00056     sysThreadPriorityUrgentDisplay  = 50,       
00057     sysThreadPriorityRealTime       = 40,       
00058     sysThreadPriorityBestUser       = 30,       
00059     sysThreadPriorityBestSystem     = 5,        
00060 
00061     sysThreadPriorityLow            = sysThreadPriorityLowered, 
00062     sysThreadPriorityHigh           = sysThreadPriorityRealTime 
00063 };
00064 
00066 enum {
00067     sysThreadStackBasic             = 4*1024,   
00068     sysThreadStackUI                = 8*1024    
00069 };
00070 
00072 typedef enum {
00073     B_WAIT_FOREVER              = 0x0000,
00074     B_POLL                      = 0x0300,
00075     B_RELATIVE_TIMEOUT          = 0x0100,
00076     B_ABSOLUTE_TIMEOUT          = 0x0200
00077 } timeoutFlagsEnum_t;
00078 typedef uint16_t timeoutFlags_t; 
00079 
00080 // -------------------------------------------------------
00081 // THREAD SUPPORT
00082 // -------------------------------------------------------
00083 
00086 
00087 int32_t SysAtomicInc32(int32_t volatile *ioOperandP);
00088 int32_t SysAtomicDec32(int32_t volatile *ioOperandP);
00089 int32_t SysAtomicAdd32(int32_t volatile *ioOperandP, int32_t iAddend);
00090 uint32_t SysAtomicAnd32(uint32_t volatile *ioOperandP, uint32_t iValue);
00091 uint32_t SysAtomicOr32(uint32_t volatile *ioOperandP, uint32_t iValue);
00092 uint32_t SysAtomicCompareAndSwap32(uint32_t volatile *ioOperandP, uint32_t iOldValue,
00093                  uint32_t iNewValue);
00095 
00098 
00100 
00101 nsecs_t SysGetRunTime(void);
00102 
00103 //@]
00104 
00107 
00108 typedef uint32_t SysTSDSlotID;
00109 typedef void (SysTSDDestructorFunc)(void*);
00110 enum { sysTSDAnonymous=0 }; // symbolic value for iName in unnamed slots
00111 status_t    SysTSDAllocate(SysTSDSlotID *oTSDSlot, SysTSDDestructorFunc *iDestructor, uint32_t iName);
00112 status_t    SysTSDFree(SysTSDSlotID tsdslot);
00113 void        *SysTSDGet(SysTSDSlotID tsdslot);
00114 void        SysTSDSet(SysTSDSlotID tsdslot, void *iValue);
00115 
00117 
00120 
00121 typedef uint32_t SysThreadExitCallbackID;
00122 typedef void (SysThreadExitCallbackFunc)(void*);
00123 status_t    SysThreadInstallExitCallback(   SysThreadExitCallbackFunc *iExitCallbackP,
00124                                             void *iCallbackArg,
00125                                             SysThreadExitCallbackID *oThreadExitCallbackId);
00126 status_t    SysThreadRemoveExitCallback(SysThreadExitCallbackID iThreadCallbackId);
00127 
00129 
00132 
00134 #define sysCriticalSectionInitializer NULL
00135 typedef void * SysCriticalSectionType;
00136 
00137 #if (TARGET_HOST == TARGET_HOST_WIN32)
00138 // Not needed for TARGET_HOST_WIN32
00139 #else
00140 #if 1 || TARGET_HOST == TARGET_HOST_PALMOS // FIXME: Linux host/target
00141 void SysCriticalSectionEnter(SysCriticalSectionType *iCS);
00142 void SysCriticalSectionExit(SysCriticalSectionType *iCS);
00143 #endif //TARGET_HOST == TARGET_HOST_PALMOS
00144 #endif // TARGET_HOST == TARGET_HOST_WIN32
00145 
00148 
00150 #define sysConditionVariableInitializer 0
00151 typedef void * SysConditionVariableType;
00152 
00153 #if (TARGET_HOST == TARGET_HOST_WIN32)
00154 // Not needed for TARGET_HOST_WIN32
00155 #else
00156 #if 1 || TARGET_HOST == TARGET_HOST_PALMOS // FIXME: Linux host/target
00157 void SysConditionVariableWait(SysConditionVariableType *iCV, SysCriticalSectionType *iOptionalCS);
00158 void SysConditionVariableOpen(SysConditionVariableType *iCV);
00159 void SysConditionVariableClose(SysConditionVariableType *iCV);
00160 void SysConditionVariableBroadcast(SysConditionVariableType *iCV);
00161 #endif //TARGET_HOST == TARGET_HOST_PALMOS
00162 #endif // TARGET_HOST == TARGET_HOST_WIN32
00163 
00165 
00168 
00169 enum { sysSemaphoreMaxCount = 0xffff };
00170 status_t    SysSemaphoreCreateEZ(uint32_t initialCount, SysHandle* outSemaphore);
00171 status_t    SysSemaphoreCreate( uint32_t initialCount, uint32_t maxCount, uint32_t flags,
00172                                 SysHandle* outSemaphore);
00173 status_t    SysSemaphoreDestroy(SysHandle semaphore);
00174 status_t    SysSemaphoreSignal(SysHandle semaphore);
00175 status_t    SysSemaphoreSignalCount(SysHandle semaphore, uint32_t count);
00176 status_t    SysSemaphoreWait(   SysHandle semaphore,
00177                                 timeoutFlags_t iTimeoutFlags, nsecs_t iTimeout);
00178 status_t    SysSemaphoreWaitCount(  SysHandle semaphore,
00179                                     timeoutFlags_t iTimeoutFlags, nsecs_t iTimeout,
00180                                     uint32_t count);
00181 
00183 
00184 // -------------------------------------------------------
00185 // THREAD GROUPS
00186 // -------------------------------------------------------
00187 
00196 
00197 struct SysThreadGroupTag;
00198 typedef struct SysThreadGroupTag SysThreadGroupType;
00199 typedef SysThreadGroupType* SysThreadGroupHandle;
00200 
00201 SysThreadGroupHandle    SysThreadGroupCreate(void);
00202 status_t                SysThreadGroupDestroy(SysThreadGroupHandle group);
00203 status_t                SysThreadGroupWait(SysThreadGroupHandle group);
00204 
00205 // Use this if you don't want the thread in a group.
00206 #define         sysThreadNoGroup    NULL
00207 
00209 
00210 // -------------------------------------------------------
00211 // THREAD CREATION
00212 // -------------------------------------------------------
00213 
00216 
00218 
00231 typedef void (SysThreadEnterFunc) (void *);
00232 status_t    SysThreadCreateEZ(  const char *name,
00233                                 SysThreadEnterFunc *func, void *argument,
00234                                 SysHandle* outThread);
00235 
00237 
00245 status_t    SysThreadCreate(SysThreadGroupHandle group, const char *name,
00246                             uint8_t priority, uint32_t stackSize,
00247                             SysThreadEnterFunc *func, void *argument,
00248                             SysHandle* outThread);
00249 
00251 
00255 status_t    SysThreadStart(SysHandle thread);
00256 
00258 
00262 int     SysThreadKill(SysHandle thread, int signo);
00263 
00265 SysHandle   SysCurrentThread(void);
00266 
00268 
00269 void        SysThreadExit(void);
00270 
00272 status_t    SysThreadDelay(nsecs_t timeout, timeoutFlags_t flags);
00273 
00274 #if 0 // FIXME: Missing API, not supportable with pthreads LINUX_DEMO_HACK
00275 
00276 status_t    SysThreadSuspend(SysHandle thread);
00278 
00279 status_t    SysThreadResume(SysHandle thread);
00280 #endif
00281 
00283 status_t    SysThreadChangePriority(SysHandle thread, uint8_t priority);
00284 
00286 
00287 #ifdef __cplusplus
00288 }   // extern "C"
00289 #endif
00290 
00293 #endif // _SYSTHREAD_H_