Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
w32ipcsem.c File Reference
#include "primpl.h"

Go to the source code of this file.

Classes

struct  WaitSingleArg

Functions

static void WaitSingleThread (void *arg)
static DWORD FiberSafeWaitForSingleObject (HANDLE hHandle, DWORD dwMilliseconds)
PRSem_PR_MD_OPEN_SEMAPHORE (const char *osname, PRIntn flags, PRIntn mode, PRUintn value)
PRStatus _PR_MD_WAIT_SEMAPHORE (PRSem *sem)
PRStatus _PR_MD_POST_SEMAPHORE (PRSem *sem)
PRStatus _PR_MD_CLOSE_SEMAPHORE (PRSem *sem)

Variables

static DWORD semAccessTable []

Class Documentation

struct WaitSingleArg

Definition at line 74 of file w32ipcsem.c.

Class Members
DWORD error
HANDLE handle
DWORD rv
DWORD timeout

Function Documentation

Definition at line 219 of file w32ipcsem.c.

{
    if (CloseHandle(sem->sem) == FALSE) {
        _PR_MD_MAP_CLOSE_ERROR(GetLastError());
        return PR_FAILURE;
    }
    PR_DELETE(sem);
    return PR_SUCCESS;
}
PRSem* _PR_MD_OPEN_SEMAPHORE ( const char *  osname,
PRIntn  flags,
PRIntn  mode,
PRUintn  value 
)

Definition at line 128 of file w32ipcsem.c.

{
    PRSem *sem;
    SECURITY_ATTRIBUTES sa;
    LPSECURITY_ATTRIBUTES lpSA = NULL;
    PSECURITY_DESCRIPTOR pSD = NULL;
    PACL pACL = NULL;

    sem = PR_NEW(PRSem);
    if (sem == NULL) {
        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
        return NULL;
    }
    if (flags & PR_SEM_CREATE) {
        if (_PR_NT_MakeSecurityDescriptorACL(mode, semAccessTable,
                &pSD, &pACL) == PR_SUCCESS) {
            sa.nLength = sizeof(sa);
            sa.lpSecurityDescriptor = pSD;
            sa.bInheritHandle = FALSE;
            lpSA = &sa;
        }
        sem->sem = CreateSemaphore(lpSA, value, 0x7fffffff, osname);
        if (lpSA != NULL) {
            _PR_NT_FreeSecurityDescriptorACL(pSD, pACL);
        }
        if (sem->sem == NULL) {
            _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
            PR_DELETE(sem);
            return NULL;
        }
        if ((flags & PR_SEM_EXCL) && (GetLastError() == ERROR_ALREADY_EXISTS)) {
            PR_SetError(PR_FILE_EXISTS_ERROR, ERROR_ALREADY_EXISTS);
            CloseHandle(sem->sem);
            PR_DELETE(sem);
            return NULL;
        }
    } else {
        sem->sem = OpenSemaphore(
                SEMAPHORE_MODIFY_STATE|SYNCHRONIZE, FALSE, osname);
        if (sem->sem == NULL) {
            DWORD err = GetLastError();

            /*
             * If we open a nonexistent named semaphore, NT
             * returns ERROR_FILE_NOT_FOUND, while Win95
             * returns ERROR_INVALID_NAME
             */
            if (err == ERROR_INVALID_NAME) {
                PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
            } else {
                _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
            }
            PR_DELETE(sem);
            return NULL;
        }
    }
    return sem;
}

Here is the call graph for this function:

Definition at line 210 of file w32ipcsem.c.

{
    if (ReleaseSemaphore(sem->sem, 1, NULL) == FALSE) {
        _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
        return PR_FAILURE;
    }
    return PR_SUCCESS;
}

Definition at line 188 of file w32ipcsem.c.

{
    DWORD rv;

#ifdef _PR_GLOBAL_THREADS_ONLY
    rv = WaitForSingleObject(sem->sem, INFINITE);
#else
    rv = FiberSafeWaitForSingleObject(sem->sem, INFINITE);
#endif
    PR_ASSERT(rv == WAIT_FAILED || rv == WAIT_OBJECT_0);
    if (rv == WAIT_FAILED) {
        _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
        return PR_FAILURE;
    }
    if (rv != WAIT_OBJECT_0) {
        /* Should not happen */
        PR_SetError(PR_UNKNOWN_ERROR, 0);
        return PR_FAILURE;
    }
    return PR_SUCCESS;
}

Here is the call graph for this function:

static DWORD FiberSafeWaitForSingleObject ( HANDLE  hHandle,
DWORD  dwMilliseconds 
) [static]

Definition at line 91 of file w32ipcsem.c.

{
    PRThread *me = _PR_MD_CURRENT_THREAD();

    if (_PR_IS_NATIVE_THREAD(me)) {
        return WaitForSingleObject(hHandle, dwMilliseconds);
    } else {
        PRThread *waitThread;
        struct WaitSingleArg warg;
        PRStatus rv;

        warg.handle = hHandle;
        warg.timeout = dwMilliseconds;
        waitThread = PR_CreateThread(
            PR_USER_THREAD, WaitSingleThread, &warg,
            PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
        if (waitThread == NULL) {
            return WAIT_FAILED;
        }

        rv = PR_JoinThread(waitThread);
        PR_ASSERT(rv == PR_SUCCESS);
        if (rv == PR_FAILURE) {
            return WAIT_FAILED;
        }
        if (warg.rv == WAIT_FAILED) {
            SetLastError(warg.error);
        }
        return warg.rv;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void WaitSingleThread ( void arg) [static]

Definition at line 81 of file w32ipcsem.c.

{
    struct WaitSingleArg *warg = (struct WaitSingleArg *) arg;

    warg->rv = WaitForSingleObject(warg->handle, warg->timeout);
    if (warg->rv == WAIT_FAILED) {
        warg->error = GetLastError();
    }
}

Here is the caller graph for this function:


Variable Documentation

DWORD semAccessTable[] [static]
Initial value:
 {
    STANDARD_RIGHTS_REQUIRED|0x1, 
    STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|SEMAPHORE_MODIFY_STATE, 
    0 
}

Definition at line 55 of file w32ipcsem.c.