Ignore:
Timestamp:
Jun 19, 2001, 12:50:26 PM (24 years ago)
Author:
sandervl
Message:

semaphore rewrite (not activated)

File:
1 edited

Legend:

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

    r2802 r6049  
    1 /* $Id: hmmutex.cpp,v 1.3 2000-02-16 14:24:00 sandervl Exp $ */
     1/* $Id: hmmutex.cpp,v 1.4 2001-06-19 10:50:25 sandervl Exp $ */
    22
    33/*
     4 * Win32 Mutex Semaphore implementation
     5 *
     6 * TODO: Inheritance
     7 * TODO: No inheritance when CreateMutex is called for existing named event semaphore?
     8 *       (see HMCreateMutex in handlemanager.cpp)
     9 * TODO: Name collisions with files & mutex not allowed. Check if this can happen in OS/2
     10 *
    411 * Project Odin Software License can be found in LICENSE.TXT
    5  * Win32 Unified Handle Manager for OS/2
    6  * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de)
     12 *
     13 * Copyright 2001 Sander van Leeuwen (sandervl@xs4all.nl)
    714 */
    815
     
    2229 *****************************************************************************/
    2330
     31#ifdef USE_OS2SEMAPHORES
     32#define INCL_DOSSEMAPHORES
     33#include <os2wrap.h>
     34#include <win32type.h>
     35#include <win32api.h>
     36#include <winconst.h>
     37#else
    2438#include <os2win.h>
     39#endif
    2540#include <stdlib.h>
    2641#include <string.h>
    2742#include "unicode.h"
    2843#include "misc.h"
     44#include "oslibdos.h"
    2945
    3046#include "HandleManager.H"
     
    6480                                      LPCTSTR               lpszMutexName)
    6581{
     82#ifdef USE_OS2SEMAPHORES
     83  APIRET rc;
     84  HMTX htmx;
     85  char szSemName[CCHMAXPATH];
     86
     87  dprintf(("KERNEL32: HandleManager::Mutex::CreateMutex(%08xh,%08xh,%08xh,%s)\n",
     88           pHMHandleData,
     89           lpsa,
     90           fInitialOwner,
     91           lpszMutexName));
     92
     93  if(lpszMutexName) {
     94      strcpy(szSemName, "\\SEM32\\");
     95      strcat(szSemName, lpszMutexName);
     96      lpszMutexName = szSemName;
     97  }
     98  rc = DosCreateMutexSem(lpszMutexName, &htmx, 0, fInitialOwner);
     99
     100  if(rc) {
     101      dprintf(("DosCreateMutexSem %x failed with rc %d", pHMHandleData->hHMHandle, rc));
     102      pHMHandleData->hHMHandle = 0;
     103      return error2WinError(rc);
     104  }
     105  pHMHandleData->dwAccess  = MUTEX_ALL_ACCESS_W;
     106  pHMHandleData->hHMHandle = htmx;
     107  return ERROR_SUCCESS_W;
     108#else
    66109  HANDLE hOpen32;
    67110
     
    83126  else
    84127    return (O32_GetLastError());
     128#endif
    85129}
    86130
     
    102146                                    LPCTSTR               lpszMutexName)
    103147{
     148#ifdef USE_OS2SEMAPHORES
     149  HMTX   hmtx;
     150  APIRET rc;
     151  char szSemName[CCHMAXPATH];
     152
     153  dprintf(("KERNEL32: HandleManager::Mutex::OpenMutex(%08xh,%08xh,%s)\n",
     154           pHMHandleData,
     155           fInheritHandle,
     156           lpszMutexName));
     157
     158  if(lpszMutexName == NULL) {
     159      pHMHandleData->hHMHandle = 0;
     160      return ERROR_INVALID_PARAMETER_W;
     161  }
     162
     163  strcpy(szSemName, "\\SEM32\\");
     164  strcat(szSemName, lpszMutexName);
     165  rc = DosOpenMutexSem(szSemName, &hmtx);
     166  if(rc) {
     167      dprintf(("DosOpenMutexSem %x failed with rc %d", pHMHandleData->hHMHandle, rc));
     168      pHMHandleData->hHMHandle = 0;
     169      return error2WinError(rc);
     170  }
     171  pHMHandleData->hHMHandle = hmtx;
     172  return ERROR_SUCCESS_W;
     173#else
    104174  HANDLE hOpen32;
    105175
     
    120190  else
    121191    return (O32_GetLastError());
    122 }
    123 
     192#endif
     193}
     194
     195/*****************************************************************************
     196 * Name      : HMDeviceMutexClass::CloseHandle
     197 * Purpose   : close the handle
     198 * Parameters: PHMHANDLEDATA pHMHandleData
     199 * Variables :
     200 * Result    : API returncode
     201 * Remark    :
     202 * Status    :
     203 *
     204 * Author    :
     205 *****************************************************************************/
     206
     207#ifdef USE_OS2SEMAPHORES
     208BOOL HMDeviceMutexClass::CloseHandle(PHMHANDLEDATA pHMHandleData)
     209{
     210  APIRET rc;
     211
     212  if(pHMHandleData->hHMHandle) {
     213      rc = DosCloseMutexSem((HEV)pHMHandleData->hHMHandle);
     214      if(rc) {
     215          dprintf(("DosCloseMutexSem %x failed with rc %d", pHMHandleData->hHMHandle, rc));
     216          SetLastError(error2WinError(rc));
     217          return FALSE;
     218      }
     219  }
     220  return TRUE;
     221}
     222#endif
     223
     224/*****************************************************************************
     225 * Name      : HMDeviceMutexClass::DuplicateHandle
     226 * Purpose   :
     227 * Parameters:
     228 *             various parameters as required
     229 * Variables :
     230 * Result    :
     231 * Remark    : the standard behaviour is to return an error code for non-
     232 *             existant request codes
     233 * Status    :
     234 *
     235 * Author    :
     236 *****************************************************************************/
     237#ifdef USE_OS2SEMAPHORES
     238BOOL HMDeviceMutexClass::DuplicateHandle(PHMHANDLEDATA pHMHandleData, HANDLE  srcprocess,
     239                               PHMHANDLEDATA pHMSrcHandle,
     240                               HANDLE  destprocess,
     241                               PHANDLE desthandle,
     242                               DWORD   fdwAccess,
     243                               BOOL    fInherit,
     244                               DWORD   fdwOptions,
     245                               DWORD   fdwOdinOptions)
     246{
     247  APIRET rc;
     248  HMTX hmtx;
     249 
     250  dprintf(("KERNEL32:HandleManager::DuplicateHandle %s(%08x,%08x,%08x,%08x,%08x) - NOT IMPLEMENTED!!!!!!!!\n",
     251           lpHMDeviceName,
     252           pHMHandleData,
     253           srcprocess, pHMSrcHandle, destprocess, desthandle));
     254
     255  if(srcprocess != destprocess) {
     256      DebugInt3();
     257      SetLastError(ERROR_ACCESS_DENIED_W);
     258      return FALSE;
     259  }
     260  hmtx = (HMTX)pHMSrcHandle->hHMHandle;
     261  rc = DosOpenMutexSem(NULL, &hmtx);
     262  if(rc) {
     263      dprintf(("DosOpenMutexSem %x failed with rc %d", pHMSrcHandle->hHMHandle, rc));
     264      pHMHandleData->hHMHandle = 0;
     265      SetLastError(error2WinError(rc));
     266      return FALSE;
     267  }
     268  pHMHandleData->dwAccess  = fdwAccess;
     269  pHMHandleData->hHMHandle = hmtx;
     270  SetLastError(ERROR_SUCCESS_W);
     271  return TRUE;
     272}
     273#endif
    124274
    125275/*****************************************************************************
     
    137287BOOL HMDeviceMutexClass::ReleaseMutex(PHMHANDLEDATA pHMHandleData)
    138288{
     289#ifdef USE_OS2SEMAPHORES
     290  APIRET rc;
     291 
    139292  dprintf(("KERNEL32: HandleManager::Mutex::ReleaseMutex(%08xh)\n",
    140293           pHMHandleData->hHMHandle));
    141294
     295  rc = DosReleaseMutexSem(pHMHandleData->hHMHandle);
     296  if(rc) {
     297      dprintf(("DosReleaseMutexSem %x failed with rc %d", pHMHandleData->hHMHandle, rc));
     298      SetLastError(error2WinError(rc));
     299      return FALSE;
     300  }
     301  SetLastError(ERROR_SUCCESS_W);
     302  return TRUE;
     303#else
     304  dprintf(("KERNEL32: HandleManager::Mutex::ReleaseMutex(%08xh)\n",
     305           pHMHandleData->hHMHandle));
     306
    142307  return (O32_ReleaseMutex(pHMHandleData->hHMHandle));
    143 }
    144 
     308#endif
     309}
     310
Note: See TracChangeset for help on using the changeset viewer.