diff options
Diffstat (limited to 'pr/src/md/os2/os2cv.c')
-rw-r--r-- | pr/src/md/os2/os2cv.c | 108 |
1 files changed, 77 insertions, 31 deletions
diff --git a/pr/src/md/os2/os2cv.c b/pr/src/md/os2/os2cv.c index 1a2d9399..76c96330 100644 --- a/pr/src/md/os2/os2cv.c +++ b/pr/src/md/os2/os2cv.c @@ -48,6 +48,38 @@ #include "primpl.h" +#ifdef USE_RAMSEM +ULONG _Far16 _Pascal Dos16GetInfoSeg(PSEL pselGlobal, PSEL pselLocal); + +typedef struct _LINFOSEG +{ + USHORT pidCurrent; + USHORT pidParent; + USHORT prtyCurrent; + USHORT tidCurrent; + USHORT sgCurrent; + UCHAR rfProcStatus; + UCHAR dummy1; + BOOL16 fForeground; + UCHAR typProcess; + UCHAR dummy2; + SEL selEnvironment; + USHORT offCmdLine; + USHORT cbDataSegment; + USHORT cbStack; + USHORT cbHeap; + USHORT hmod; + SEL selDS; + SEL selPack; + SEL selPackShr; + SEL selPackPck; + ULONG ulReserved; +} LINFOSEG; +typedef LINFOSEG FAR *PLINFOSEG; + +PLINFOSEG plisCurrent = NULL; +#endif + /* * AddThreadToCVWaitQueueInternal -- * @@ -82,7 +114,7 @@ AddThreadToCVWaitQueueInternal(PRThread *thred, struct _MDCVar *cv) * This function is called by _PR_MD_WAIT_CV and _PR_MD_UNLOCK, * the two places where a lock is unlocked. */ -static void +void md_UnlockAndPostNotifies( _MDLock *lock, PRThread *waitThred, @@ -163,7 +195,11 @@ md_UnlockAndPostNotifies( } /* Release the lock before notifying */ - DosReleaseMutexSem(lock->mutex); +#ifdef USE_RAMSEM + SemReleasex86(&lock->mutex, 0); +#else + DosReleaseMutexSem(lock->mutex); +#endif notified = &post; /* this is where we start */ do { @@ -270,7 +306,11 @@ _PR_MD_WAIT_CV(_MDCVar *cv, _MDLock *lock, PRIntervalTime timeout ) md_UnlockAndPostNotifies(lock, thred, cv); } else { AddThreadToCVWaitQueueInternal(thred, cv); +#ifdef USE_RAMSEM + SemReleasex86( &lock->mutex, 0 ); +#else DosReleaseMutexSem(lock->mutex); +#endif } /* Wait for notification or timeout; don't really care which */ @@ -279,7 +319,11 @@ _PR_MD_WAIT_CV(_MDCVar *cv, _MDLock *lock, PRIntervalTime timeout ) DosResetEventSem(thred->md.blocked_sema, &count); } +#ifdef USE_RAMSEM + SemRequest486(&(lock->mutex), -1); +#else DosRequestMutexSem((lock->mutex), SEM_INDEFINITE_WAIT); +#endif PR_ASSERT(rv == NO_ERROR || rv == ERROR_TIMEOUT); @@ -336,28 +380,41 @@ _PR_MD_NOTIFY_CV(_MDCVar *cv, _MDLock *lock) PRStatus _PR_MD_NEW_LOCK(_MDLock *lock) { +#ifdef USE_RAMSEM + // It's better if this API traps when pCriticalSect is not a valid + // pointer, because we can't return an error code and if we just return + // the API caller will have nasty bugs that are hard to find. + + PRAMSEM pramsem = (PRAMSEM)(&(lock->mutex)); + /* First time, set up addresses of processor specific functions + */ + if (plisCurrent == NULL) + { + SEL selGlobal = 0, selLocal = 0; + + /* Convert 16 bit global information segment to 32 bit address + * by performing CRMA on the 16 bit address: "shift" operation + * to convert sel to flat, "and" operation to mask the address + * to 32-bit + */ + Dos16GetInfoSeg(&selGlobal, &selLocal); + plisCurrent = (PLINFOSEG)(((ULONG)selLocal << 13) & + (ULONG)0x1fff0000); + + } + + memset(pramsem, 0, sizeof(pramsem)); + DosCreateEventSem(0, &pramsem->hevSem, DC_SEM_SHARED, 0); + + lock->notified.length=0; + lock->notified.link=NULL; + return PR_SUCCESS; +#else DosCreateMutexSem(0, &(lock->mutex), 0, 0); (lock)->notified.length=0; (lock)->notified.link=NULL; return PR_SUCCESS; -} - -void -_PR_MD_FREE_LOCK(_MDLock *lock) -{ - DosCloseMutexSem(lock->mutex); -} - -void _PR_MD_LOCK(_MDLock *lock) -{ - DosRequestMutexSem(lock->mutex, SEM_INDEFINITE_WAIT); -} - -PRIntn -_PR_MD_TEST_AND_LOCK(_MDLock *lock) -{ - DosRequestMutexSem(lock->mutex, SEM_INDEFINITE_WAIT); - return 0; +#endif } void @@ -366,14 +423,3 @@ _PR_MD_NOTIFYALL_CV(_MDCVar *cv, _MDLock *lock) md_PostNotifyToCvar(cv, lock, PR_TRUE); return; } - -void -_PR_MD_UNLOCK(_MDLock *lock) -{ - if (0 != lock->notified.length) { - md_UnlockAndPostNotifies(lock, NULL, NULL); - } else { - DosReleaseMutexSem(lock->mutex); - } - return; -} |