1 | /* $Id: vmutex.cpp,v 1.6 1999-08-28 19:33:44 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Mutex class
|
---|
5 | *
|
---|
6 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | *
|
---|
11 | */
|
---|
12 | #define INCL_DOSSEMAPHORES
|
---|
13 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
---|
14 | #include <vmutex.h>
|
---|
15 | #include <win32type.h>
|
---|
16 | #include <misc.h>
|
---|
17 |
|
---|
18 | /******************************************************************************/
|
---|
19 | /******************************************************************************/
|
---|
20 | VMutex::VMutex(int fShared) : waiting(0)
|
---|
21 | {
|
---|
22 | APIRET rc;
|
---|
23 |
|
---|
24 | rc = DosCreateMutexSem(NULL, &sem_handle, (fShared) ? DC_SEM_SHARED : 0, FALSE);
|
---|
25 | if(rc != 0) {
|
---|
26 | dprintf(("Error creating mutex %X\n", rc));
|
---|
27 | sem_handle = 0;
|
---|
28 | }
|
---|
29 | }
|
---|
30 | /******************************************************************************/
|
---|
31 | /******************************************************************************/
|
---|
32 | 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 VMutex::enter(ULONG timeout)
|
---|
46 | {
|
---|
47 | if(sem_handle) {
|
---|
48 | waiting++;
|
---|
49 | DosRequestMutexSem(sem_handle, timeout);
|
---|
50 | waiting--;
|
---|
51 | }
|
---|
52 | }
|
---|
53 | /******************************************************************************/
|
---|
54 | /******************************************************************************/
|
---|
55 | void VMutex::leave()
|
---|
56 | {
|
---|
57 | DosReleaseMutexSem(sem_handle);
|
---|
58 | }
|
---|
59 | /******************************************************************************/
|
---|
60 | /******************************************************************************/
|
---|
61 |
|
---|