home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / xlib_LockDisplay.c < prev    next >
C/C++ Source or Header  |  2000-06-15  |  3KB  |  82 lines

  1. #include "Xlib.h"
  2. #include "Xlib_private.h" 
  3. #include "locking.h"
  4.  
  5.  
  6. /*
  7.  
  8. Copyright 1986, 1998  The Open Group
  9.  
  10. All Rights Reserved.
  11.  
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14.  
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  18. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  19. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21.  
  22. Except as contained in this notice, the name of The Open Group shall not be
  23. used in advertising or otherwise to promote the sale, use or other dealings
  24. in this Software without prior written authorization from The Open Group.
  25.  
  26. */
  27.  
  28.  
  29. /* 
  30.  * Arguments
  31.  * 
  32.  *  display   Specifies the connection to the X server. 
  33.  * 
  34.  * 
  35.  * Description
  36.  * 
  37.  * The XLockDisplay() function locks out all other threads from using the specified display. Other threads attempting to use the
  38.  * display will block until the display is unlocked by this thread. Nested calls to XLockDisplay() work correctly; the display will not
  39.  * actually be unlocked until XUnlockDisplay() has been called the same number of times as XLockDisplay(). This function has no
  40.  * effect unless Xlib was successfully initialized for threads using XInitThreads(). 
  41.  */
  42.  
  43. void XLockDisplay(register Display* dpy)
  44. {
  45.     DBUG_ENTER("XLockDisplay");
  46.     LockDisplay(dpy);
  47.     if (dpy->lock)
  48.     (*dpy->lock->user_lock_display)(dpy);
  49.     /*
  50.      * We want the threads in the reply queue to all get out before
  51.      * XLockDisplay returns, in case they have any side effects the
  52.      * caller of XLockDisplay was trying to protect against.
  53.      * XLockDisplay puts itself at the head of the event waiters queue
  54.      * to wait for all the replies to come in.
  55.      */
  56.     if (dpy->lock && dpy->lock->reply_awaiters) {
  57.     struct _XCVList *cvl;
  58.  
  59.     cvl = (*dpy->lock->create_cvl)(dpy);
  60.  
  61.     /* stuff ourselves on the head of the queue */
  62.     cvl->next = dpy->lock->event_awaiters;
  63.     dpy->lock->event_awaiters = cvl;
  64.  
  65.     while (dpy->lock->reply_awaiters)
  66.         ConditionWait(dpy, cvl->cv);
  67.     UnlockNextEventReader(dpy); /* pass the signal on */
  68.     }
  69.     UnlockDisplay(dpy);
  70.     DBUG_VOID_RETURN;
  71. }
  72.  
  73. void XUnlockDisplay(register Display* dpy)
  74. {
  75.     DBUG_ENTER("XUnlockDisplay");
  76.     LockDisplay(dpy);
  77.     if (dpy->lock)
  78.     (*dpy->lock->user_unlock_display)(dpy);
  79.     UnlockDisplay(dpy);
  80.     DBUG_VOID_RETURN;
  81. }
  82.