| 1 |
/** BEGIN COPYRIGHT BLOCK |
| 2 |
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission. |
| 3 |
* Copyright (C) 2005 Red Hat, Inc. |
| 4 |
* All rights reserved. |
| 5 |
* |
| 6 |
* License: GPL (version 3 or any later version). |
| 7 |
* See LICENSE for details. |
| 8 |
* END COPYRIGHT BLOCK **/ |
| 9 |
|
| 10 |
#ifdef HAVE_CONFIG_H |
| 11 |
#include <config.h> |
| 12 |
#endif |
| 13 |
|
| 14 |
/* |
| 15 |
* fsmutex: Mutexes that are filesystem-based so they're available from more |
| 16 |
* than one process and address space |
| 17 |
* |
| 18 |
* Rob McCool |
| 19 |
*/ |
| 20 |
|
| 21 |
|
| 22 |
#ifndef FSMUTEX_H |
| 23 |
#define FSMUTEX_H |
| 24 |
|
| 25 |
#include "netsite.h" |
| 26 |
|
| 27 |
typedef void *FSMUTEX; |
| 28 |
|
| 29 |
|
| 30 |
/* ------------------------------ Prototypes ------------------------------ */ |
| 31 |
|
| 32 |
NSPR_BEGIN_EXTERN_C |
| 33 |
|
| 34 |
/* |
| 35 |
Flags to fsmutex_init. |
| 36 |
|
| 37 |
FSMUTEX_VISIBLE makes a filesystem mutex which can be opened by other |
| 38 |
programs or processes. |
| 39 |
|
| 40 |
FSMUTEX_NEEDCRIT specifies that the fsmutex_lock and fsmutex_unlock |
| 41 |
functions should also use a critical section to ensure that more than |
| 42 |
one thread does not acquire the mutex at a time. If this flag is not |
| 43 |
specified, it is up to the caller to ensure that only thread within a |
| 44 |
process tries to acquire the lock at any given time. |
| 45 |
*/ |
| 46 |
#define FSMUTEX_VISIBLE 0x01 |
| 47 |
#define FSMUTEX_NEEDCRIT 0x02 |
| 48 |
|
| 49 |
|
| 50 |
/* |
| 51 |
fsmutex_init creates a new filesystem-based mutex. The resulting mutex |
| 52 |
is part of the filesystem. The name and number parameters are used to |
| 53 |
create a name for the mutex. If the FSMUTEX_VISIBLE flag is specified, |
| 54 |
the mutex will be left in the filesystem for other programs and processes |
| 55 |
to access. If a mutex with the given name/number combination already |
| 56 |
exists, the calling process is allowed access to it. If the mutex does |
| 57 |
not already exist, the mutex is created. |
| 58 |
|
| 59 |
Returns NULL on failure, a void pointer to a fsmutex structure otherwise. |
| 60 |
This fsmutex structure is local to the current process. |
| 61 |
*/ |
| 62 |
NSAPI_PUBLIC FSMUTEX fsmutex_init(char *name, int number, int flags); |
| 63 |
|
| 64 |
/* |
| 65 |
Sets the ownership of the underlying filesystem object to the given |
| 66 |
uid and gid. Only effective if the server is running as root. |
| 67 |
*/ |
| 68 |
#include <unistd.h> |
| 69 |
#ifdef __sony |
| 70 |
#include <sys/types.h> |
| 71 |
#endif |
| 72 |
NSAPI_PUBLIC void fsmutex_setowner(FSMUTEX fsm, uid_t uid, gid_t gid); |
| 73 |
|
| 74 |
/* |
| 75 |
fsmutex_terminate deletes a filesystem-based mutex. A mutex will only |
| 76 |
be deleted when every process which has an open pointer to the mutex |
| 77 |
calls this function. |
| 78 |
*/ |
| 79 |
NSAPI_PUBLIC void fsmutex_terminate(FSMUTEX id); |
| 80 |
|
| 81 |
/* |
| 82 |
fsmutex_lock attempts to acquire the given filesystem-based mutex. If |
| 83 |
another process is holding the mutex, or if the FSMUTEX_NEEDCRIT flag |
| 84 |
was passed to fsmutex_init and another thread in the current process is |
| 85 |
holding the mutex, then the calling thread will block until the mutex |
| 86 |
is available. |
| 87 |
*/ |
| 88 |
NSAPI_PUBLIC void fsmutex_lock(FSMUTEX id); |
| 89 |
|
| 90 |
/* |
| 91 |
fsmutex_unlock releases a filesystem-based mutex previously acquired |
| 92 |
by fsmutex_lock. |
| 93 |
*/ |
| 94 |
NSAPI_PUBLIC void fsmutex_unlock(FSMUTEX id); |
| 95 |
|
| 96 |
NSPR_END_EXTERN_C |
| 97 |
|
| 98 |
#endif |