Ignore:
Timestamp:
Feb 4, 2003, 12:29:03 PM (23 years ago)
Author:
sandervl
Message:

Support DuplicateHandle for threads; cleaned up semaphore code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/hmmutex.cpp

    r6084 r9748  
    1 /* $Id: hmmutex.cpp,v 1.7 2001-06-23 16:59:28 sandervl Exp $ */
     1/* $Id: hmmutex.cpp,v 1.8 2003-02-04 11:28:58 sandervl Exp $ */
    22
    33/*
     
    2929 *****************************************************************************/
    3030
    31 #ifdef USE_OS2SEMAPHORES
    32 #define INCL_DOSSEMAPHORES
    33 #define INCL_DOSERRORS
    34 #include <os2wrap.h>
    35 #include <win32type.h>
    36 #include <win32api.h>
    37 #include <winconst.h>
    38 #else
    3931#include <os2win.h>
    40 #endif
    4132#include <stdlib.h>
    4233#include <string.h>
     
    8273                                      LPCTSTR               lpszMutexName)
    8374{
    84 #ifdef USE_OS2SEMAPHORES
    85   APIRET rc;
    86   HMTX htmx;
    87   char szSemName[CCHMAXPATH];
    88 
    89   dprintf(("KERNEL32: HandleManager::Mutex::CreateMutex(%08xh,%08xh,%08xh,%s)\n",
    90            pHMHandleData,
    91            lpsa,
    92            fInitialOwner,
    93            lpszMutexName));
    94 
    95   if(lpszMutexName) {
    96       strcpy(szSemName, "\\SEM32\\");
    97       strcat(szSemName, lpszMutexName);
    98       lpszMutexName = szSemName;
    99       FixSemName((char *)lpszMutexName);
    100   }
    101   rc = DosCreateMutexSem(lpszMutexName, &htmx, 0, fInitialOwner);
    102 
    103   if(rc) {
    104       dprintf(("DosCreateMutexSem %x failed with rc %d", pHMHandleData->hHMHandle, rc));
    105       pHMHandleData->hHMHandle = 0;
    106       return error2WinError(rc);
    107   }
    108   pHMHandleData->dwAccess  = MUTEX_ALL_ACCESS_W;
    109   pHMHandleData->hHMHandle = htmx;
    110   pHMHandleData->dwInternalType = HMTYPE_MUTEXSEM;
    111   return ERROR_SUCCESS_W;
    112 #else
    11375  HANDLE hOpen32;
    11476
     
    12991  }
    13092  else
    131     return (O32_GetLastError());
    132 #endif
     93    return (GetLastError());
    13394}
    13495
     
    150111                                    LPCTSTR               lpszMutexName)
    151112{
    152 #ifdef USE_OS2SEMAPHORES
    153   HMTX   hmtx;
    154   APIRET rc;
    155   char szSemName[CCHMAXPATH];
    156 
    157   dprintf(("KERNEL32: HandleManager::Mutex::OpenMutex(%08xh,%08xh,%s)\n",
    158            pHMHandleData,
    159            fInheritHandle,
    160            lpszMutexName));
    161 
    162   if(lpszMutexName == NULL) {
    163       pHMHandleData->hHMHandle = 0;
    164       return ERROR_INVALID_PARAMETER_W;
    165   }
    166 
    167   strcpy(szSemName, "\\SEM32\\");
    168   strcat(szSemName, lpszMutexName);
    169   FixSemName(szSemName);
    170   rc = DosOpenMutexSem(szSemName, &hmtx);
    171   if(rc) {
    172       dprintf(("DosOpenMutexSem %x failed with rc %d", pHMHandleData->hHMHandle, rc));
    173       pHMHandleData->hHMHandle = 0;
    174       return error2WinError(rc);
    175   }
    176   pHMHandleData->hHMHandle = hmtx;
    177   pHMHandleData->dwInternalType = HMTYPE_MUTEXSEM;
    178   return ERROR_SUCCESS_W;
    179 #else
    180113  HANDLE hOpen32;
    181114
     
    195128  }
    196129  else
    197     return (O32_GetLastError());
    198 #endif
     130    return (GetLastError());
    199131}
    200 
    201 /*****************************************************************************
    202  * Name      : HMDeviceMutexClass::CloseHandle
    203  * Purpose   : close the handle
    204  * Parameters: PHMHANDLEDATA pHMHandleData
    205  * Variables :
    206  * Result    : API returncode
    207  * Remark    :
    208  * Status    :
    209  *
    210  * Author    :
    211  *****************************************************************************/
    212 
    213 #ifdef USE_OS2SEMAPHORES
    214 BOOL HMDeviceMutexClass::CloseHandle(PHMHANDLEDATA pHMHandleData)
    215 {
    216   APIRET rc;
    217 
    218   if(pHMHandleData->hHMHandle) {
    219       rc = DosCloseMutexSem((HEV)pHMHandleData->hHMHandle);
    220       if(rc) {
    221           dprintf(("DosCloseMutexSem %x failed with rc %d", pHMHandleData->hHMHandle, rc));
    222           SetLastError(error2WinError(rc));
    223           return FALSE;
    224       }
    225   }
    226   return TRUE;
    227 }
    228 #endif
    229 
    230 /*****************************************************************************
    231  * Name      : HMDeviceMutexClass::DuplicateHandle
    232  * Purpose   :
    233  * Parameters:
    234  *             various parameters as required
    235  * Variables :
    236  * Result    :
    237  * Remark    : the standard behaviour is to return an error code for non-
    238  *             existant request codes
    239  * Status    :
    240  *
    241  * Author    :
    242  *****************************************************************************/
    243 #ifdef USE_OS2SEMAPHORES
    244 BOOL HMDeviceMutexClass::DuplicateHandle(PHMHANDLEDATA pHMHandleData, HANDLE  srcprocess,
    245                                PHMHANDLEDATA pHMSrcHandle,
    246                                HANDLE  destprocess,
    247                                PHANDLE desthandle,
    248                                DWORD   fdwAccess,
    249                                BOOL    fInherit,
    250                                DWORD   fdwOptions,
    251                                DWORD   fdwOdinOptions)
    252 {
    253   APIRET rc;
    254   HMTX hmtx;
    255  
    256   dprintf(("KERNEL32:HandleManager::DuplicateHandle %s(%08x,%08x,%08x,%08x,%08x) - NOT IMPLEMENTED!!!!!!!!\n",
    257            lpHMDeviceName,
    258            pHMHandleData,
    259            srcprocess, pHMSrcHandle, destprocess, desthandle));
    260 
    261   if(srcprocess != destprocess) {
    262       DebugInt3();
    263       SetLastError(ERROR_ACCESS_DENIED_W);
    264       return FALSE;
    265   }
    266   hmtx = (HMTX)pHMSrcHandle->hHMHandle;
    267   rc = DosOpenMutexSem(NULL, &hmtx);
    268   if(rc) {
    269       dprintf(("DosOpenMutexSem %x failed with rc %d", pHMSrcHandle->hHMHandle, rc));
    270       pHMHandleData->hHMHandle = 0;
    271       SetLastError(error2WinError(rc));
    272       return FALSE;
    273   }
    274   pHMHandleData->dwAccess  = fdwAccess;
    275   pHMHandleData->hHMHandle = hmtx;
    276   pHMHandleData->dwInternalType = HMTYPE_MUTEXSEM;
    277   SetLastError(ERROR_SUCCESS_W);
    278   return TRUE;
    279 }
    280 #endif
    281 
    282 
    283 #ifdef USE_OS2SEMAPHORES
    284 /*****************************************************************************
    285  * Name      : DWORD HMDeviceOpen32Class::WaitForSingleObject
    286  * Purpose   : object synchronization
    287  * Parameters: PHMHANDLEDATA pHMHandleData
    288  *             DWORD dwTimeout
    289  * Variables :
    290  * Result    : API returncode
    291  * Remark    :
    292  * Status    :
    293  *
    294  * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
    295  *****************************************************************************/
    296 
    297 DWORD HMDeviceMutexClass::WaitForSingleObject(PHMHANDLEDATA pHMHandleData,
    298                                               DWORD         dwTimeout)
    299 {
    300  DWORD rc;
    301 
    302   dprintf2(("KERNEL32: HMDeviceMutexClass::WaitForSingleObject(%08xh %08xh)",
    303             pHMHandleData->hHMHandle, dwTimeout));
    304 
    305   if(!(pHMHandleData->dwAccess & SYNCHRONIZE_W) )
    306   {
    307       dprintf(("ERROR: Access denied!!"));
    308       SetLastError(ERROR_ACCESS_DENIED_W);
    309       return FALSE;
    310   }
    311 
    312   rc = DosRequestMutexSem(pHMHandleData->hHMHandle, dwTimeout);
    313   if(rc && rc != ERROR_INTERRUPT && rc != ERROR_TIMEOUT && rc != ERROR_SEM_OWNER_DIED) {
    314       dprintf(("DosWaitEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc));
    315       SetLastError(error2WinError(rc));
    316       return WAIT_FAILED_W;
    317   }
    318   SetLastError(ERROR_SUCCESS_W);
    319   if(rc == ERROR_INTERRUPT || rc == ERROR_SEM_OWNER_DIED) {
    320       return WAIT_ABANDONED_W;
    321   }
    322   else
    323   if(rc == ERROR_TIMEOUT) {
    324       return WAIT_TIMEOUT_W;
    325   }
    326   return WAIT_OBJECT_0_W;
    327 }
    328 #endif
    329 
    330 #ifdef USE_OS2SEMAPHORES
    331 /*****************************************************************************
    332  * Name      : DWORD HMDeviceOpen32Class::WaitForSingleObjectEx
    333  * Purpose   : object synchronization
    334  * Parameters: PHMHANDLEDATA pHMHandleData
    335  *             DWORD dwTimeout
    336  *             BOOL  fAlertable
    337  * Variables :
    338  * Result    : API returncode
    339  * Remark    :
    340  * Status    :
    341  *
    342  * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
    343  *****************************************************************************/
    344 
    345 DWORD HMDeviceMutexClass::WaitForSingleObjectEx(PHMHANDLEDATA pHMHandleData,
    346                                                 DWORD         dwTimeout,
    347                                                 BOOL          fAlertable)
    348 {
    349   dprintf2(("KERNEL32: HMDeviceMutexClass::WaitForSingleObjectEx(%08xh,%08h,%08xh) not implemented correctly.\n",
    350             pHMHandleData->hHMHandle, dwTimeout, fAlertable));
    351 
    352   if(!(pHMHandleData->dwAccess & SYNCHRONIZE_W) )
    353   {
    354       dprintf(("ERROR: Access denied!!"));
    355       SetLastError(ERROR_ACCESS_DENIED_W);
    356       return WAIT_FAILED_W;
    357   }
    358 
    359   return WaitForSingleObject(pHMHandleData, dwTimeout);
    360 }
    361 #endif
    362 
    363 #ifdef USE_OS2SEMAPHORES
    364 /*****************************************************************************
    365  * Name      : BOOL HMDeviceMutexClass::MsgWaitForMultipleObjects
    366  * Purpose   :
    367  * Variables :
    368  * Result    :
    369  * Remark    :
    370  * Status    :
    371  *
    372  * Author    : SvL
    373  *****************************************************************************/
    374 DWORD HMDeviceMutexClass::MsgWaitForMultipleObjects(PHMHANDLEDATA pHMHandleData,
    375                                                     DWORD      nCount,
    376                                                     PHANDLE    pHandles,
    377                                                     BOOL       fWaitAll,
    378                                                     DWORD      dwMilliseconds,
    379                                                     DWORD      dwWakeMask)
    380 {
    381     return HMSemMsgWaitForMultipleObjects(nCount, pHandles, fWaitAll, dwMilliseconds, dwWakeMask);
    382 }
    383 #endif
    384 
    385 #ifdef USE_OS2SEMAPHORES
    386 /*****************************************************************************
    387  * Name      : BOOL HMDeviceMutexClass::WaitForMultipleObjects
    388  * Purpose   :
    389  * Variables :
    390  * Result    :
    391  * Remark    :
    392  * Status    :
    393  *
    394  * Author    : SvL
    395  *****************************************************************************/
    396 DWORD HMDeviceMutexClass::WaitForMultipleObjects(PHMHANDLEDATA pHMHandleData,
    397                                                  DWORD   cObjects,
    398                                                  PHANDLE lphObjects,
    399                                                  BOOL    fWaitAll,
    400                                                  DWORD   dwTimeout)
    401 {
    402     return HMSemWaitForMultipleObjects(cObjects, lphObjects, fWaitAll, dwTimeout);
    403 }
    404 #endif
    405132
    406133/*****************************************************************************
     
    418145BOOL HMDeviceMutexClass::ReleaseMutex(PHMHANDLEDATA pHMHandleData)
    419146{
    420 #ifdef USE_OS2SEMAPHORES
    421   APIRET rc;
    422  
    423   dprintf(("KERNEL32: HandleManager::Mutex::ReleaseMutex(%08xh)\n",
    424            pHMHandleData->hHMHandle));
    425 
    426   rc = DosReleaseMutexSem(pHMHandleData->hHMHandle);
    427   if(rc) {
    428       dprintf(("DosReleaseMutexSem %x failed with rc %d", pHMHandleData->hHMHandle, rc));
    429       SetLastError(error2WinError(rc));
    430       return FALSE;
    431   }
    432   SetLastError(ERROR_SUCCESS_W);
    433   return TRUE;
    434 #else
    435147  dprintf(("KERNEL32: HandleManager::Mutex::ReleaseMutex(%08xh)\n",
    436148           pHMHandleData->hHMHandle));
    437149
    438150  return (O32_ReleaseMutex(pHMHandleData->hHMHandle));
    439 #endif
    440151}
    441152
Note: See TracChangeset for help on using the changeset viewer.