#include <errno.h>
#include "rlwthread.h"
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <pthread.h>
Go to the source code of this file.
◆ TESTINGx
◆ USE_OLD_JOIN
◆ rlsleep()
void rlsleep |
( |
long |
msec | ) |
|
◆ rlwrapdestroy_semaphore()
Definition at line 294 of file rlwthread.cpp.
int rlwthread_mutex_destroy(pthread_mutex_t *mptr)
◆ rlwrapincrement_semaphore()
Definition at line 310 of file rlwthread.cpp.
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);
◆ rlwrapinit_semaphore()
int rlwrapinit_semaphore |
( |
WSEMAPHORE * |
s, |
|
|
int |
cmax |
|
) |
| |
Definition at line 268 of file rlwthread.cpp.
288 pthread_cond_init(&s->cond, NULL);
int rlwthread_mutex_init(pthread_mutex_t *mptr, const pthread_mutexattr_t *attr)
◆ rlwrapwait_semaphore()
Definition at line 341 of file rlwthread.cpp.
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);
◆ rlwthread_attr_init()
Definition at line 36 of file rlwthread.cpp.
42 return pthread_attr_init(attr);
◆ rlwthread_cancel()
Definition at line 253 of file rlwthread.cpp.
256 return (
int) CloseHandle((HANDLE) tid);
258 return pthread_cancel(tid);
◆ rlwthread_close_handle()
void rlwthread_close_handle |
( |
pthread_t * |
tid | ) |
|
Definition at line 79 of file rlwthread.cpp.
82 CloseHandle((HANDLE) *tid);
84 if(tid == NULL)
return;
◆ rlwthread_create()
Definition at line 54 of file rlwthread.cpp.
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);
unsigned long int pthread_t
◆ rlwthread_exit()
void rlwthread_exit |
( |
void * |
status | ) |
|
Definition at line 94 of file rlwthread.cpp.
98 ptr = (DWORD *) status;
99 if(status == NULL) ExitThread((DWORD) 0);
100 else ExitThread(*ptr);
102 pthread_exit(status);
◆ rlwthread_join()
int rlwthread_join |
( |
pthread_t |
tid, |
|
|
void ** |
status |
|
) |
| |
Definition at line 113 of file rlwthread.cpp.
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);
◆ rlwthread_mutex_destroy()
Definition at line 178 of file rlwthread.cpp.
185 return pthread_mutex_destroy(mptr);
◆ rlwthread_mutex_init()
Definition at line 160 of file rlwthread.cpp.
164 HANDLE handle = CreateMutex(NULL, FALSE, NULL);
165 if(handle) *mptr = handle;
170 return pthread_mutex_init(mptr,attr);
◆ rlwthread_mutex_lock()
Definition at line 193 of file rlwthread.cpp.
196 if(WaitForSingleObject(*mptr, INFINITE) == WAIT_OBJECT_0)
return 0;
200 return pthread_mutex_lock(mptr);
◆ rlwthread_mutex_trylock()
Definition at line 215 of file rlwthread.cpp.
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;
◆ rlwthread_mutex_unlock()
Definition at line 238 of file rlwthread.cpp.
245 return pthread_mutex_unlock(mptr);
◆ rlwthread_sleep()
int rlwthread_sleep |
( |
long |
msec | ) |
|
Definition at line 366 of file rlwthread.cpp.
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);
◆ TryEnterCriticalSection()
WINBASEAPI BOOL WINAPI TryEnterCriticalSection |
( |
LPCRITICAL_SECTION |
lpCriticalSection | ) |
|