Changeset 1131


Ignore:
Timestamp:
Feb 1, 2004, 12:53:27 AM (22 years ago)
Author:
bird
Message:

Fixed deadlock problem, when libc_FH() imports a handle.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/lib/sys/filehandles.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1130 r1131  
    6363*******************************************************************************/
    6464static int __libc_fhMoreHandles(unsigned cMin);
     65static int __libc_fhAllocate(int fh, unsigned fFlags, int cb, PLIBCFHOPS pOps, PLIBCFH *ppFH, int *pfh, int fOwnSem);
    6566
    6667
     
    197198         * Allocate handle and initialize handle.
    198199         */
    199         rc = __libc_FHAllocate(i, fLibc, sizeof(LIBCFH), NULL, NULL, NULL);
     200        rc = __libc_fhAllocate(i, fLibc, sizeof(LIBCFH), NULL, NULL, NULL, 1);
    200201        if (rc)
    201202        {
     
    422423 * @param   ppFH    Where to store the allocated file handle struct pointer. (NULL allowed)
    423424 * @param   pfh     Where to store the number of the filehandle allocated.
     425 * @param   fOwnSem Set if we should not take or release the semaphore.
    424426 * @remark  The preallocated handles make this function somewhat big and messy.
    425427 */
    426 int __libc_FHAllocate(int fh, unsigned fFlags, int cb, PLIBCFHOPS pOps, PLIBCFH *ppFH, int *pfh)
     428static int __libc_fhAllocate(int fh, unsigned fFlags, int cb, PLIBCFHOPS pOps, PLIBCFH *ppFH, int *pfh, int fOwnSem)
    427429{
    428430    PLIBCFH     pFH;
     
    445447     * Now take the lock.
    446448     */
    447     if (_fmutex_request(&gmtx, 0))
     449    if (!fOwnSem && _fmutex_request(&gmtx, 0))
    448450        return -1;
    449451
     
    582584        *pfh = fh;
    583585
    584     _fmutex_release(&gmtx);
     586    if (!fOwnSem)
     587        _fmutex_release(&gmtx);
    585588    return rc;
    586589}
     590
     591/**
     592 * Allocates a file handle.
     593 *
     594 * @returns 0 on success.
     595 * @returns OS/2 error code and errno set to the corresponding error number.
     596 * @param   fh      Number of the filehandle to allocate.
     597 *                  Will fail if the handle is in use.
     598 *                  Use -1 for any handle.
     599 * @param   fFlags  Initial flags.
     600 * @param   cb      Size of the file handle.
     601 *                  Must not be less than the mandatory size (sizeof(LIBCFH)).
     602 * @param   pOps    Value of the pOps field, NULL not allowed.
     603 * @param   ppFH    Where to store the allocated file handle struct pointer. (NULL allowed)
     604 * @param   pfh     Where to store the number of the filehandle allocated.
     605 * @remark  The preallocated handles make this function somewhat big and messy.
     606 */
     607int __libc_FHAllocate(int fh, unsigned fFlags, int cb, PLIBCFHOPS pOps, PLIBCFH *ppFH, int *pfh)
     608{
     609    return __libc_fhAllocate(fh, fFlags, cb, pOps, ppFH, pfh, 0);
     610}
     611
    587612
    588613/**
     
    749774                 * Allocate a new handle for this filehandle.
    750775                 */
    751                 rc = __libc_FHAllocate(fh, fLibc, sizeof(LIBCFH), NULL, &pFH, NULL);
     776                rc = __libc_fhAllocate(fh, fLibc, sizeof(LIBCFH), NULL, &pFH, NULL, 1);
    752777                if (rc)
    753778                    pFH = NULL;
Note: See TracChangeset for help on using the changeset viewer.