nsprpub/pr/src/misc/pripcsem.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/src/misc/pripcsem.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,98 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * File: pripcsem.c
    1.11 + *
    1.12 + * Description: implements the named semaphores API in prsemipc.h
    1.13 + * for classic NSPR.  If _PR_HAVE_NAMED_SEMAPHORES is not defined,
    1.14 + * the named semaphore functions all fail with the error code
    1.15 + * PR_NOT_IMPLEMENTED_ERROR.
    1.16 + */
    1.17 +
    1.18 +#include "primpl.h"
    1.19 +
    1.20 +#ifdef _PR_PTHREADS
    1.21 +
    1.22 +#error "This file should not be compiled for the pthreads version"
    1.23 +
    1.24 +#else
    1.25 +
    1.26 +#ifndef _PR_HAVE_NAMED_SEMAPHORES
    1.27 +
    1.28 +PRSem * _PR_MD_OPEN_SEMAPHORE(
    1.29 +    const char *osname, PRIntn flags, PRIntn mode, PRUintn value)
    1.30 +{
    1.31 +    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
    1.32 +    return NULL;
    1.33 +}
    1.34 +
    1.35 +PRStatus _PR_MD_WAIT_SEMAPHORE(PRSem *sem)
    1.36 +{
    1.37 +    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
    1.38 +    return PR_FAILURE;
    1.39 +}
    1.40 +
    1.41 +PRStatus _PR_MD_POST_SEMAPHORE(PRSem *sem)
    1.42 +{
    1.43 +    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
    1.44 +    return PR_FAILURE;
    1.45 +}
    1.46 +
    1.47 +PRStatus _PR_MD_CLOSE_SEMAPHORE(PRSem *sem)
    1.48 +{
    1.49 +    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
    1.50 +    return PR_FAILURE;
    1.51 +}
    1.52 +
    1.53 +PRStatus _PR_MD_DELETE_SEMAPHORE(const char *osname)
    1.54 +{
    1.55 +    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
    1.56 +    return PR_FAILURE;
    1.57 +}
    1.58 +
    1.59 +#endif /* !_PR_HAVE_NAMED_SEMAPHORES */
    1.60 +
    1.61 +PR_IMPLEMENT(PRSem *) PR_OpenSemaphore(
    1.62 +    const char *name, PRIntn flags, PRIntn mode, PRUintn value)
    1.63 +{
    1.64 +    char osname[PR_IPC_NAME_SIZE];
    1.65 +
    1.66 +    if (!_pr_initialized) _PR_ImplicitInitialization();
    1.67 +    if (_PR_MakeNativeIPCName(name, osname, sizeof(osname), _PRIPCSem)
    1.68 +            == PR_FAILURE) {
    1.69 +        return NULL;
    1.70 +    }
    1.71 +    return _PR_MD_OPEN_SEMAPHORE(osname, flags, mode, value);
    1.72 +}
    1.73 +
    1.74 +PR_IMPLEMENT(PRStatus) PR_WaitSemaphore(PRSem *sem)
    1.75 +{
    1.76 +    return _PR_MD_WAIT_SEMAPHORE(sem);
    1.77 +}
    1.78 +
    1.79 +PR_IMPLEMENT(PRStatus) PR_PostSemaphore(PRSem *sem)
    1.80 +{
    1.81 +    return _PR_MD_POST_SEMAPHORE(sem);
    1.82 +}
    1.83 +
    1.84 +PR_IMPLEMENT(PRStatus) PR_CloseSemaphore(PRSem *sem)
    1.85 +{
    1.86 +    return _PR_MD_CLOSE_SEMAPHORE(sem);
    1.87 +}
    1.88 +
    1.89 +PR_IMPLEMENT(PRStatus) PR_DeleteSemaphore(const char *name)
    1.90 +{
    1.91 +    char osname[PR_IPC_NAME_SIZE];
    1.92 +
    1.93 +    if (!_pr_initialized) _PR_ImplicitInitialization();
    1.94 +    if (_PR_MakeNativeIPCName(name, osname, sizeof(osname), _PRIPCSem)
    1.95 +            == PR_FAILURE) {
    1.96 +        return PR_FAILURE;
    1.97 +    }
    1.98 +    return _PR_MD_DELETE_SEMAPHORE(osname);
    1.99 +}
   1.100 +
   1.101 +#endif /* _PR_PTHREADS */

mercurial