source: trunk/src/kernel32/hmmutex.cpp

Last change on this file was 9748, checked in by sandervl, 23 years ago

Support DuplicateHandle for threads; cleaned up semaphore code

File size: 4.8 KB
Line 
1/* $Id: hmmutex.cpp,v 1.8 2003-02-04 11:28:58 sandervl Exp $ */
2
3/*
4 * Win32 Mutex Semaphore implementation
5 *
6 * TODO: Inheritance
7 * TODO: No inheritance when CreateMutex is called for existing named event semaphore?
8 * (see HMCreateMutex in handlemanager.cpp)
9 * TODO: Name collisions with files & mutex not allowed. Check if this can happen in OS/2
10 *
11 * Project Odin Software License can be found in LICENSE.TXT
12 *
13 * Copyright 2001 Sander van Leeuwen (sandervl@xs4all.nl)
14 */
15
16#undef DEBUG_LOCAL
17//#define DEBUG_LOCAL
18
19
20/*****************************************************************************
21 * Remark *
22 *****************************************************************************
23
24 */
25
26
27/*****************************************************************************
28 * Includes *
29 *****************************************************************************/
30
31#include <os2win.h>
32#include <stdlib.h>
33#include <string.h>
34#include "unicode.h"
35#include "misc.h"
36#include "oslibdos.h"
37
38#include "HandleManager.H"
39#include "HMMutex.h"
40#include "HMSemaphore.h"
41
42#define DBG_LOCALLOG DBG_hmmutex
43#include "dbglocal.h"
44
45/*****************************************************************************
46 * Defines *
47 *****************************************************************************/
48
49/*****************************************************************************
50 * Structures *
51 *****************************************************************************/
52
53/*****************************************************************************
54 * Local Prototypes *
55 *****************************************************************************/
56
57
58/*****************************************************************************
59 * Name : HMCreateMutex
60 * Purpose : router function for CreateMutex
61 * Parameters:
62 * Variables :
63 * Result :
64 * Remark :
65 * Status :
66 *
67 * Author : Patrick Haller [Tue, 1999/07/06 20:44]
68 *****************************************************************************/
69
70DWORD HMDeviceMutexClass::CreateMutex(PHMHANDLEDATA pHMHandleData,
71 LPSECURITY_ATTRIBUTES lpsa,
72 BOOL fInitialOwner,
73 LPCTSTR lpszMutexName)
74{
75 HANDLE hOpen32;
76
77 dprintf(("KERNEL32: HandleManager::Mutex::CreateMutex(%08xh,%08xh,%08xh,%s)\n",
78 pHMHandleData,
79 lpsa,
80 fInitialOwner,
81 lpszMutexName));
82
83 hOpen32 = O32_CreateMutex(lpsa, // call Open32
84 fInitialOwner,
85 lpszMutexName);
86
87 if (0 != hOpen32) // check success
88 {
89 pHMHandleData->hHMHandle = hOpen32; // save handle
90 return (NO_ERROR);
91 }
92 else
93 return (GetLastError());
94}
95
96
97/*****************************************************************************
98 * Name : HMOpenMutex
99 * Purpose : router function for OpenMutex
100 * Parameters:
101 * Variables :
102 * Result :
103 * Remark :
104 * Status :
105 *
106 * Author : Patrick Haller [Tue, 1999/07/06 20:44]
107 *****************************************************************************/
108
109DWORD HMDeviceMutexClass::OpenMutex(PHMHANDLEDATA pHMHandleData,
110 BOOL fInheritHandle,
111 LPCTSTR lpszMutexName)
112{
113 HANDLE hOpen32;
114
115 dprintf(("KERNEL32: HandleManager::Mutex::OpenMutex(%08xh,%08xh,%s)\n",
116 pHMHandleData,
117 fInheritHandle,
118 lpszMutexName));
119
120 hOpen32 = O32_OpenMutex(pHMHandleData->dwAccess, // call Open32
121 fInheritHandle,
122 lpszMutexName);
123
124 if (0 != hOpen32) // check success
125 {
126 pHMHandleData->hHMHandle = hOpen32; // save handle
127 return (NO_ERROR);
128 }
129 else
130 return (GetLastError());
131}
132
133/*****************************************************************************
134 * Name : HMReleaseMutex
135 * Purpose : router function for ReleaseMutex
136 * Parameters:
137 * Variables :
138 * Result :
139 * Remark :
140 * Status :
141 *
142 * Author : Patrick Haller [Tue, 1999/07/06 20:44]
143 *****************************************************************************/
144
145BOOL HMDeviceMutexClass::ReleaseMutex(PHMHANDLEDATA pHMHandleData)
146{
147 dprintf(("KERNEL32: HandleManager::Mutex::ReleaseMutex(%08xh)\n",
148 pHMHandleData->hHMHandle));
149
150 return (O32_ReleaseMutex(pHMHandleData->hHMHandle));
151}
152
Note: See TracBrowser for help on using the repository browser.