tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

pripcsem.c (2395B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 /*
      7 * File: pripcsem.c
      8 *
      9 * Description: implements the named semaphores API in prsemipc.h
     10 * for classic NSPR.  If _PR_HAVE_NAMED_SEMAPHORES is not defined,
     11 * the named semaphore functions all fail with the error code
     12 * PR_NOT_IMPLEMENTED_ERROR.
     13 */
     14 
     15 #include "primpl.h"
     16 
     17 #ifdef _PR_PTHREADS
     18 
     19 #  error "This file should not be compiled for the pthreads version"
     20 
     21 #else
     22 
     23 #  ifndef _PR_HAVE_NAMED_SEMAPHORES
     24 
     25 PRSem* _PR_MD_OPEN_SEMAPHORE(const char* osname, PRIntn flags, PRIntn mode,
     26                             PRUintn value) {
     27  PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
     28  return NULL;
     29 }
     30 
     31 PRStatus _PR_MD_WAIT_SEMAPHORE(PRSem* sem) {
     32  PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
     33  return PR_FAILURE;
     34 }
     35 
     36 PRStatus _PR_MD_POST_SEMAPHORE(PRSem* sem) {
     37  PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
     38  return PR_FAILURE;
     39 }
     40 
     41 PRStatus _PR_MD_CLOSE_SEMAPHORE(PRSem* sem) {
     42  PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
     43  return PR_FAILURE;
     44 }
     45 
     46 PRStatus _PR_MD_DELETE_SEMAPHORE(const char* osname) {
     47  PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
     48  return PR_FAILURE;
     49 }
     50 
     51 #  endif /* !_PR_HAVE_NAMED_SEMAPHORES */
     52 
     53 PR_IMPLEMENT(PRSem*)
     54 PR_OpenSemaphore(const char* name, PRIntn flags, PRIntn mode, PRUintn value) {
     55  char osname[PR_IPC_NAME_SIZE];
     56 
     57  if (!_pr_initialized) {
     58    _PR_ImplicitInitialization();
     59  }
     60  if (_PR_MakeNativeIPCName(name, osname, sizeof(osname), _PRIPCSem) ==
     61      PR_FAILURE) {
     62    return NULL;
     63  }
     64  return _PR_MD_OPEN_SEMAPHORE(osname, flags, mode, value);
     65 }
     66 
     67 PR_IMPLEMENT(PRStatus) PR_WaitSemaphore(PRSem* sem) {
     68  return _PR_MD_WAIT_SEMAPHORE(sem);
     69 }
     70 
     71 PR_IMPLEMENT(PRStatus) PR_PostSemaphore(PRSem* sem) {
     72  return _PR_MD_POST_SEMAPHORE(sem);
     73 }
     74 
     75 PR_IMPLEMENT(PRStatus) PR_CloseSemaphore(PRSem* sem) {
     76  return _PR_MD_CLOSE_SEMAPHORE(sem);
     77 }
     78 
     79 PR_IMPLEMENT(PRStatus) PR_DeleteSemaphore(const char* name) {
     80  char osname[PR_IPC_NAME_SIZE];
     81 
     82  if (!_pr_initialized) {
     83    _PR_ImplicitInitialization();
     84  }
     85  if (_PR_MakeNativeIPCName(name, osname, sizeof(osname), _PRIPCSem) ==
     86      PR_FAILURE) {
     87    return PR_FAILURE;
     88  }
     89  return _PR_MD_DELETE_SEMAPHORE(osname);
     90 }
     91 
     92 #endif /* _PR_PTHREADS */