1 | /* $Id: vmutex.cpp,v 1.8 2000-02-16 14:22:47 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 | #define DBG_LOCALLOG DBG_vmutex
|
---|
19 | #include "dbglocal.h"
|
---|
20 |
|
---|
21 | /******************************************************************************/
|
---|
22 | /******************************************************************************/
|
---|
23 | VMutex::VMutex(int fShared) : waiting(0)
|
---|
24 | {
|
---|
25 | APIRET rc;
|
---|
26 |
|
---|
27 | rc = DosCreateMutexSem(NULL, &sem_handle, (fShared == VMUTEX_SHARED) ? DC_SEM_SHARED : 0, FALSE);
|
---|
28 | if(rc != 0) {
|
---|
29 | dprintf(("Error creating mutex %X\n", rc));
|
---|
30 | sem_handle = 0;
|
---|
31 | }
|
---|
32 | }
|
---|
33 | /******************************************************************************/
|
---|
34 | /******************************************************************************/
|
---|
35 | VMutex::~VMutex()
|
---|
36 | {
|
---|
37 | int i;
|
---|
38 |
|
---|
39 | if(sem_handle) {
|
---|
40 | for(i=0;i<waiting;i++) {
|
---|
41 | DosReleaseMutexSem(sem_handle);
|
---|
42 | }
|
---|
43 | DosCloseMutexSem(sem_handle);
|
---|
44 | }
|
---|
45 | }
|
---|
46 | /******************************************************************************/
|
---|
47 | /******************************************************************************/
|
---|
48 | void VMutex::enter(ULONG timeout)
|
---|
49 | {
|
---|
50 | if(sem_handle) {
|
---|
51 | waiting++;
|
---|
52 | DosRequestMutexSem(sem_handle, timeout);
|
---|
53 | waiting--;
|
---|
54 | }
|
---|
55 | }
|
---|
56 | /******************************************************************************/
|
---|
57 | /******************************************************************************/
|
---|
58 | void VMutex::leave()
|
---|
59 | {
|
---|
60 | DosReleaseMutexSem(sem_handle);
|
---|
61 | }
|
---|
62 | /******************************************************************************/
|
---|
63 | /******************************************************************************/
|
---|
64 |
|
---|