source: trunk/src/kernel32/hmsemaphore.cpp@ 9748

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

Support DuplicateHandle for threads; cleaned up semaphore code

File size: 5.8 KB
Line 
1/* $Id: hmsemaphore.cpp,v 1.10 2003-02-04 11:29:00 sandervl Exp $ */
2
3/*
4 * Win32 Semaphore implementation
5 *
6 * TODO: Inheritance
7 * TODO: Does DCE_POSTONE work in Warp 3 or 4 with no FP applied?
8 * TODO: No inheritance when CreateSemaphore is called for existing named event semaphore?
9 * (see HMCreateSemaphore in handlemanager.cpp)
10 * TODO: OpenSemaphore does not work. (get SEM_INFO pointer)
11 * TODO: Name collisions with files & mutex not allowed. Check if this can happen in OS/2
12 *
13 * TODO: Use DosQueryEventSem to test the posted count against maximum count!!
14 *
15 * Project Odin Software License can be found in LICENSE.TXT
16 *
17 * Copyright 2001 Sander van Leeuwen (sandervl@xs4all.nl)
18 */
19
20#undef DEBUG_LOCAL
21//#define DEBUG_LOCAL
22
23
24/*****************************************************************************
25 * Remark *
26 *****************************************************************************
27
28 */
29
30
31/*****************************************************************************
32 * Includes *
33 *****************************************************************************/
34
35#include <os2win.h>
36#include <stdlib.h>
37#include <string.h>
38#include <heapshared.h>
39#include "unicode.h"
40#include "misc.h"
41
42#include "HandleManager.H"
43#include "HMSemaphore.h"
44#include "oslibdos.h"
45
46#define DBG_LOCALLOG DBG_hmsemaphore
47#include "dbglocal.h"
48
49/*****************************************************************************
50 * Defines *
51 *****************************************************************************/
52
53/*****************************************************************************
54 * Structures *
55 *****************************************************************************/
56
57/*****************************************************************************
58 * Local Prototypes *
59 *****************************************************************************/
60
61
62/*****************************************************************************
63 * Name : HMCreateSemaphore
64 * Purpose : router function for CreateSemaphore
65 * Parameters:
66 * Variables :
67 * Result :
68 * Remark :
69 * Status :
70 *
71 * Author : Patrick Haller [Tue, 1999/07/06 20:44]
72 *****************************************************************************/
73
74DWORD HMDeviceSemaphoreClass::CreateSemaphore(PHMHANDLEDATA pHMHandleData,
75 LPSECURITY_ATTRIBUTES lpsa,
76 LONG lInitialCount,
77 LONG lMaximumCount,
78 LPCTSTR lpszSemaphoreName)
79{
80 HANDLE hOpen32;
81
82 dprintf(("KERNEL32: HandleManager::Semaphore::CreateSemaphore(%08xh,%08xh,%08xh,%08xh,%s)\n",
83 pHMHandleData,
84 lpsa,
85 lInitialCount,
86 lMaximumCount,
87 lpszSemaphoreName));
88
89 hOpen32 = O32_CreateSemaphore(lpsa, // call Open32
90 lInitialCount,
91 lMaximumCount,
92 (LPTSTR)lpszSemaphoreName);
93
94 if (0 != hOpen32) // check success
95 {
96 pHMHandleData->hHMHandle = hOpen32; // save handle
97 return (NO_ERROR);
98 }
99 else
100 return (GetLastError());
101}
102
103
104/*****************************************************************************
105 * Name : HMOpenSemaphore
106 * Purpose : router function for OpenSemaphore
107 * Parameters:
108 * Variables :
109 * Result :
110 * Remark :
111 * Status :
112 *
113 * Author : Patrick Haller [Tue, 1999/07/06 20:44]
114 *****************************************************************************/
115
116DWORD HMDeviceSemaphoreClass::OpenSemaphore(PHMHANDLEDATA pHMHandleData,
117 BOOL fInheritHandle,
118 LPCTSTR lpszSemaphoreName)
119{
120 HANDLE hOpen32;
121
122 dprintf(("KERNEL32: HandleManager::Semaphore::OpenSemaphore(%08xh,%08xh,%s)\n",
123 pHMHandleData,
124 fInheritHandle,
125 lpszSemaphoreName));
126
127 hOpen32 = O32_OpenSemaphore(pHMHandleData->dwAccess, // call Open32
128 fInheritHandle,
129 lpszSemaphoreName);
130
131 if (0 != hOpen32) // check success
132 {
133 pHMHandleData->hHMHandle = hOpen32; // save handle
134 return (NO_ERROR);
135 }
136 else
137 return (GetLastError());
138}
139
140
141/*****************************************************************************
142 * Name : HMReleaseSemaphore
143 * Purpose : router function for ReleaseSemaphore
144 * Parameters:
145 * Variables :
146 * Result :
147 * Remark :
148 * Status :
149 *
150 * Author : Patrick Haller [Tue, 1999/07/06 20:44]
151 *****************************************************************************/
152
153BOOL HMDeviceSemaphoreClass::ReleaseSemaphore(PHMHANDLEDATA pHMHandleData,
154 LONG cReleaseCount,
155 LPLONG lpPreviousCount)
156{
157 dprintf(("KERNEL32: HandleManager::Semaphore::ReleaseSemaphore(%08xh,%08xh,%08xh)\n",
158 pHMHandleData->hHMHandle,
159 cReleaseCount,
160 lpPreviousCount));
161
162 return (O32_ReleaseSemaphore(pHMHandleData->hHMHandle,
163 cReleaseCount,
164 lpPreviousCount));
165}
166
167//******************************************************************************
168//******************************************************************************
Note: See TracBrowser for help on using the repository browser.