1 | /*
|
---|
2 | *
|
---|
3 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
4 | *
|
---|
5 | */
|
---|
6 | /*
|
---|
7 | * Mutex class
|
---|
8 | *
|
---|
9 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
10 | *
|
---|
11 | */
|
---|
12 | #define INCL_DOSSEMAPHORES
|
---|
13 | #include <os2.h>
|
---|
14 | #include <vmutex.h>
|
---|
15 | #include <win32type.h>
|
---|
16 | #include <misc.h>
|
---|
17 |
|
---|
18 | /******************************************************************************/
|
---|
19 | /******************************************************************************/
|
---|
20 | _Export VMutex::VMutex() : waiting(0)
|
---|
21 | {
|
---|
22 | APIRET rc;
|
---|
23 |
|
---|
24 | rc = DosCreateMutexSem(NULL, &sem_handle, 0, FALSE);
|
---|
25 | if(rc != 0) {
|
---|
26 | dprintf(("Error creating mutex %X\n", rc));
|
---|
27 | sem_handle = 0;
|
---|
28 | }
|
---|
29 | }
|
---|
30 | /******************************************************************************/
|
---|
31 | /******************************************************************************/
|
---|
32 | _Export VMutex::~VMutex()
|
---|
33 | {
|
---|
34 | int i;
|
---|
35 |
|
---|
36 | if(sem_handle) {
|
---|
37 | for(i=0;i<waiting;i++) {
|
---|
38 | DosReleaseMutexSem(sem_handle);
|
---|
39 | }
|
---|
40 | DosCloseMutexSem(sem_handle);
|
---|
41 | }
|
---|
42 | }
|
---|
43 | /******************************************************************************/
|
---|
44 | /******************************************************************************/
|
---|
45 | void _Export VMutex::enter(ULONG timeout)
|
---|
46 | {
|
---|
47 | if(sem_handle) {
|
---|
48 | waiting++;
|
---|
49 | DosRequestMutexSem(sem_handle, timeout);
|
---|
50 | waiting--;
|
---|
51 | }
|
---|
52 | }
|
---|
53 | /******************************************************************************/
|
---|
54 | /******************************************************************************/
|
---|
55 | void _Export VMutex::leave()
|
---|
56 | {
|
---|
57 | DosReleaseMutexSem(sem_handle);
|
---|
58 | }
|
---|
59 | /******************************************************************************/
|
---|
60 | /******************************************************************************/
|
---|
61 |
|
---|