Changeset 6049 for trunk/src/kernel32/hmsemaphore.cpp
- Timestamp:
- Jun 19, 2001, 12:50:26 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/hmsemaphore.cpp
r2802 r6049 1 /* $Id: hmsemaphore.cpp,v 1. 3 2000-02-16 14:24:00sandervl Exp $ */1 /* $Id: hmsemaphore.cpp,v 1.4 2001-06-19 10:50:25 sandervl Exp $ */ 2 2 3 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: Name collisions with files & mutex not allowed. Check if this can happen in OS/2 11 * TODO: Does NOT work for sharing semaphores between processes!! 12 * 4 13 * Project Odin Software License can be found in LICENSE.TXT 5 * Win32 Unified Handle Manager for OS/26 * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de)14 * 15 * Copyright 2001 Sander van Leeuwen (sandervl@xs4all.nl) 7 16 */ 8 17 … … 22 31 *****************************************************************************/ 23 32 33 #ifdef USE_OS2SEMAPHORES 34 #define INCL_DOSSEMAPHORES 35 #include <os2wrap.h> 36 #include <win32type.h> 37 #include <win32api.h> 38 #include <winconst.h> 39 #else 24 40 #include <os2win.h> 41 #endif 25 42 #include <stdlib.h> 26 43 #include <string.h> … … 30 47 #include "HandleManager.H" 31 48 #include "HMSemaphore.h" 49 #include "oslibdos.h" 32 50 33 51 #define DBG_LOCALLOG DBG_hmsemaphore 34 52 #include "dbglocal.h" 53 54 #ifndef DCE_AUTORESET 55 #define DCE_AUTORESET 0x1000 /* DosCreateEventSem option to auto-reset */ 56 /* event semaphore on post. */ 57 #define DCE_POSTONE 0x0800 /* DosCreateEventSem option to post only */ 58 /* waiter and auto-reset the semaphore when*/ 59 /* there are multiple waiters. */ 60 #endif 35 61 36 62 … … 66 92 LPCTSTR lpszSemaphoreName) 67 93 { 68 HANDLE hOpen32; 94 #ifdef USE_OS2SEMAPHORES 95 APIRET rc; 96 HEV hev; 97 char szSemName[CCHMAXPATH]; 98 69 99 70 100 dprintf(("KERNEL32: HandleManager::Semaphore::CreateSemaphore(%08xh,%08xh,%08xh,%08xh,%s)\n", … … 75 105 lpszSemaphoreName)); 76 106 107 if(lMaximumCount <= 0 || lInitialCount < 0 || lInitialCount > lMaximumCount) { 108 dprintf(("ERROR: invalid parameter")); 109 return ERROR_INVALID_PARAMETER_W; 110 } 111 112 if(lpszSemaphoreName) { 113 strcpy(szSemName, "\\SEM32\\"); 114 strcat(szSemName, lpszSemaphoreName); 115 lpszSemaphoreName = szSemName; 116 } 117 //Manual reset means all threads waiting on the event semaphore will be 118 //unblocked and the app must manually reset the event semaphore 119 //Automatic reset -> only one waiting thread unblocked & state reset 120 rc = DosCreateEventSem(lpszSemaphoreName, &hev, DCE_POSTONE, lInitialCount); 121 122 if(rc) { 123 dprintf(("DosCreateEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 124 pHMHandleData->hHMHandle = 0; 125 return error2WinError(rc); 126 } 127 pHMHandleData->dwAccess = SEMAPHORE_ALL_ACCESS_W; 128 pHMHandleData->dwFlags = lMaximumCount; 129 pHMHandleData->hHMHandle = hev; 130 return ERROR_SUCCESS_W; 131 #else 132 HANDLE hOpen32; 133 134 dprintf(("KERNEL32: HandleManager::Semaphore::CreateSemaphore(%08xh,%08xh,%08xh,%08xh,%s)\n", 135 pHMHandleData, 136 lpsa, 137 lInitialCount, 138 lMaximumCount, 139 lpszSemaphoreName)); 140 77 141 hOpen32 = O32_CreateSemaphore(lpsa, // call Open32 78 142 lInitialCount, … … 87 151 else 88 152 return (O32_GetLastError()); 153 #endif 89 154 } 90 155 … … 106 171 LPCTSTR lpszSemaphoreName) 107 172 { 173 #ifdef USE_OS2SEMAPHORES 174 HEV hev; 175 APIRET rc; 176 char szSemName[CCHMAXPATH]; 177 178 dprintf(("KERNEL32: HandleManager::Semaphore::OpenSemaphore(%08xh,%08xh,%s)\n", 179 pHMHandleData, 180 fInheritHandle, 181 lpszSemaphoreName)); 182 183 if(lpszSemaphoreName == NULL) { 184 pHMHandleData->hHMHandle = 0; 185 return ERROR_INVALID_PARAMETER_W; 186 } 187 188 strcpy(szSemName, "\\SEM32\\"); 189 strcat(szSemName, lpszSemaphoreName); 190 rc = DosOpenEventSem(szSemName, &hev); 191 if(rc) { 192 dprintf(("DosOpenEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 193 pHMHandleData->hHMHandle = 0; 194 return error2WinError(rc); 195 } 196 pHMHandleData->hHMHandle = hev; 197 return ERROR_SUCCESS_W; 198 #else 108 199 HANDLE hOpen32; 109 200 … … 124 215 else 125 216 return (O32_GetLastError()); 126 } 127 217 #endif 218 } 219 220 /***************************************************************************** 221 * Name : HMDeviceEventClass::CloseHandle 222 * Purpose : close the handle 223 * Parameters: PHMHANDLEDATA pHMHandleData 224 * Variables : 225 * Result : API returncode 226 * Remark : 227 * Status : 228 * 229 * Author : 230 *****************************************************************************/ 231 232 #ifdef USE_OS2SEMAPHORES 233 BOOL HMDeviceSemaphoreClass::CloseHandle(PHMHANDLEDATA pHMHandleData) 234 { 235 APIRET rc; 236 237 if(pHMHandleData->hHMHandle) { 238 rc = DosCloseEventSem((HEV)pHMHandleData->hHMHandle); 239 if(rc) { 240 dprintf(("DosCloseEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 241 SetLastError(error2WinError(rc)); 242 return FALSE; 243 } 244 } 245 return TRUE; 246 } 247 #endif 248 249 250 /***************************************************************************** 251 * Name : HMDeviceEventClass::DuplicateHandle 252 * Purpose : 253 * Parameters: 254 * various parameters as required 255 * Variables : 256 * Result : 257 * Remark : the standard behaviour is to return an error code for non- 258 * existant request codes 259 * Status : 260 * 261 * Author : 262 *****************************************************************************/ 263 #ifdef USE_OS2SEMAPHORES 264 BOOL HMDeviceSemaphoreClass::DuplicateHandle(PHMHANDLEDATA pHMHandleData, HANDLE srcprocess, 265 PHMHANDLEDATA pHMSrcHandle, 266 HANDLE destprocess, 267 PHANDLE desthandle, 268 DWORD fdwAccess, 269 BOOL fInherit, 270 DWORD fdwOptions, 271 DWORD fdwOdinOptions) 272 { 273 APIRET rc; 274 HEV hev; 275 276 dprintf(("KERNEL32:HandleManager::DuplicateHandle %s(%08x,%08x,%08x,%08x,%08x)", 277 lpHMDeviceName, 278 pHMHandleData, 279 srcprocess, pHMSrcHandle, destprocess, desthandle)); 280 281 if(srcprocess != destprocess) { 282 DebugInt3(); 283 SetLastError(ERROR_ACCESS_DENIED_W); 284 return FALSE; 285 } 286 hev = (HEV)pHMSrcHandle->hHMHandle; 287 rc = DosOpenEventSem(NULL, &hev); 288 if(rc) { 289 dprintf(("DosOpenEventSem %x failed with rc %d", pHMSrcHandle->hHMHandle, rc)); 290 pHMHandleData->hHMHandle = 0; 291 SetLastError(error2WinError(rc)); 292 return FALSE; 293 } 294 pHMHandleData->dwAccess = fdwAccess; 295 pHMHandleData->dwFlags = pHMSrcHandle->dwFlags; //lMaximumCount; 296 pHMHandleData->hHMHandle = hev; 297 SetLastError(ERROR_SUCCESS_W); 298 return TRUE; 299 } 300 #endif 128 301 129 302 /***************************************************************************** … … 143 316 LPLONG lpPreviousCount) 144 317 { 318 #ifdef USE_OS2SEMAPHORES 319 APIRET rc; 320 ULONG count; 321 322 dprintf2(("KERNEL32: HandleManager::Semaphore::ReleaseSemaphore(%08xh,%08xh,%08xh)\n", 323 pHMHandleData->hHMHandle, 324 cReleaseCount, 325 lpPreviousCount)); 326 327 if(!(pHMHandleData->dwAccess & SEMAPHORE_MODIFY_STATE_W) ) 328 { 329 dprintf(("ERROR: Access denied!!")); 330 SetLastError(ERROR_ACCESS_DENIED_W); 331 return FALSE; 332 } 333 334 rc = DosResetEventSem(pHMHandleData->hHMHandle, &count); 335 if(rc) { 336 dprintf(("DosResetEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 337 SetLastError(error2WinError(rc)); 338 return FALSE; 339 } 340 SetLastError(ERROR_SUCCESS_W); 341 return TRUE; 342 #else 145 343 dprintf(("KERNEL32: HandleManager::Semaphore::ReleaseSemaphore(%08xh,%08xh,%08xh)\n", 146 344 pHMHandleData->hHMHandle, … … 151 349 cReleaseCount, 152 350 lpPreviousCount)); 153 } 154 351 #endif 352 } 353
Note:
See TracChangeset
for help on using the changeset viewer.