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

Last change on this file since 4 was 4, checked in by ktk, 26 years ago

Import

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