- Timestamp:
- Jun 22, 2001, 9:40:28 PM (24 years ago)
- Location:
- trunk/src/kernel32
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/HandleManager.cpp
r6049 r6069 1 /* $Id: HandleManager.cpp,v 1.6 5 2001-06-19 10:50:23sandervl Exp $ */1 /* $Id: HandleManager.cpp,v 1.66 2001-06-22 19:40:27 sandervl Exp $ */ 2 2 3 3 /* … … 1913 1913 1914 1914 while(TRUE) { 1915 dwResult = O32_MsgWaitForMultipleObjects(1, &hObject, FALSE,1916 1915 dwResult = HMMsgWaitForMultipleObjects(1, &hObject, FALSE, 1916 INFINITE, QS_ALLINPUT); 1917 1917 if(dwResult == WAIT_OBJECT_0 + 1) { 1918 1918 MSG msg ; … … 1948 1948 } 1949 1949 1950 // @@@PH Problem: wrong class (base class) is called instead of1951 // open32 class ?! Why ?!1952 1950 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 1953 1951 dwResult = pHMHandle->pDeviceHandler->WaitForSingleObject(&pHMHandle->hmHandleData, … … 2877 2875 DWORD dwTimeout) 2878 2876 { 2877 #ifdef USE_OS2SEMAPHORES 2878 int iIndex; /* index into the handle table */ 2879 DWORD dwResult; /* result from the device handler's API */ 2880 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 2881 2882 if(cObjects == 1) { 2883 return HMWaitForSingleObject(*lphObjects, dwTimeout); 2884 } 2885 /* validate handle */ 2886 iIndex = _HMHandleQuery(*lphObjects); /* get the index */ 2887 if (-1 == iIndex) /* error ? */ 2888 {//oh, oh. possible problem here 2889 //TODO: rewrite handling of other handles; don't forward to open32 2890 dprintf(("WANRING: HMWaitForMultipleObjects: unknown handle passed on to Open32 -> will not work if other handles are semaphores")); 2891 return O32_WaitForMultipleObjects(cObjects, lphObjects, fWaitAll, dwTimeout); 2892 } 2893 2894 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 2895 dwResult = pHMHandle->pDeviceHandler->WaitForMultipleObjects(&pHMHandle->hmHandleData, 2896 cObjects, lphObjects, fWaitAll, 2897 dwTimeout); 2898 2899 return (dwResult); /* deliver return code */ 2900 #else 2879 2901 ULONG ulIndex; 2880 2902 PHANDLE pArrayOfHandles; … … 2933 2955 2934 2956 return (rc); // OK, done 2957 #endif 2935 2958 } 2936 2959 … … 2973 2996 *****************************************************************************/ 2974 2997 2975 DWORD HMMsgWaitForMultipleObjects (DWORD nCount,2976 LPHANDLE pHandles,2998 DWORD HMMsgWaitForMultipleObjects (DWORD cObjects, 2999 LPHANDLE lphObjects, 2977 3000 BOOL fWaitAll, 2978 DWORD dw Milliseconds,3001 DWORD dwTimeout, 2979 3002 DWORD dwWakeMask) 2980 3003 { 3004 #ifdef USE_OS2SEMAPHORES 3005 int iIndex; /* index into the handle table */ 3006 DWORD dwResult; /* result from the device handler's API */ 3007 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3008 3009 /* validate handle */ 3010 iIndex = _HMHandleQuery(*lphObjects); /* get the index */ 3011 if (-1 == iIndex) /* error ? */ 3012 {//oh, oh. possible problem here 3013 //TODO: rewrite handling of other handles; don't forward to open32 3014 dprintf(("WANRING: HMWaitForMultipleObjects: unknown handle passed on to Open32 -> will not work if other handles are semaphores")); 3015 return O32_MsgWaitForMultipleObjects(cObjects, lphObjects, fWaitAll, dwTimeout, dwWakeMask); 3016 } 3017 3018 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3019 dwResult = pHMHandle->pDeviceHandler->MsgWaitForMultipleObjects(&pHMHandle->hmHandleData, 3020 cObjects, lphObjects, fWaitAll, 3021 dwTimeout, dwWakeMask); 3022 3023 return (dwResult); /* deliver return code */ 3024 #else 2981 3025 ULONG ulIndex; 2982 3026 PHANDLE pArrayOfHandles; … … 3030 3074 3031 3075 return (rc); // OK, done 3076 #endif 3032 3077 } 3033 3078 /***************************************************************************** -
trunk/src/kernel32/hmdevice.h
r6060 r6069 1 /* $Id: hmdevice.h,v 1.2 7 2001-06-21 21:07:53sandervl Exp $ */1 /* $Id: hmdevice.h,v 1.28 2001-06-22 19:40:27 sandervl Exp $ */ 2 2 3 3 /* … … 25 25 *****************************************************************************/ 26 26 27 #define HMTYPE_UNKNOWN 028 #define HMTYPE_MEMMAP 129 #define HMTYPE_DEVICE 230 #define HMTYPE_PROCESSTOKEN 331 #define HMTYPE_THREADTOKEN 427 #define HMTYPE_UNKNOWN 0 28 #define HMTYPE_MEMMAP 1 29 #define HMTYPE_DEVICE 2 30 #define HMTYPE_PROCESSTOKEN 3 31 #define HMTYPE_THREADTOKEN 4 32 32 #define HMTYPE_THREAD 5 33 33 #define HMTYPE_PIPE 6 34 #define HMTYPE_EVENTSEM 7 35 #define HMTYPE_MUTEXSEM 8 36 #define HMTYPE_SEMAPHORE 9 34 37 //..... 35 38 -
trunk/src/kernel32/hmevent.cpp
r6060 r6069 1 /* $Id: hmevent.cpp,v 1. 6 2001-06-21 21:07:53sandervl Exp $ */1 /* $Id: hmevent.cpp,v 1.7 2001-06-22 19:40:28 sandervl Exp $ */ 2 2 3 3 /* … … 122 122 pHMHandleData->dwFlags = fManualReset; 123 123 pHMHandleData->hHMHandle = hev; 124 pHMHandleData->dwInternalType = HMTYPE_EVENTSEM; 124 125 return ERROR_SUCCESS_W; 125 126 #else … … 188 189 return error2WinError(rc); 189 190 } 191 pHMHandleData->dwInternalType = HMTYPE_EVENTSEM; 190 192 pHMHandleData->hHMHandle = hev; 191 193 return ERROR_SUCCESS_W; … … 288 290 pHMHandleData->dwFlags = pHMSrcHandle->dwFlags; //fManualReset 289 291 pHMHandleData->hHMHandle = hev; 292 pHMHandleData->dwInternalType = HMTYPE_EVENTSEM; 290 293 SetLastError(ERROR_SUCCESS_W); 291 294 return TRUE; -
trunk/src/kernel32/hmmutex.cpp
r6060 r6069 1 /* $Id: hmmutex.cpp,v 1. 5 2001-06-21 21:07:53sandervl Exp $ */1 /* $Id: hmmutex.cpp,v 1.6 2001-06-22 19:40:28 sandervl Exp $ */ 2 2 3 3 /* … … 106 106 pHMHandleData->dwAccess = MUTEX_ALL_ACCESS_W; 107 107 pHMHandleData->hHMHandle = htmx; 108 pHMHandleData->dwInternalType = HMTYPE_MUTEXSEM; 108 109 return ERROR_SUCCESS_W; 109 110 #else … … 171 172 } 172 173 pHMHandleData->hHMHandle = hmtx; 174 pHMHandleData->dwInternalType = HMTYPE_MUTEXSEM; 173 175 return ERROR_SUCCESS_W; 174 176 #else … … 269 271 pHMHandleData->dwAccess = fdwAccess; 270 272 pHMHandleData->hHMHandle = hmtx; 273 pHMHandleData->dwInternalType = HMTYPE_MUTEXSEM; 271 274 SetLastError(ERROR_SUCCESS_W); 272 275 return TRUE; -
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.