Main Page | Modules | Data Structures | File List | Data Fields | Related Pages

threading.h

00001 
00011 #ifndef __HELPER_THREADING_H__
00012 #define __HELPER_THREADING_H__
00013 
00014 #ifdef HAVE_CONFIG_H
00015     #include "config.h"
00016 #endif
00017 
00018 #ifdef WITH_PTHREADS
00019    #include <sys/time.h>
00020    #include <pthread.h>
00021    #include <errno.h>
00022    extern int errno;
00023 #elif defined(WITH_SDLTHREADS)
00024    #include <SDL_thread.h>
00025 #endif
00026 #include <stdlib.h>
00027 #include "errmanager.h"
00028 
00029 
00030 /*
00031  * public defines
00032  */
00033 
00034 
00035 typedef void * thread_rdwrattr_t;                   
00037 #define thread_rdwrattr_default NULL;           
00038 #define T_RDWR thread_rdwr_t                    
00039 #define T_RDWRATTR thread_rdwrattr_t            
00041 #ifdef WITH_PTHREADS
00042    #define T_MUTEX pthread_mutex_t              
00043    #define T_MUTEXATTR pthread_mutexattr_t      
00044    #define T_COND pthread_cond_t                
00045    #define T_CONDATTR pthread_condattr_t        
00046    #define T_THREAD pthread_t                   
00047    #define T_THREADATTR pthread_attr_t          
00048 #elif defined(WITH_SDLTHREADS)
00049    #define T_MUTEX SDL_mutex *                  
00050    #define T_MUTEXATTR int                      
00051    #define T_COND SDL_cond *                    
00052    #define T_CONDATTR int                       
00053    #define T_THREAD SDL_Thread *                
00054    #define T_THREADATTR int                     
00055 #else
00056    #define T_MUTEX int                          
00057    #define T_MUTEXATTR int                      
00058    #define T_COND int                           
00059    #define T_CONDATTR int                       
00060    #define T_THREAD int                         
00061    #define T_THREADATTR int                     
00062 #endif
00063 
00064 #define T_MUTEX_INIT(mutex, attr) thread_mutex_init(mutex, attr)           
00065 #define T_MUTEX_LOCK(mutex) thread_mutex_lock(mutex)                       
00066 #define T_MUTEX_TRYLOCK(mutex) thread_mutex_trylock(mutex)                 
00067 #define T_MUTEX_UNLOCK(mutex) thread_mutex_unlock(mutex)                   
00068 #define T_MUTEX_DESTROY(mutex) thread_mutex_destroy(mutex)                 
00069 #define T_COND_INIT(cond, attr) thread_cond_init(cond, attr);              
00070 #define T_COND_SIGNAL(cond) thread_cond_signal(cond)                       
00071 #define T_COND_BROADCAST(cond) thread_cond_broadcast(cond)                 
00072 #define T_COND_WAIT(cond, mutex) thread_cond_wait(cond, mutex)             
00073 #define T_COND_TIMEDWAIT(c, m, t) thread_cond_timedwait(c, m, t)           
00074 #define T_COND_DESTROY(cond) thread_cond_destroy(cond)                     
00075 #define T_RDWR_INIT(rdwrp, attrp) thread_rdwr_init_np(rdwrp, attrp)        
00076 #define T_RDWR_RLOCK(rdwrp) thread_rdwr_rlock_np(rdwrp)                    
00077 #define T_RDWR_RUNLOCK(rdwrp) thread_rdwr_runlock_np(rdwrp)                
00078 #define T_RDWR_WLOCK(rdwrp) thread_rdwr_wlock_np(rdwrp)                    
00079 #define T_RDWR_WUNLOCK(rdwrp) thread_rdwr_wunlock_np(rdwrp)                
00080 #define T_CREATE(t, attr, func, arg) thread_create(t, attr, func, arg)     
00081 #define T_JOIN(t, ret) thread_join(t, ret)                                 
00082 #define T_EXIT(ret) thread_exit(ret)                                       
00083 #define T_CANCEL(t) thread_cancel(t)                                       
00086 /*
00087  * public structs
00088  */
00089 
00090 
00094 typedef struct rdwr_var {
00095     int readers_reading;          
00096     int writer_writing;           
00097     T_MUTEX mutex;                
00098     T_COND lock_free;             
00099 } T_RDWR;
00100 
00101 
00102 /*
00103  * public methods
00104  */
00105 
00106 
00112 
00113 
00123 int thread_create(T_THREAD *thread, T_THREADATTR *attr, void *(*routine)(void *), void *arg);
00124 
00125 
00133 int thread_join(T_THREAD thread, void **ret);
00134 
00135 
00142 int thread_exit(void *ret);
00143 
00144 
00151 int thread_cancel(T_THREAD thread);
00152 
00153 
00159 
00160 
00168 int thread_cond_init(T_COND *cond, T_CONDATTR *cond_attr);
00169 
00170 
00177 int thread_cond_signal(T_COND *cond);
00178 
00179 
00186 int thread_cond_broadcast(T_COND *cond);
00187 
00188 
00196 int thread_cond_wait(T_COND *cond, T_MUTEX *mutex);
00197 
00198 
00207 int thread_cond_timedwait(T_COND *cond, T_MUTEX *mutex, unsigned int timeout);
00208 
00209 
00216 int thread_cond_destroy(T_COND *cond);
00217 
00218 
00224 
00225 
00233 int thread_mutex_init(T_MUTEX *mutex, T_MUTEXATTR *mutexattr);
00234 
00235 
00242 int thread_mutex_lock(T_MUTEX *mutex);
00243 
00244 
00251 int thread_mutex_trylock(T_MUTEX *mutex);
00252 
00253 
00260 int thread_mutex_unlock(T_MUTEX *mutex);
00261 
00262 
00269 int thread_mutex_destroy(T_MUTEX *mutex);
00270 
00271 
00277 
00278 
00286 int thread_rdwr_init_np(T_RDWR *rdwrp, T_RDWRATTR *attrp);
00287 
00288 
00295 int thread_rdwr_rlock_np(T_RDWR *rdwrp);
00296 
00297 
00304 int thread_rdwr_runlock_np(T_RDWR *rdwrp);
00305 
00306 
00313 int thread_rdwr_wlock_np(T_RDWR *rdwrp);
00314 
00315 
00322 int thread_rdwr_wunlock_np(T_RDWR *rdwrp);
00323 
00324 
00325 /*
00326  * private methods
00327  */
00328 
00329 
00330 
00331 
00332 #endif
00333 

Generated on Wed Mar 30 13:43:27 2005 for Mntd by  doxygen 1.3.9.1