2 * Copyright (C) 2001-2003, Parrot Foundation.
6 * This is the api header for the windows thread primitives
7 * Data Structure and Algorithms:
13 #ifndef PARROT_THR_WINDOWS_H_GUARD
14 #define PARROT_THR_WINDOWS_H_GUARD
20 typedef CRITICAL_SECTION Parrot_mutex
;
21 typedef struct Windows_cond
26 typedef HANDLE Parrot_thread
;
28 # define MUTEX_INIT(m) InitializeCriticalSection((PCRITICAL_SECTION)&(m))
29 # define MUTEX_DESTROY(m) DeleteCriticalSection((PCRITICAL_SECTION)&(m))
31 # define COND_INIT(c) \
33 (c).m_hSema = CreateSemaphore(NULL, 0, LONG_MAX, NULL); \
37 # define COND_DESTROY(c) CloseHandle((c).m_hSema)
39 # define LOCK(m) EnterCriticalSection((PCRITICAL_SECTION)&(m))
40 # define UNLOCK(m) LeaveCriticalSection((PCRITICAL_SECTION)&(m))
42 # define COND_WAIT(c, m) \
46 WaitForSingleObject((c).m_hSema, INFINITE); \
51 # define COND_TIMED_WAIT(c, m, t) \
57 now = Parrot_floatval_time(); \
59 nsec = (LONG)((now - sec)*1000.0f)*1000000L; \
60 if ((t)->tv_sec > sec || ((t)->tv_sec == sec && (t)->tv_nsec > nsec)) \
64 diff = (DWORD)(((t)->tv_sec - sec)*1000L + ((t)->tv_nsec - nsec)/1000000L); \
65 WaitForSingleObject((c).m_hSema, diff); \
71 # define COND_SIGNAL(c) \
73 if ((c).m_lWaiters > 0) \
74 ReleaseSemaphore((c).m_hSema, 1, NULL); \
77 # define COND_BROADCAST(c) \
79 if ((c).m_lWaiters > 0) \
80 ReleaseSemaphore((c).m_hSema, (c).m_lWaiters, NULL); \
83 # define JOIN(t, ret) \
85 WaitForSingleObject((t), INFINITE); \
86 GetExitCodeThread((t), (LPDWORD)&(ret)); \
90 # define DETACH(t) CloseHandle(t)
92 /* If the compiler CRT library has a good _beginthreadXX() routine, use it instead of
93 the Win32 API CreateThread(). _beginthreadXX guards call to the thread start routine
94 with SEH to implement runtime errors and signal support. Also it frees calloc-ed
95 per-thread data block at exit */
97 # define THREAD_CREATE_JOINABLE(t, func, arg) \
100 (t) = (HANDLE)_beginthreadex(NULL, 0, unsigned (__stdcall * (func)) (void*), \
101 (void*)(arg), 0, &tid); \
104 # define THREAD_CREATE_JOINABLE(t, func, arg) \
107 (t) = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)(func), (PVOID)(arg), 0, &tid); \
111 # define THREAD_CREATE_DETACHED(t, func, arg) \
113 THREAD_CREATE_JOINABLE((t), (func), (arg)); \
117 # define CLEANUP_PUSH(f, a)
118 # define CLEANUP_POP(a)
120 typedef void (*Cleanup_Handler
)(void *);
122 #ifndef HAVE_STRUCT_TIMESPEC
123 # define HAVE_STRUCT_TIMESPEC
128 #endif /* HAVE_STRUCT_TIMESPEC */
130 #endif /* PARROT_THR_WINDOWS_H_GUARD */
134 * c-file-style: "parrot"
136 * vim: expandtab shiftwidth=4: