home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / js / src / jslock.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.0 KB  |  85 lines

  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef jslock_h___
  20. #define jslock_h___
  21. /*
  22.  * JS locking macros, used to protect globals only if JS_THREADSAFE is defined.
  23.  */
  24.  
  25. #ifdef JS_THREADSAFE
  26.  
  27. #include "prlock.h"
  28. #include "jscntxt.h"
  29.  
  30. #define JS_ACQUIRE_LOCK(l)      PR_Lock(l)
  31. #define JS_RELEASE_LOCK(l)      PR_Unlock(l)
  32.  
  33. #define JS_LOCK_RUNTIME(rt)     js_lock_runtime(rt)
  34. #define JS_UNLOCK_RUNTIME(rt)   js_unlock_runtime(rt)
  35.  
  36. extern void js_lock_runtime(JSRuntime *rt);
  37. extern void js_unlock_runtime(JSRuntime *rt);
  38. #ifdef DEBUG
  39. #define JS_IS_RUNTIME_LOCKED(rt) js_is_runtime_locked(rt)
  40.  
  41. extern int js_is_runtime_locked(JSRuntime *rt);
  42. #else
  43. #define JS_IS_RUNTIME_LOCKED(rt) 1
  44. #endif
  45.  
  46. #define JS_LOCK_VOID(cx, e)                                                   \
  47.     PR_BEGIN_MACRO                                                            \
  48.     JSRuntime *_rt = (cx)->runtime;                                       \
  49.     JS_LOCK_RUNTIME_VOID(_rt, e);                                         \
  50.     PR_END_MACRO
  51.  
  52. #else  /* !JS_THREADSAFE */
  53.  
  54. #define JS_ACQUIRE_LOCK(l)      ((void)0)
  55. #define JS_RELEASE_LOCK(l)      ((void)0)
  56.  
  57. #define JS_LOCK_RUNTIME(rt)     ((void)0)
  58. #define JS_UNLOCK_RUNTIME(rt)   ((void)0)
  59. #define JS_IS_RUNTIME_LOCKED(rt) 1
  60. #define JS_LOCK_VOID(cx, e)     JS_LOCK_RUNTIME_VOID((cx)->runtime, e)
  61.  
  62. #endif /* !JS_THREADSAFE */
  63.  
  64. #define JS_LOCK(cx)             JS_LOCK_RUNTIME((cx)->runtime)
  65. #define JS_UNLOCK(cx)           JS_UNLOCK_RUNTIME((cx)->runtime)
  66. #define JS_IS_LOCKED(cx)        JS_IS_RUNTIME_LOCKED((cx)->runtime)
  67.  
  68. #define JS_LOCK_RUNTIME_VOID(t,e) \
  69.     (JS_LOCK_RUNTIME(t), (void)(e), JS_UNLOCK_RUNTIME(t))
  70.  
  71. #define JS_LOCK_AND_RETURN_TYPE(cx, type, call)                               \
  72.     PR_BEGIN_MACRO                                                            \
  73.     type _ret;                                                            \
  74.     JS_LOCK_VOID(cx, _ret = call);                                        \
  75.     return _ret;                                                          \
  76.     PR_END_MACRO
  77.  
  78. #define JS_LOCK_AND_RETURN_BOOL(cx, call)                                     \
  79.     JS_LOCK_AND_RETURN_TYPE(cx, JSBool, call)
  80.  
  81. #define JS_LOCK_AND_RETURN_STRING(cx, call)                                   \
  82.     JS_LOCK_AND_RETURN_TYPE(cx, JSString *, call)
  83.  
  84. #endif /* jslock_h___ */
  85.