27 #include <sys/socket.h> 28 #include <netinet/in.h> 42 return pthread_attr_init(attr);
55 void *(*func)(
void*),
void *arg)
62 handle = CreateThread( NULL,
64 (LPTHREAD_START_ROUTINE)func,
67 (
unsigned long *) &ThreadId
70 if(handle == NULL)
return -1;
73 int ret = pthread_create(tid,attr,func,arg);
82 CloseHandle((HANDLE) *tid);
84 if(tid == NULL)
return;
98 ptr = (DWORD *) status;
99 if(status == NULL) ExitThread((DWORD) 0);
100 else ExitThread(*ptr);
102 pthread_exit(status);
121 GetExitCodeThread((HANDLE) tid,&exitcode);
122 if(exitcode != STILL_ACTIVE)
return exitcode;
125 if(status == NULL)
return 0;
129 DWORD dwWait = WaitForSingleObject((HANDLE) tid, INFINITE);
130 if(dwWait == WAIT_OBJECT_0)
132 if(GetExitCodeThread((HANDLE) tid, &exitcode) == TRUE)
135 *status = (int) exitcode;
139 result = GetLastError();
142 else if(dwWait == WAIT_FAILED)
144 result = GetLastError();
146 if(status)
return result;
151 return pthread_join(tid,status);
164 HANDLE handle = CreateMutex(NULL, FALSE, NULL);
165 if(handle) *mptr = handle;
170 return pthread_mutex_init(mptr,attr);
185 return pthread_mutex_destroy(mptr);
196 if(WaitForSingleObject(*mptr, INFINITE) == WAIT_OBJECT_0)
return 0;
200 return pthread_mutex_lock(mptr);
220 ret = WaitForSingleObject(*mptr, 0);
221 if(ret == WAIT_OBJECT_0)
return 1;
228 ret = pthread_mutex_trylock(mptr);
229 if(ret == EBUSY)
return 0;
245 return pthread_mutex_unlock(mptr);
256 return (
int) CloseHandle((HANDLE) tid);
258 return pthread_cancel(tid);
288 pthread_cond_init(&s->cond, NULL);
315 if(!ReleaseSemaphore(
326 pthread_mutex_lock(&s->mutex);
327 if(s->nready == 0) pthread_cond_signal(&s->cond);
329 pthread_mutex_unlock(&s->mutex);
346 ret = WaitForSingleObject(
354 pthread_mutex_lock(&s->mutex);
355 while(s->nready == 0)
357 pthread_cond_wait(&s->cond,&s->mutex);
360 pthread_mutex_unlock(&s->mutex);
374 fd_set wset,rset,eset;
375 struct timeval timeout;
380 timeout.tv_sec = msec / 1000;
381 timeout.tv_usec = (msec % 1000) * 1000;
382 select(1,&rset,&wset,&eset,&timeout);
387 struct timespec interval;
389 interval.tv_sec = msec / 1000;
390 interval.tv_nsec = (msec % 1000) * 1000 * 1000;
391 pthread_delay_np(&interval);
425 void *thread(
void *arg)
428 printf(
"thread start : %s\n",(
const char *) arg);
432 printf(
"thread %d\n",i);
463 printf(
"create a thread\n");
482 printf(
"main %d\n",i);
484 if(i%4 == 0) Sleep(10);
487 printf(
"waiting for thread\n");
int rlwthread_mutex_destroy(pthread_mutex_t *mptr)
int rlwthread_attr_init(pthread_attr_t *attr)
void rlwthread_close_handle(pthread_t *tid)
int rlwthread_cancel(pthread_t tid)
int rlwthread_mutex_init(pthread_mutex_t *mptr, const pthread_mutexattr_t *attr)
void rlwthread_exit(void *status)
int rlwthread_mutex_lock(pthread_mutex_t *mptr)
int rlwthread_mutex_trylock(pthread_mutex_t *mptr)
WINBASEAPI BOOL WINAPI TryEnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
int rlwthread_join(pthread_t tid, void **status)
unsigned long int pthread_t
int rlwrapincrement_semaphore(WSEMAPHORE *s)
int rlwrapinit_semaphore(WSEMAPHORE *s, int cmax)
int rlwthread_mutex_unlock(pthread_mutex_t *mptr)
int rlwthread_create(pthread_t *tid, const pthread_attr_t *attr, void *(*func)(void *), void *arg)
int rlwrapwait_semaphore(WSEMAPHORE *s)
int rlwrapdestroy_semaphore(WSEMAPHORE *s)
int rlwthread_sleep(long msec)