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

threading.h

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

Generated on Thu May 27 23:27:28 2004 for Mntd by doxygen 1.3.5