[9748] | 1 | /* $Id: hmsemaphore.cpp,v 1.10 2003-02-04 11:29:00 sandervl Exp $ */
|
---|
[278] | 2 |
|
---|
| 3 | /*
|
---|
[6049] | 4 | * Win32 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 CreateSemaphore is called for existing named event semaphore?
|
---|
| 9 | * (see HMCreateSemaphore in handlemanager.cpp)
|
---|
[6069] | 10 | * TODO: OpenSemaphore does not work. (get SEM_INFO pointer)
|
---|
[6049] | 11 | * TODO: Name collisions with files & mutex not allowed. Check if this can happen in OS/2
|
---|
| 12 | *
|
---|
[9748] | 13 | * TODO: Use DosQueryEventSem to test the posted count against maximum count!!
|
---|
| 14 | *
|
---|
[278] | 15 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
[6049] | 16 | *
|
---|
| 17 | * Copyright 2001 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
[278] | 18 | */
|
---|
| 19 |
|
---|
| 20 | #undef DEBUG_LOCAL
|
---|
| 21 | //#define DEBUG_LOCAL
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 | /*****************************************************************************
|
---|
| 25 | * Remark *
|
---|
| 26 | *****************************************************************************
|
---|
| 27 |
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | /*****************************************************************************
|
---|
| 32 | * Includes *
|
---|
| 33 | *****************************************************************************/
|
---|
| 34 |
|
---|
| 35 | #include <os2win.h>
|
---|
| 36 | #include <stdlib.h>
|
---|
| 37 | #include <string.h>
|
---|
[6069] | 38 | #include <heapshared.h>
|
---|
[278] | 39 | #include "unicode.h"
|
---|
| 40 | #include "misc.h"
|
---|
| 41 |
|
---|
| 42 | #include "HandleManager.H"
|
---|
| 43 | #include "HMSemaphore.h"
|
---|
[6049] | 44 | #include "oslibdos.h"
|
---|
[278] | 45 |
|
---|
[2802] | 46 | #define DBG_LOCALLOG DBG_hmsemaphore
|
---|
| 47 | #include "dbglocal.h"
|
---|
[278] | 48 |
|
---|
| 49 | /*****************************************************************************
|
---|
| 50 | * Defines *
|
---|
| 51 | *****************************************************************************/
|
---|
| 52 |
|
---|
| 53 | /*****************************************************************************
|
---|
| 54 | * Structures *
|
---|
| 55 | *****************************************************************************/
|
---|
| 56 |
|
---|
| 57 | /*****************************************************************************
|
---|
| 58 | * Local Prototypes *
|
---|
| 59 | *****************************************************************************/
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | /*****************************************************************************
|
---|
| 63 | * Name : HMCreateSemaphore
|
---|
| 64 | * Purpose : router function for CreateSemaphore
|
---|
| 65 | * Parameters:
|
---|
| 66 | * Variables :
|
---|
| 67 | * Result :
|
---|
| 68 | * Remark :
|
---|
| 69 | * Status :
|
---|
| 70 | *
|
---|
| 71 | * Author : Patrick Haller [Tue, 1999/07/06 20:44]
|
---|
| 72 | *****************************************************************************/
|
---|
| 73 |
|
---|
| 74 | DWORD HMDeviceSemaphoreClass::CreateSemaphore(PHMHANDLEDATA pHMHandleData,
|
---|
| 75 | LPSECURITY_ATTRIBUTES lpsa,
|
---|
| 76 | LONG lInitialCount,
|
---|
| 77 | LONG lMaximumCount,
|
---|
| 78 | LPCTSTR lpszSemaphoreName)
|
---|
| 79 | {
|
---|
| 80 | HANDLE hOpen32;
|
---|
| 81 |
|
---|
| 82 | dprintf(("KERNEL32: HandleManager::Semaphore::CreateSemaphore(%08xh,%08xh,%08xh,%08xh,%s)\n",
|
---|
| 83 | pHMHandleData,
|
---|
| 84 | lpsa,
|
---|
| 85 | lInitialCount,
|
---|
| 86 | lMaximumCount,
|
---|
| 87 | lpszSemaphoreName));
|
---|
| 88 |
|
---|
| 89 | hOpen32 = O32_CreateSemaphore(lpsa, // call Open32
|
---|
| 90 | lInitialCount,
|
---|
| 91 | lMaximumCount,
|
---|
| 92 | (LPTSTR)lpszSemaphoreName);
|
---|
| 93 |
|
---|
[21302] | 94 | dprintf(("KERNEL32: HandleManager::Semaphore::CreateSemaphore hOpen32 = %p, pHMHandleData->hHMHandle = %p\n", hOpen32, pHMHandleData->hHMHandle));
|
---|
| 95 |
|
---|
[1461] | 96 | if (0 != hOpen32) // check success
|
---|
[278] | 97 | {
|
---|
| 98 | pHMHandleData->hHMHandle = hOpen32; // save handle
|
---|
| 99 | return (NO_ERROR);
|
---|
| 100 | }
|
---|
| 101 | else
|
---|
[9748] | 102 | return (GetLastError());
|
---|
[278] | 103 | }
|
---|
| 104 |
|
---|
| 105 |
|
---|
| 106 | /*****************************************************************************
|
---|
| 107 | * Name : HMOpenSemaphore
|
---|
| 108 | * Purpose : router function for OpenSemaphore
|
---|
| 109 | * Parameters:
|
---|
| 110 | * Variables :
|
---|
| 111 | * Result :
|
---|
| 112 | * Remark :
|
---|
| 113 | * Status :
|
---|
| 114 | *
|
---|
| 115 | * Author : Patrick Haller [Tue, 1999/07/06 20:44]
|
---|
| 116 | *****************************************************************************/
|
---|
| 117 |
|
---|
| 118 | DWORD HMDeviceSemaphoreClass::OpenSemaphore(PHMHANDLEDATA pHMHandleData,
|
---|
| 119 | BOOL fInheritHandle,
|
---|
| 120 | LPCTSTR lpszSemaphoreName)
|
---|
| 121 | {
|
---|
| 122 | HANDLE hOpen32;
|
---|
| 123 |
|
---|
| 124 | dprintf(("KERNEL32: HandleManager::Semaphore::OpenSemaphore(%08xh,%08xh,%s)\n",
|
---|
| 125 | pHMHandleData,
|
---|
| 126 | fInheritHandle,
|
---|
| 127 | lpszSemaphoreName));
|
---|
| 128 |
|
---|
| 129 | hOpen32 = O32_OpenSemaphore(pHMHandleData->dwAccess, // call Open32
|
---|
| 130 | fInheritHandle,
|
---|
| 131 | lpszSemaphoreName);
|
---|
| 132 |
|
---|
[1461] | 133 | if (0 != hOpen32) // check success
|
---|
[278] | 134 | {
|
---|
| 135 | pHMHandleData->hHMHandle = hOpen32; // save handle
|
---|
| 136 | return (NO_ERROR);
|
---|
| 137 | }
|
---|
| 138 | else
|
---|
[9748] | 139 | return (GetLastError());
|
---|
[278] | 140 | }
|
---|
| 141 |
|
---|
| 142 |
|
---|
| 143 | /*****************************************************************************
|
---|
| 144 | * Name : HMReleaseSemaphore
|
---|
| 145 | * Purpose : router function for ReleaseSemaphore
|
---|
| 146 | * Parameters:
|
---|
| 147 | * Variables :
|
---|
| 148 | * Result :
|
---|
| 149 | * Remark :
|
---|
| 150 | * Status :
|
---|
| 151 | *
|
---|
| 152 | * Author : Patrick Haller [Tue, 1999/07/06 20:44]
|
---|
| 153 | *****************************************************************************/
|
---|
| 154 |
|
---|
| 155 | BOOL HMDeviceSemaphoreClass::ReleaseSemaphore(PHMHANDLEDATA pHMHandleData,
|
---|
| 156 | LONG cReleaseCount,
|
---|
| 157 | LPLONG lpPreviousCount)
|
---|
| 158 | {
|
---|
| 159 | dprintf(("KERNEL32: HandleManager::Semaphore::ReleaseSemaphore(%08xh,%08xh,%08xh)\n",
|
---|
| 160 | pHMHandleData->hHMHandle,
|
---|
| 161 | cReleaseCount,
|
---|
| 162 | lpPreviousCount));
|
---|
| 163 |
|
---|
| 164 | return (O32_ReleaseSemaphore(pHMHandleData->hHMHandle,
|
---|
| 165 | cReleaseCount,
|
---|
| 166 | lpPreviousCount));
|
---|
| 167 | }
|
---|
| 168 |
|
---|
[6084] | 169 | //******************************************************************************
|
---|
| 170 | //******************************************************************************
|
---|