00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #ifndef AVCODEC_OS2PTHREADS_H
00027 #define AVCODEC_OS2PTHREADS_H
00028
00029 #define INCL_DOS
00030 #include <os2.h>
00031
00032 #undef __STRICT_ANSI__
00033 #include <stdlib.h>
00034
00035 typedef TID pthread_t;
00036 typedef void pthread_attr_t;
00037
00038 typedef HMTX pthread_mutex_t;
00039 typedef void pthread_mutexattr_t;
00040
00041 typedef struct {
00042 HEV event_sem;
00043 int wait_count;
00044 } pthread_cond_t;
00045
00046 typedef void pthread_condattr_t;
00047
00048 struct thread_arg {
00049 void *(*start_routine)(void *);
00050 void *arg;
00051 };
00052
00053 static void thread_entry(void *arg)
00054 {
00055 struct thread_arg *thread_arg = arg;
00056
00057 thread_arg->start_routine(thread_arg->arg);
00058
00059 av_free(thread_arg);
00060 }
00061
00062 static av_always_inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg)
00063 {
00064 struct thread_arg *thread_arg;
00065
00066 thread_arg = av_mallocz(sizeof(struct thread_arg));
00067
00068 thread_arg->start_routine = start_routine;
00069 thread_arg->arg = arg;
00070
00071 *thread = _beginthread(thread_entry, NULL, 256 * 1024, thread_arg);
00072
00073 return 0;
00074 }
00075
00076 static av_always_inline int pthread_join(pthread_t thread, void **value_ptr)
00077 {
00078 DosWaitThread((PTID)&thread, DCWW_WAIT);
00079
00080 return 0;
00081 }
00082
00083 static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
00084 {
00085 DosCreateMutexSem(NULL, (PHMTX)mutex, 0, FALSE);
00086
00087 return 0;
00088 }
00089
00090 static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
00091 {
00092 DosCloseMutexSem(*(PHMTX)mutex);
00093
00094 return 0;
00095 }
00096
00097 static av_always_inline int pthread_mutex_lock(pthread_mutex_t *mutex)
00098 {
00099 DosRequestMutexSem(*(PHMTX)mutex, SEM_INDEFINITE_WAIT);
00100
00101 return 0;
00102 }
00103
00104 static av_always_inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
00105 {
00106 DosReleaseMutexSem(*(PHMTX)mutex);
00107
00108 return 0;
00109 }
00110
00111 static av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
00112 {
00113 DosCreateEventSem(NULL, &cond->event_sem, DCE_POSTONE, FALSE);
00114
00115 cond->wait_count = 0;
00116
00117 return 0;
00118 }
00119
00120 static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
00121 {
00122 DosCloseEventSem(cond->event_sem);
00123
00124 return 0;
00125 }
00126
00127 static av_always_inline int pthread_cond_signal(pthread_cond_t *cond)
00128 {
00129 if (cond->wait_count > 0) {
00130 DosPostEventSem(cond->event_sem);
00131
00132 cond->wait_count--;
00133 }
00134
00135 return 0;
00136 }
00137
00138 static av_always_inline int pthread_cond_broadcast(pthread_cond_t *cond)
00139 {
00140 while (cond->wait_count > 0) {
00141 DosPostEventSem(cond->event_sem);
00142
00143 cond->wait_count--;
00144 }
00145
00146 return 0;
00147 }
00148
00149 static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
00150 {
00151 cond->wait_count++;
00152
00153 pthread_mutex_unlock(mutex);
00154
00155 DosWaitEventSem(cond->event_sem, SEM_INDEFINITE_WAIT);
00156
00157 pthread_mutex_lock(mutex);
00158
00159 return 0;
00160 }
00161
00162 #endif