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/hmevent.cpp

    r5332 r6049  
    1 /* $Id: hmevent.cpp,v 1.4 2001-03-19 19:27:13 sandervl Exp $ */
     1/* $Id: hmevent.cpp,v 1.5 2001-06-19 10:50:24 sandervl Exp $ */
    22
    33/*
     4 * Win32 Event 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 CreateEvent is called for existing named event semaphore?
     9 *       (see HMCreateEvent in handlemanager.cpp)
     10 * TODO: Name collisions with files & mutex not allowed. Check if this can happen in OS/2
     11 *
    412 * 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)
     13 *
     14 * Copyright 2001 Sander van Leeuwen (sandervl@xs4all.nl)
    715 */
    816
     
    2230 *****************************************************************************/
    2331
     32#ifdef USE_OS2SEMAPHORES
     33#define INCL_DOSSEMAPHORES
     34#include <os2wrap.h>
     35#include <win32type.h>
     36#include <win32api.h>
     37#include <winconst.h>
     38#else
    2439#include <os2win.h>
     40#endif
     41
    2542#include <stdlib.h>
    2643#include <string.h>
     
    3047#include "HandleManager.H"
    3148#include "HMEvent.h"
     49#include "oslibdos.h"
    3250
    3351#define DBG_LOCALLOG    DBG_hmevent
    3452#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
    3561
    3662/*****************************************************************************
     
    6591                                      LPCTSTR               lpszEventName)
    6692{
    67   HANDLE hOpen32;
     93#ifdef USE_OS2SEMAPHORES
     94  APIRET rc;
     95  HEV hev;
     96  char szSemName[CCHMAXPATH];
    6897
    6998  dprintf(("KERNEL32: HandleManager::Event::CreateEvent(%08xh,%08xh,%08xh,%08xh,%s)\n",
     
    74103           lpszEventName));
    75104
     105  if(lpszEventName) {
     106      strcpy(szSemName, "\\SEM32\\");
     107      strcat(szSemName, lpszEventName);
     108      lpszEventName = szSemName;
     109  }
     110  //Manual reset means all threads waiting on the event semaphore will be
     111  //unblocked and the app must manually reset the event semaphore
     112  //Automatic reset -> only one waiting thread unblocked & state reset
     113  rc = DosCreateEventSem(lpszEventName, &hev, (fManualReset) ? 0 : DCE_POSTONE, fInitialState);
     114
     115  if(rc) {
     116      dprintf(("DosCreateEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc));
     117      pHMHandleData->hHMHandle = 0;
     118      return error2WinError(rc);
     119  }
     120  pHMHandleData->dwAccess  = EVENT_ALL_ACCESS_W;
     121  pHMHandleData->dwFlags   = fManualReset;
     122  pHMHandleData->hHMHandle = hev;
     123  return ERROR_SUCCESS_W;
     124#else
     125  HANDLE hOpen32;
     126
     127  dprintf(("KERNEL32: HandleManager::Event::CreateEvent(%08xh,%08xh,%08xh,%08xh,%s)\n",
     128           pHMHandleData,
     129           lpsa,
     130           fManualReset,
     131           fInitialState,
     132           lpszEventName));
     133
    76134  hOpen32 = O32_CreateEvent(lpsa,              // call Open32
    77135                            fManualReset,
     
    86144  else
    87145    return (O32_GetLastError());
     146#endif
    88147}
    89148
     
    105164                                    LPCTSTR               lpszEventName)
    106165{
    107   HANDLE hOpen32;
     166#ifdef USE_OS2SEMAPHORES
     167  HEV    hev;
     168  APIRET rc;
     169  char szSemName[CCHMAXPATH];
    108170
    109171  dprintf(("KERNEL32: HandleManager::Event::OpenEvent(%08xh,%08xh,%s)\n",
     
    112174           lpszEventName));
    113175
     176  if(lpszEventName == NULL) {
     177      pHMHandleData->hHMHandle = 0;
     178      return ERROR_INVALID_PARAMETER_W;
     179  }
     180
     181  strcpy(szSemName, "\\SEM32\\");
     182  strcat(szSemName, lpszEventName);
     183  rc = DosOpenEventSem(szSemName, &hev);
     184  if(rc) {
     185      dprintf(("DosOpenEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc));
     186      pHMHandleData->hHMHandle = 0;
     187      return error2WinError(rc);
     188  }
     189  pHMHandleData->hHMHandle = hev;
     190  return ERROR_SUCCESS_W;
     191#else
     192  HANDLE hOpen32;
     193
     194  dprintf(("KERNEL32: HandleManager::Event::OpenEvent(%08xh,%08xh,%s)\n",
     195           pHMHandleData,
     196           fInheritHandle,
     197           lpszEventName));
     198
    114199  hOpen32 = O32_OpenEvent(pHMHandleData->dwAccess,              // call Open32
    115200                          fInheritHandle,
     
    123208  else
    124209    return (O32_GetLastError());
    125 }
    126 
     210#endif
     211}
     212
     213/*****************************************************************************
     214 * Name      : HMDeviceEventClass::CloseHandle
     215 * Purpose   : close the handle
     216 * Parameters: PHMHANDLEDATA pHMHandleData
     217 * Variables :
     218 * Result    : API returncode
     219 * Remark    :
     220 * Status    :
     221 *
     222 * Author    :
     223 *****************************************************************************/
     224
     225#ifdef USE_OS2SEMAPHORES
     226BOOL HMDeviceEventClass::CloseHandle(PHMHANDLEDATA pHMHandleData)
     227{
     228  APIRET rc;
     229
     230  if(pHMHandleData->hHMHandle) {
     231      rc = DosCloseEventSem((HEV)pHMHandleData->hHMHandle);
     232      if(rc) {
     233          dprintf(("DosCloseEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc));
     234          SetLastError(error2WinError(rc));
     235          return FALSE;
     236      }
     237  }
     238  return TRUE;
     239}
     240#endif
     241
     242/*****************************************************************************
     243 * Name      : HMDeviceEventClass::DuplicateHandle
     244 * Purpose   :
     245 * Parameters:
     246 *             various parameters as required
     247 * Variables :
     248 * Result    :
     249 * Remark    : the standard behaviour is to return an error code for non-
     250 *             existant request codes
     251 * Status    :
     252 *
     253 * Author    :
     254 *****************************************************************************/
     255#ifdef USE_OS2SEMAPHORES
     256BOOL HMDeviceEventClass::DuplicateHandle(PHMHANDLEDATA pHMHandleData, HANDLE  srcprocess,
     257                               PHMHANDLEDATA pHMSrcHandle,
     258                               HANDLE  destprocess,
     259                               PHANDLE desthandle,
     260                               DWORD   fdwAccess,
     261                               BOOL    fInherit,
     262                               DWORD   fdwOptions,
     263                               DWORD   fdwOdinOptions)
     264{
     265  APIRET rc;
     266  HEV hev;
     267 
     268  dprintf(("KERNEL32:HandleManager::DuplicateHandle %s(%08x,%08x,%08x,%08x,%08x) - NOT IMPLEMENTED!!!!!!!!\n",
     269           lpHMDeviceName,
     270           pHMHandleData,
     271           srcprocess, pHMSrcHandle, destprocess, desthandle));
     272
     273  if(srcprocess != destprocess) {
     274      DebugInt3();
     275      SetLastError(ERROR_ACCESS_DENIED_W);
     276      return FALSE;
     277  }
     278  hev = (HEV)pHMSrcHandle->hHMHandle;
     279  rc = DosOpenEventSem(NULL, &hev);
     280  if(rc) {
     281      dprintf(("DosOpenEventSem %x failed with rc %d", pHMSrcHandle->hHMHandle, rc));
     282      pHMHandleData->hHMHandle = 0;
     283      SetLastError(error2WinError(rc));
     284      return FALSE;
     285  }
     286  pHMHandleData->dwAccess  = fdwAccess;
     287  pHMHandleData->dwFlags   = pHMSrcHandle->dwFlags; //fManualReset
     288  pHMHandleData->hHMHandle = hev;
     289  SetLastError(ERROR_SUCCESS_W);
     290  return TRUE;
     291}
     292#endif
    127293
    128294/*****************************************************************************
     
    140306BOOL HMDeviceEventClass::SetEvent(PHMHANDLEDATA pHMHandleData)
    141307{
    142 //testestest
     308#ifdef USE_OS2SEMAPHORES
     309  APIRET rc;
     310
    143311  dprintf(("KERNEL32: HandleManager::Event::SetEvent(%08xh)\n",
    144312            pHMHandleData->hHMHandle));
    145313
     314  if(!(pHMHandleData->dwAccess & EVENT_MODIFY_STATE_W) )
     315  {
     316      dprintf(("ERROR: Access denied!!"));
     317      SetLastError(ERROR_ACCESS_DENIED_W);
     318      return FALSE;
     319  }
     320
     321  rc = DosPostEventSem(pHMHandleData->hHMHandle);
     322  if(rc) {
     323      dprintf(("DosPostEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc));
     324      SetLastError(error2WinError(rc));
     325      return FALSE;
     326  }
     327  SetLastError(ERROR_SUCCESS_W);
     328  return TRUE;
     329#else
     330  dprintf(("KERNEL32: HandleManager::Event::SetEvent(%08xh)\n",
     331            pHMHandleData->hHMHandle));
     332
    146333  return (O32_SetEvent(pHMHandleData->hHMHandle));
     334#endif
    147335}
    148336
     
    162350BOOL HMDeviceEventClass::PulseEvent(PHMHANDLEDATA pHMHandleData)
    163351{
     352#ifdef USE_OS2SEMAPHORES
     353  APIRET rc;
     354  ULONG count; 
     355
    164356  dprintf2(("KERNEL32: HandleManager::Event::PulseEvent(%08xh)\n",
    165357            pHMHandleData->hHMHandle));
    166358
     359  if(!(pHMHandleData->dwAccess & EVENT_MODIFY_STATE_W) )
     360  {
     361      dprintf(("ERROR: Access denied!!"));
     362      SetLastError(ERROR_ACCESS_DENIED_W);
     363      return FALSE;
     364  }
     365
     366  rc = DosPostEventSem(pHMHandleData->hHMHandle);
     367  if(rc) {
     368      dprintf(("DosPostEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc));
     369      SetLastError(error2WinError(rc));
     370      return FALSE;
     371  }
     372  if(pHMHandleData->dwFlags == TRUE) {//fManualReset
     373      rc = DosResetEventSem(pHMHandleData->hHMHandle, &count);
     374      if(rc) {
     375          dprintf(("DosResetEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc));
     376          SetLastError(error2WinError(rc));
     377          return FALSE;
     378      }
     379  }
     380  SetLastError(ERROR_SUCCESS_W);
     381  return TRUE;
     382#else
     383  dprintf2(("KERNEL32: HandleManager::Event::PulseEvent(%08xh)\n",
     384            pHMHandleData->hHMHandle));
     385
    167386  return (O32_PulseEvent(pHMHandleData->hHMHandle));
     387#endif
    168388}
    169389
     
    183403BOOL HMDeviceEventClass::ResetEvent(PHMHANDLEDATA pHMHandleData)
    184404{
     405#ifdef USE_OS2SEMAPHORES
     406  APIRET rc;
     407  ULONG count; 
     408 
    185409  dprintf2(("KERNEL32: HandleManager::Event::ResetEvent(%08xh)\n",
    186410            pHMHandleData->hHMHandle));
    187411
     412  if(!(pHMHandleData->dwAccess & EVENT_MODIFY_STATE_W) )
     413  {
     414      dprintf(("ERROR: Access denied!!"));
     415      SetLastError(ERROR_ACCESS_DENIED_W);
     416      return FALSE;
     417  }
     418
     419  rc = DosResetEventSem(pHMHandleData->hHMHandle, &count);
     420  if(rc) {
     421      dprintf(("DosResetEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc));
     422      SetLastError(error2WinError(rc));
     423      return FALSE;
     424  }
     425  SetLastError(ERROR_SUCCESS_W);
     426  return TRUE;
     427#else
     428  dprintf2(("KERNEL32: HandleManager::Event::ResetEvent(%08xh)\n",
     429            pHMHandleData->hHMHandle));
     430
    188431  return (O32_ResetEvent(pHMHandleData->hHMHandle));
    189 }
    190 
     432#endif
     433}
     434
Note: See TracChangeset for help on using the changeset viewer.