Lock.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * File: Lock.h $XConsortium: Lock.h /main/4 1995/10/26 15:24:02 rswiston $
  25. * Language: C
  26. *
  27. * (c) Copyright 1990, Hewlett-Packard Company, all rights reserved.
  28. *
  29. * (c) Copyright 1993, 1994 Hewlett-Packard Company *
  30. * (c) Copyright 1993, 1994 International Business Machines Corp. *
  31. * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
  32. * (c) Copyright 1993, 1994 Novell, Inc. *
  33. */
  34. #ifndef _Dt_lock_h
  35. #define _Dt_lock_h
  36. /*
  37. GENERAL DESCRIPTION:
  38. The DT lock facility provides simple exclusive locking. It
  39. (as of 6/19/90) is based on the X11 selection-ownership
  40. mechanism, though users of Dt locking do not need to be aware of
  41. this.
  42. X11 server grabs are judiciously used to guarantee atomicity of
  43. operations. If a process which holds a lock dies (or closes its
  44. X11 server connection for some other reason), the lock will be
  45. automatically released.
  46. Locks are identified by a string. There is no mechanism to
  47. allocate unique lock strings to clients; users must take care to
  48. choose a string that will not be easily duplicated by some other
  49. client.
  50. SAMPLE CODE:
  51. #define MY_LOCK "MYAPP_MY_LOCK"
  52. ...
  53. if (_DtGetLock (display, MY_LOCK)) {
  54. <do whatever it is I want to do>
  55. _DtReleaseLock (display, MY_LOCK);
  56. }
  57. else {
  58. <do the alternative>
  59. }
  60. */
  61. extern int _DtGetLock (
  62. Display *display,
  63. char *lock_name);
  64. /*
  65. DESCRIPTION:
  66. _DtGetLock attempts to get the specified lock. If nobody holds
  67. the lock, _DtGetLock will obtain the lock and return 1. If
  68. somebody else already holds the lock, the lock will not be
  69. disturbed and _DtGetLock will return 0.
  70. If the process which owns a lock dies (or closes its X11 server
  71. connection), the lock will be automatically released. To
  72. explicitly release a lock, use _DtReleaseLock.
  73. SYNOPSIS:
  74. success = _DtGetLock (display, lock);
  75. int success; Returns 1 if the lock is obtained,
  76. 0 if not.
  77. Display *display; The X11 server connection which will
  78. hold the lock.
  79. char *lock; The string which names the lock.
  80. */
  81. extern void _DtReleaseLock (
  82. Display *display,
  83. char *lock_name);
  84. /*
  85. DESCRIPTION:
  86. _DtReleaseLock releases a lock obtained by _DtGetLock.
  87. WARNING!! It is perfectly legal for one process to release
  88. a lock held by another process. By convention you should only
  89. release locks previously obtained by your process from _DtGetLock
  90. unless you are playing God and know what you are doing.
  91. SYNOPSIS:
  92. (void) _DtReleaseLock (display, lock);
  93. Display *display; The X11 server connection which holds
  94. the lock.
  95. char *lock; The string which names the lock.
  96. */
  97. extern int _DtTestLock (
  98. Display *display,
  99. char *lock_name);
  100. /*
  101. DESCRIPTION:
  102. _DtTestLock returns a status indicating whether anybody holds the
  103. specified lock.
  104. SYNOPSIS:
  105. status = _DtTestLock (display, lock);
  106. int success; Returns 1 if anybody holds the lock,
  107. 0 otherwise.
  108. Display *display; The X11 server connection.
  109. char *lock; The string which names the lock.
  110. */
  111. #endif /* _Dt_lock_h */
  112. /* Do not add anything after this endif. */