fsmutex.h 2.9 KB

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