source: trunk/src/kernel32/vmutex.cpp@ 1570

Last change on this file since 1570 was 1432, checked in by sandervl, 26 years ago

Shared memory mapping changes

File size: 1.7 KB
Line 
1/* $Id: vmutex.cpp,v 1.7 1999-10-24 22:51:22 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/******************************************************************************/
20VMutex::VMutex(int fShared) : waiting(0)
21{
22 APIRET rc;
23
24 rc = DosCreateMutexSem(NULL, &sem_handle, (fShared == VMUTEX_SHARED) ? 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/******************************************************************************/
32VMutex::~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/******************************************************************************/
45void VMutex::enter(ULONG timeout)
46{
47 if(sem_handle) {
48 waiting++;
49 DosRequestMutexSem(sem_handle, timeout);
50 waiting--;
51 }
52}
53/******************************************************************************/
54/******************************************************************************/
55void VMutex::leave()
56{
57 DosReleaseMutexSem(sem_handle);
58}
59/******************************************************************************/
60/******************************************************************************/
61
Note: See TracBrowser for help on using the repository browser.