ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/BDB/xthread.h
(Generate patch)

Comparing BDB/xthread.h (file contents):
Revision 1.3 by root, Sun Jul 8 11:12:12 2007 UTC vs.
Revision 1.4 by root, Sun Jul 8 13:41:03 2007 UTC

18#define NTDDI_VERSION NTDDI_WIN2K // needed to get win2000 api calls 18#define NTDDI_VERSION NTDDI_WIN2K // needed to get win2000 api calls
19#define _WIN32_WINNT 0x400 19#define _WIN32_WINNT 0x400
20#include <stdio.h>//D 20#include <stdio.h>//D
21#include <fcntl.h> 21#include <fcntl.h>
22#include <io.h> 22#include <io.h>
23#include <time.h>
23#include <winsock2.h> 24#include <winsock2.h>
24#include <process.h> 25#include <process.h>
25#include <windows.h> 26#include <windows.h>
27#include <pthread.h>
26#define sigset_t int 28#define sigset_t int
27#define sigfillset(a) 29#define sigfillset(a)
28#define pthread_sigmask(a,b,c) 30#define pthread_sigmask(a,b,c)
29#define sigaddset(a,b) 31#define sigaddset(a,b)
30#define sigemptyset(s) 32#define sigemptyset(s)
31#define sigfillset(s) 33#define sigfillset(s)
32 34
33#define pthread_kill(a,b) 35typedef pthread_mutex_t mutex_t;
34#define pthread_self() 0 36#define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
37#define X_MUTEX_CHECK(mutex)
38#define X_LOCK(mutex) pthread_mutex_lock (&(mutex))
39#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
35 40
36typedef HANDLE mutex_t; 41typedef pthread_cond_t cond_t;
37#define X_MUTEX_INIT 0 42#define X_COND_INIT PTHREAD_COND_INITIALIZER
38#define X_MUTEX_CHECK(mutex) if (!(mutex)) (mutex) = CreateMutex (NULL, FALSE, NULL) 43#define X_COND_CHECK(cond)
39#define X_LOCK(mutex) WaitForSingleObject ((mutex), INFINITE) 44#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond))
40#define X_UNLOCK(mutex) ReleaseMutex (mutex) 45#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex))
46#define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to))
41 47
42typedef HANDLE cond_t; 48typedef pthread_t thread_t;
43#define X_COND_INIT 0 49#define X_THREAD_PROC(name) void *name (void *thr_arg)
44#define X_COND_CHECK(cond) if (!(cond)) (cond) = CreateEvent (NULL, FALSE, FALSE, NULL)
45#define X_COND_SIGNAL(cond) SetEvent (cond)
46#define X_COND_WAIT(cond,mutex) do { SignalObjectAndWait ((mutex), (cond),INFINITE, FALSE); WaitForSingleObject ((mutex), INFINITE); } while (0)
47
48#define ETIMEDOUT 1
49
50struct timespec {
51 unsigned long tv_sec, tv_nsec;
52};
53
54static int
55X_COND_TIMEDWAIT (mutex_t mutex, cond_t cond, struct timespec to)
56{
57 unsigned long ms = to.tv_nsec / 1000 + to.tv_sec * 1000;
58
59 if (SignalObjectAndWait (mutex, cond, ms, FALSE) == WAIT_TIMEOUT)
60 return ETIMEDOUT;
61
62 if (WaitForSingleObject (mutex, ms) == WAIT_TIMEOUT)
63 return ETIMEDOUT;
64
65 return 0;
66}
67
68typedef DWORD thread_t;
69#define X_THREAD_PROC(name) DWORD WINAPI name (LPVOID thr_arg)
70#define X_THREAD_ATFORK(a,b,c) 50#define X_THREAD_ATFORK(a,b,c)
71 51
72static int 52static int
73thread_create (thread_t *tid, LPTHREAD_START_ROUTINE proc, void *arg) 53thread_create (thread_t *tid, void *(*proc)(void *), void *arg)
74{ 54{
75 *tid = 0; 55 pthread_attr_t attr;
76 CreateThread (0, 4096, proc, arg, 0, tid); 56
77 return !!*tid; 57 pthread_attr_init (&attr);
58 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
59
60 return pthread_create (tid, &attr, proc, arg) == 0;
78} 61}
79 62
80#define respipe_read(a,b,c) PerlSock_recv ((a), (b), (c), 0) 63#define respipe_read(a,b,c) PerlSock_recv ((a), (b), (c), 0)
81#define respipe_write(a,b,c) send ((a), (b), (c), 0) 64#define respipe_write(a,b,c) send ((a), (b), (c), 0)
82#define respipe_close(a) PerlSock_closesocket ((a)) 65#define respipe_close(a) PerlSock_closesocket ((a))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines