Ignore:
Timestamp:
Aug 22, 2005, 2:14:50 AM (20 years ago)
Author:
bird
Message:

Tried to workaround the race conditions in libc_Back_safesemEvSleep/Wakeup.
These might affect SysV sems. (2nd try)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/include/InnoTekLIBC/backend.h

    • Property cvs2svn:cvs-rev changed from 1.30 to 1.31
    r2297 r2298  
    967967 * @{ */
    968968
     969/**
     970 * Safe Mutex Semaphore structure.
     971 *
     972 * For shared semaphores this structure must be in shared memory so all users
     973 * actually use the very same structure.
     974 */
     975typedef struct __LIBC_SAFESEMMTX
     976{
     977#ifdef __OS2__
     978    /** Mutex handle. */
     979    unsigned long hmtx;
     980#endif
     981} __LIBC_SAFESEMMTX;
     982/** Pointer to a SAFESEM Mutex structure. */
     983typedef __LIBC_SAFESEMMTX *__LIBC_PSAFESEMMTX;
     984
    969985/**
    970986 * Creates a safe mutex sem.
     
    972988 * @returns 0 on success.
    973989 * @returns Negative error code (errno.h) on failure.
    974  * @param   phmtx       Where to store the semaphore handle.
     990 * @param   pmtx        Pointer to the semaphore structure to initialize.
    975991 * @param   fShared     Set if the semaphore should be sharable between processes.
    976992 */
    977 int __libc_Back_safesemMtxCreate(uintptr_t *phmtx, int fShared);
     993int __libc_Back_safesemMtxCreate(__LIBC_PSAFESEMMTX pmtx, int fShared);
    978994
    979995/**
     
    982998 * @returns 0 on success.
    983999 * @returns Negative error code (errno.h) on failure.
    984  * @param   hmtx        The semaphore handle.
    985  */
    986 int __libc_Back_safesemMtxOpen(uintptr_t hmtx);
     1000 * @param   pmtx        Pointer to the semaphore structure.
     1001 */
     1002int __libc_Back_safesemMtxOpen(__LIBC_PSAFESEMMTX pmtx);
    9871003
    9881004/**
     
    9911007 * @returns 0 on success.
    9921008 * @returns Negative error code (errno.h) on failure.
    993  * @param   hmtx        The semaphore handle.
    994  */
    995 int __libc_Back_safesemMtxClose(uintptr_t hmtx);
     1009 * @param   pmtx        Pointer to the semaphore structure.
     1010 */
     1011int __libc_Back_safesemMtxClose(__LIBC_PSAFESEMMTX pmtx);
    9961012
    9971013/**
     
    10001016 * @returns 0 on success.
    10011017 * @returns Negative errno on failure.
    1002  * @param   hmtx    Handle to the mutex.
    1003  */
    1004 int __libc_Back_safesemMtxLock(uintptr_t hmtx);
     1018 * @param   pmtx        Pointer to the semaphore structure.
     1019 */
     1020int __libc_Back_safesemMtxLock(__LIBC_PSAFESEMMTX pmtx);
    10051021
    10061022/**
     
    10091025 * @returns 0 on success.
    10101026 * @returns Negative errno on failure.
    1011  * @param   hmtx    Handle to the mutex.
    1012  */
    1013 int __libc_Back_safesemMtxUnlock(uintptr_t hmtx);
     1027 * @param   pmtx        Pointer to the semaphore structure.
     1028 */
     1029int __libc_Back_safesemMtxUnlock(__LIBC_PSAFESEMMTX pmtx);
     1030
     1031
     1032/**
     1033 * Safe Event Semaphore structure.
     1034 *
     1035 * For shared semaphores this structure must be in shared memory so all users
     1036 * actually use the very same structure.
     1037 *
     1038 * @remark  The event semaphore business is difficult because the lack of
     1039 *          atomic mutex release + event wait apis in OS/2. We have to
     1040 *          jump around the place to get this working nearly safly...
     1041 */
     1042typedef struct __LIBC_SAFESEMEV
     1043{
     1044#ifdef __OS2__
     1045    /** The event semaphore. */
     1046    unsigned long       hev;
     1047#endif
     1048    /** Number of threads which are supposed to be blocking on the above event semaphore. */
     1049    uint32_t volatile   cWaiters;
     1050    /** The mutex semaphore used to protect the event semaphore. */
     1051    __LIBC_PSAFESEMMTX  pmtx;
     1052    /** Set if the semaphore is shared.
     1053     * If shared this structure is allocated from SPM, else it's from the heap. */
     1054    unsigned            fShared;
     1055} __LIBC_SAFESEMEV;
     1056/** Pointer to a SAFESEM Event structure. */
     1057typedef __LIBC_SAFESEMEV *__LIBC_PSAFESEMEV;
    10141058
    10151059/**
     
    10181062 * @returns 0 on success.
    10191063 * @returns Negative error code (errno.h) on failure.
    1020  * @param   phev        Where to store the semaphore handle.
     1064 * @param   pev         Pointer to the semaphore structure to initialize.
     1065 * @param   pmtx        Pointer to the mutex semaphore which protects the event semaphore.
    10211066 * @param   fShared     Set if the semaphore should be sharable between processes.
    10221067 */
    1023 int __libc_Back_safesemEvCreate(uintptr_t *phev, int fShared);
     1068int __libc_Back_safesemEvCreate(__LIBC_PSAFESEMEV pev, __LIBC_PSAFESEMMTX pmtx, int fShared);
    10241069
    10251070/**
    10261071 * Opens a shared safe event sem.
    10271072 *
    1028  * @returns 0 on success.
    1029  * @returns Negative error code (errno.h) on failure.
    1030  * @param   hev         The semaphore handle.
    1031  */
    1032 int __libc_Back_safesemEvOpen(uintptr_t hev);
     1073 * The caller is responsible for opening the associated mutex
     1074 * semaphore before calling this function.
     1075 *
     1076 * @returns 0 on success.
     1077 * @returns Negative error code (errno.h) on failure.
     1078 * @param   pev         Pointer to the semaphore structure to open.
     1079 */
     1080int __libc_Back_safesemEvOpen(__LIBC_PSAFESEMEV pev);
    10331081
    10341082/**
     
    10371085 * @returns 0 on success.
    10381086 * @returns Negative error code (errno.h) on failure.
    1039  * @param   hev         The semaphore handle.
    1040  */
    1041 int __libc_Back_safesemEvClose(uintptr_t hev);
     1087 * @param   pev         Pointer to the semaphore structure to close.
     1088 */
     1089int __libc_Back_safesemEvClose(__LIBC_PSAFESEMEV pev);
    10421090
    10431091/**
    10441092 * Sleep on a semaphore.
    10451093 *
    1046  * This is the most difficult thing we're doing in this file.
    1047  *
    1048  * @returns 0 on success.
    1049  * @returns Negative error code (errno.h) on failure.
    1050  *
    1051  * @param   hev         The semaphore to sleep on.
    1052  * @param   hmtx        The semaphore protecting hev and which is to be unlocked while
    1053  *                      sleeping and reaquired upon waking up.
    1054  * @param   pfnComplete Function to execute on signal and on wait completion.
     1094 * The caller must own the associated mutex semaphore. The mutex semaphore will
     1095 * be released as we go to sleep and reclaimed when we wake up.
     1096 *
     1097 * The pfnComplete callback is used to correct state before signals are handled.
     1098 * It will always be called be for this function returns, and it'll either be under
     1099 * the protection of the signal mutex or the associated mutex (both safe sems).
     1100 *
     1101 * This is the most difficult thing we're doing in this API. On OS/2 we have
     1102 * potential (at least theoretically) race conditions...
     1103 *
     1104 * @returns 0 on success.
     1105 * @returns Negative error code (errno.h) on failure.
     1106 *
     1107 * @param   pev         Pointer to the semaphore structure to sleep on.
     1108 * @param   pfnComplete Function to execute on signal or on wait completion.
    10551109 * @param   pvUser      User argument to pfnComplete.
    10561110 */
    1057 int __libc_Back_safesemEvSleep(uintptr_t hev, uintptr_t hmtx, void (*pfnComplete)(void *pvUser), void *pvUser);
     1111int __libc_Back_safesemEvSleep(__LIBC_PSAFESEMEV pev, void (*pfnComplete)(void *pvUser), void *pvUser);
    10581112
    10591113/**
     
    10621116 * @returns 0 on success.
    10631117 * @returns Negative error code (errno.h) on failure.
    1064  * @param   hev         Event semaphore to post.
    1065  * @param   hmtx        The semaphore protecting hev (see __libc_Back_safesemEvSleep).
    1066  *                      The caller should own this semaphore, it's purpose is debug strictness only!
    1067  */
    1068 int __libc_Back_safesemEvWakeup(uintptr_t hev, uintptr_t hmtx);
     1118 * @param   pev         Pointer to the semaphore structure to post.
     1119 */
     1120int __libc_Back_safesemEvWakeup(__LIBC_PSAFESEMEV pev);
    10691121
    10701122
Note: See TracChangeset for help on using the changeset viewer.