Back to index

lightning-sunbird  0.9+nobinonly
pripcsem.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039  * File: pripcsem.c
00040  *
00041  * Description: implements the named semaphores API in prsemipc.h
00042  * for classic NSPR.  If _PR_HAVE_NAMED_SEMAPHORES is not defined,
00043  * the named semaphore functions all fail with the error code
00044  * PR_NOT_IMPLEMENTED_ERROR.
00045  */
00046 
00047 #include "primpl.h"
00048 
00049 #ifdef _PR_PTHREADS
00050 
00051 #error "This file should not be compiled for the pthreads version"
00052 
00053 #else
00054 
00055 #ifndef _PR_HAVE_NAMED_SEMAPHORES
00056 
00057 PRSem * _PR_MD_OPEN_SEMAPHORE(
00058     const char *osname, PRIntn flags, PRIntn mode, PRUintn value)
00059 {
00060     PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
00061     return NULL;
00062 }
00063 
00064 PRStatus _PR_MD_WAIT_SEMAPHORE(PRSem *sem)
00065 {
00066     PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
00067     return PR_FAILURE;
00068 }
00069 
00070 PRStatus _PR_MD_POST_SEMAPHORE(PRSem *sem)
00071 {
00072     PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
00073     return PR_FAILURE;
00074 }
00075 
00076 PRStatus _PR_MD_CLOSE_SEMAPHORE(PRSem *sem)
00077 {
00078     PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
00079     return PR_FAILURE;
00080 }
00081 
00082 PRStatus _PR_MD_DELETE_SEMAPHORE(const char *osname)
00083 {
00084     PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
00085     return PR_FAILURE;
00086 }
00087 
00088 #endif /* !_PR_HAVE_NAMED_SEMAPHORES */
00089 
00090 PR_IMPLEMENT(PRSem *) PR_OpenSemaphore(
00091     const char *name, PRIntn flags, PRIntn mode, PRUintn value)
00092 {
00093     char osname[PR_IPC_NAME_SIZE];
00094 
00095     if (!_pr_initialized) _PR_ImplicitInitialization();
00096     if (_PR_MakeNativeIPCName(name, osname, sizeof(osname), _PRIPCSem)
00097             == PR_FAILURE) {
00098         return NULL;
00099     }
00100     return _PR_MD_OPEN_SEMAPHORE(osname, flags, mode, value);
00101 }
00102 
00103 PR_IMPLEMENT(PRStatus) PR_WaitSemaphore(PRSem *sem)
00104 {
00105     return _PR_MD_WAIT_SEMAPHORE(sem);
00106 }
00107 
00108 PR_IMPLEMENT(PRStatus) PR_PostSemaphore(PRSem *sem)
00109 {
00110     return _PR_MD_POST_SEMAPHORE(sem);
00111 }
00112 
00113 PR_IMPLEMENT(PRStatus) PR_CloseSemaphore(PRSem *sem)
00114 {
00115     return _PR_MD_CLOSE_SEMAPHORE(sem);
00116 }
00117 
00118 PR_IMPLEMENT(PRStatus) PR_DeleteSemaphore(const char *name)
00119 {
00120     char osname[PR_IPC_NAME_SIZE];
00121 
00122     if (!_pr_initialized) _PR_ImplicitInitialization();
00123     if (_PR_MakeNativeIPCName(name, osname, sizeof(osname), _PRIPCSem)
00124             == PR_FAILURE) {
00125         return PR_FAILURE;
00126     }
00127     return _PR_MD_DELETE_SEMAPHORE(osname);
00128 }
00129 
00130 #endif /* _PR_PTHREADS */