| 1 | #ifndef _WIN32THREAD_H
|
|---|
| 2 | #define _WIN32THREAD_H
|
|---|
| 3 |
|
|---|
| 4 | #include "win32.h"
|
|---|
| 5 |
|
|---|
| 6 | typedef struct win32_cond { LONG waiters; HANDLE sem; } perl_cond;
|
|---|
| 7 | typedef DWORD perl_key;
|
|---|
| 8 | typedef HANDLE perl_os_thread;
|
|---|
| 9 |
|
|---|
| 10 | #ifndef DONT_USE_CRITICAL_SECTION
|
|---|
| 11 |
|
|---|
| 12 | /* Critical Sections used instead of mutexes: lightweight,
|
|---|
| 13 | * but can't be communicated to child processes, and can't get
|
|---|
| 14 | * HANDLE to it for use elsewhere.
|
|---|
| 15 | */
|
|---|
| 16 | typedef CRITICAL_SECTION perl_mutex;
|
|---|
| 17 | #define MUTEX_INIT(m) InitializeCriticalSection(m)
|
|---|
| 18 | #define MUTEX_LOCK(m) EnterCriticalSection(m)
|
|---|
| 19 | #define MUTEX_UNLOCK(m) LeaveCriticalSection(m)
|
|---|
| 20 | #define MUTEX_DESTROY(m) DeleteCriticalSection(m)
|
|---|
| 21 |
|
|---|
| 22 | #else
|
|---|
| 23 |
|
|---|
| 24 | typedef HANDLE perl_mutex;
|
|---|
| 25 | # define MUTEX_INIT(m) \
|
|---|
| 26 | STMT_START { \
|
|---|
| 27 | if ((*(m) = CreateMutex(NULL,FALSE,NULL)) == NULL) \
|
|---|
| 28 | Perl_croak_nocontext("panic: MUTEX_INIT"); \
|
|---|
| 29 | } STMT_END
|
|---|
| 30 |
|
|---|
| 31 | # define MUTEX_LOCK(m) \
|
|---|
| 32 | STMT_START { \
|
|---|
| 33 | if (WaitForSingleObject(*(m),INFINITE) == WAIT_FAILED) \
|
|---|
| 34 | Perl_croak_nocontext("panic: MUTEX_LOCK"); \
|
|---|
| 35 | } STMT_END
|
|---|
|
|---|