INTEGRATION: CWS os2port02 (1.3.4); FILE MERGED
2007/10/08 14:27:05 obr 1.3.4.2: RESYNC: (1.3-1.4); FILE MERGED 2007/09/30 11:54:51 ydario 1.3.4.1: Issue number: i82034 Submitted by: ydario Reviewed by: ydario Commit of changes for OS/2 CWS source code integration.
This commit is contained in:
parent
4ca3e1a358
commit
75ccc4735a
1 changed files with 18 additions and 12 deletions
|
@ -4,9 +4,9 @@
|
|||
*
|
||||
* $RCSfile: semaphor.c,v $
|
||||
*
|
||||
* $Revision: 1.4 $
|
||||
* $Revision: 1.5 $
|
||||
*
|
||||
* last change: $Author: vg $ $Date: 2007-09-25 09:49:11 $
|
||||
* last change: $Author: hr $ $Date: 2007-11-02 12:33:22 $
|
||||
*
|
||||
* The Contents of this file are made available subject to
|
||||
* the terms of GNU Lesser General Public License Version 2.1.
|
||||
|
@ -46,10 +46,13 @@
|
|||
|
||||
typedef struct _oslSemaphoreImpl
|
||||
{
|
||||
int nCount;
|
||||
HEV hevReachedZero;
|
||||
int nCount;
|
||||
} oslSemaphoreImpl;
|
||||
|
||||
// static mutex to control access to private members of oslMutexImpl
|
||||
static HMTX MutexLock = NULL;
|
||||
|
||||
/*****************************************************************************/
|
||||
/* osl_createSemaphore */
|
||||
/*****************************************************************************/
|
||||
|
@ -58,7 +61,6 @@ typedef struct _oslSemaphoreImpl
|
|||
- Erzeugen der Semaphore
|
||||
- Z„hler auf initialCount setzen
|
||||
*/
|
||||
|
||||
oslSemaphore SAL_CALL osl_createSemaphore(sal_uInt32 initialCount)
|
||||
{
|
||||
APIRET rc;
|
||||
|
@ -82,6 +84,10 @@ oslSemaphore SAL_CALL osl_createSemaphore(sal_uInt32 initialCount)
|
|||
|
||||
pSemaphoreImpl->nCount = initialCount;
|
||||
|
||||
// create static mutex for private members
|
||||
if (MutexLock == NULL)
|
||||
DosCreateMutexSem( NULL, &MutexLock, 0, FALSE );
|
||||
|
||||
return (oslSemaphore) pSemaphoreImpl;
|
||||
}
|
||||
|
||||
|
@ -118,22 +124,22 @@ sal_Bool SAL_CALL osl_acquireSemaphore(oslSemaphore Semaphore)
|
|||
int nCount;
|
||||
OSL_ASSERT(Semaphore != 0);
|
||||
|
||||
DosEnterCritSec();
|
||||
DosRequestMutexSem( MutexLock, SEM_INDEFINITE_WAIT );
|
||||
|
||||
while( pSemaphoreImpl->nCount < 1 )
|
||||
{
|
||||
sal_uInt32 nPostCount;
|
||||
|
||||
DosExitCritSec();
|
||||
DosReleaseMutexSem( MutexLock);
|
||||
|
||||
rc = DosWaitEventSem(pSemaphoreImpl->hevReachedZero, SEM_INDEFINITE_WAIT );
|
||||
DosResetEventSem(pSemaphoreImpl->hevReachedZero, &nPostCount);
|
||||
|
||||
DosEnterCritSec();
|
||||
DosRequestMutexSem( MutexLock, SEM_INDEFINITE_WAIT );
|
||||
}
|
||||
|
||||
pSemaphoreImpl->nCount--;
|
||||
DosExitCritSec();
|
||||
DosReleaseMutexSem( MutexLock);
|
||||
|
||||
return( rc == NO_ERROR );
|
||||
}
|
||||
|
@ -152,13 +158,13 @@ sal_Bool SAL_CALL osl_tryToAcquireSemaphore(oslSemaphore Semaphore)
|
|||
int nCount;
|
||||
OSL_ASSERT(Semaphore != 0);
|
||||
|
||||
DosEnterCritSec();
|
||||
DosRequestMutexSem( MutexLock, SEM_INDEFINITE_WAIT );
|
||||
|
||||
nCount = pSemaphoreImpl->nCount;
|
||||
if( pSemaphoreImpl->nCount > 0 )
|
||||
pSemaphoreImpl->nCount--;
|
||||
|
||||
DosExitCritSec();
|
||||
DosReleaseMutexSem( MutexLock);
|
||||
|
||||
return( nCount > 0 );
|
||||
}
|
||||
|
@ -176,12 +182,12 @@ sal_Bool SAL_CALL osl_releaseSemaphore(oslSemaphore Semaphore)
|
|||
int nCount;
|
||||
OSL_ASSERT(Semaphore != 0);
|
||||
|
||||
DosEnterCritSec();
|
||||
DosRequestMutexSem( MutexLock, SEM_INDEFINITE_WAIT );
|
||||
|
||||
nCount = pSemaphoreImpl->nCount;
|
||||
pSemaphoreImpl->nCount++;
|
||||
|
||||
DosExitCritSec();
|
||||
DosReleaseMutexSem( MutexLock);
|
||||
|
||||
if( nCount == 0 )
|
||||
DosPostEventSem(pSemaphoreImpl->hevReachedZero);
|
||||
|
|
Loading…
Reference in a new issue