Changeset 6069 for trunk/src/kernel32/hmsemaphore.cpp
- Timestamp:
- Jun 22, 2001, 9:40:28 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/hmsemaphore.cpp
r6060 r6069 1 /* $Id: hmsemaphore.cpp,v 1. 5 2001-06-21 21:07:54sandervl Exp $ */1 /* $Id: hmsemaphore.cpp,v 1.6 2001-06-22 19:40:28 sandervl Exp $ */ 2 2 3 3 /* … … 8 8 * TODO: No inheritance when CreateSemaphore is called for existing named event semaphore? 9 9 * (see HMCreateSemaphore in handlemanager.cpp) 10 * TODO: OpenSemaphore does not work right now! initialcount/maximumcount)10 * TODO: OpenSemaphore does not work. (get SEM_INFO pointer) 11 11 * TODO: Name collisions with files & mutex not allowed. Check if this can happen in OS/2 12 * TODO: Does NOT work for sharing semaphores between processes!!13 12 * 14 13 * Project Odin Software License can be found in LICENSE.TXT … … 44 43 #include <stdlib.h> 45 44 #include <string.h> 45 #include <heapshared.h> 46 46 #include "unicode.h" 47 47 #include "misc.h" … … 62 62 #endif 63 63 64 typedef struct { 65 LONG currentCount; 66 LONG maximumCount; 67 LONG refCount; 68 HEV hev; 69 } SEM_INFO, *PSEM_INFO; 64 70 65 71 /***************************************************************************** … … 125 131 } 126 132 pHMHandleData->dwAccess = SEMAPHORE_ALL_ACCESS_W; 127 pHMHandleData->dwFlags = lMaximumCount; 128 pHMHandleData->dwCreation= lInitialCount; 129 pHMHandleData->hHMHandle = hev; 133 PSEM_INFO pSemInfo = (PSEM_INFO)_smalloc(sizeof(SEM_INFO)); 134 pSemInfo->refCount = 1; 135 pSemInfo->hev = hev; 136 pSemInfo->maximumCount = lMaximumCount; 137 pSemInfo->currentCount = lInitialCount; 138 pHMHandleData->hHMHandle = (DWORD)pSemInfo; 139 pHMHandleData->dwInternalType = HMTYPE_SEMAPHORE; 130 140 return ERROR_SUCCESS_W; 131 141 #else … … 196 206 } 197 207 pHMHandleData->hHMHandle = hev; 208 pHMHandleData->dwInternalType = HMTYPE_SEMAPHORE; 198 209 return ERROR_SUCCESS_W; 199 210 #else … … 235 246 { 236 247 APIRET rc; 237 238 if(pHMHandleData->hHMHandle) { 239 rc = DosCloseEventSem((HEV)pHMHandleData->hHMHandle); 248 PSEM_INFO pSemInfo = (PSEM_INFO)pHMHandleData->hHMHandle; 249 250 if(pSemInfo) { 251 rc = DosCloseEventSem(pSemInfo->hev); 240 252 if(rc) { 241 dprintf(("DosCloseEventSem %x failed with rc %d", p HMHandleData->hHMHandle, rc));253 dprintf(("DosCloseEventSem %x failed with rc %d", pSemInfo->hev, rc)); 242 254 SetLastError(error2WinError(rc)); 243 255 return FALSE; 256 } 257 if(InterlockedDecrement(&pSemInfo->refCount) == 0) { 258 free(pSemInfo); 244 259 } 245 260 } … … 273 288 { 274 289 APIRET rc; 275 HEV hev; 290 HEV hev; 291 PSEM_INFO pSemInfo = (PSEM_INFO)pHMSrcHandle->hHMHandle; 276 292 277 293 dprintf(("KERNEL32:HandleManager::DuplicateHandle %s(%08x,%08x,%08x,%08x,%08x)", … … 285 301 return FALSE; 286 302 } 287 hev = (HEV)pHMSrcHandle->hHMHandle; 288 rc = DosOpenEventSem(NULL, &hev); 289 if(rc) { 290 dprintf(("DosOpenEventSem %x failed with rc %d", pHMSrcHandle->hHMHandle, rc)); 291 pHMHandleData->hHMHandle = 0; 292 SetLastError(error2WinError(rc)); 293 return FALSE; 294 } 303 InterlockedIncrement(&pSemInfo->refCount); 295 304 pHMHandleData->dwAccess = fdwAccess; 296 pHMHandleData->dwFlags = pHMSrcHandle->dwFlags; //lMaximumCount; 297 pHMHandleData->dwCreation= pHMSrcHandle->dwCreation; //lInitialCount; 298 pHMHandleData->hHMHandle = hev; 305 pHMHandleData->hHMHandle = (DWORD)pSemInfo; 306 pHMHandleData->dwInternalType = HMTYPE_SEMAPHORE; 299 307 SetLastError(ERROR_SUCCESS_W); 300 308 return TRUE; … … 317 325 318 326 DWORD HMDeviceSemaphoreClass::WaitForSingleObject(PHMHANDLEDATA pHMHandleData, 319 DWORD dwTimeout)327 DWORD dwTimeout) 320 328 { 321 329 DWORD rc; … … 331 339 } 332 340 333 rc = DosWaitEventSem(pHMHandleData->hHMHandle, dwTimeout); 341 PSEM_INFO pSemInfo = (PSEM_INFO)pHMHandleData->hHMHandle; 342 343 if(InterlockedDecrement(&pSemInfo->currentCount) >= 0) { 344 SetLastError(ERROR_SUCCESS_W); 345 return WAIT_OBJECT_0_W; 346 } 347 348 rc = DosWaitEventSem(pSemInfo->hev, dwTimeout); 334 349 if(rc && rc != ERROR_INTERRUPT && rc != ERROR_TIMEOUT && rc != ERROR_SEM_OWNER_DIED) { 335 dprintf(("DosWaitEventSem %x failed with rc %d", p HMHandleData->hHMHandle, rc));350 dprintf(("DosWaitEventSem %x failed with rc %d", pSemInfo->hev, rc)); 336 351 SetLastError(error2WinError(rc)); 337 352 return WAIT_FAILED_W; … … 477 492 } 478 493 479 rc = DosResetEventSem(pHMHandleData->hHMHandle, &count); 494 PSEM_INFO pSemInfo = (PSEM_INFO)pHMHandleData->hHMHandle; 495 496 if(InterlockedIncrement(&pSemInfo->currentCount) > 0) { 497 //TODO: this is NOT thread safe: 498 if(pSemInfo->currentCount > pSemInfo->maximumCount) { 499 pSemInfo->currentCount = pSemInfo->maximumCount; 500 } 501 SetLastError(ERROR_SUCCESS_W); 502 return TRUE; 503 } 504 505 rc = DosResetEventSem(pSemInfo->hev, &count); 480 506 if(rc) { 481 dprintf(("DosResetEventSem %x failed with rc %d", p HMHandleData->hHMHandle, rc));507 dprintf(("DosResetEventSem %x failed with rc %d", pSemInfo->hev, rc)); 482 508 SetLastError(error2WinError(rc)); 483 509 return FALSE;
Note:
See TracChangeset
for help on using the changeset viewer.