/[jscoverage]/trunk/js/jslock.h
ViewVC logotype

Diff of /trunk/js/jslock.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 459 by siliconforks, Thu Oct 23 19:03:33 2008 UTC revision 460 by siliconforks, Sat Sep 26 23:15:22 2009 UTC
# Line 103  Line 103 
103  };  };
104    
105  /*  /*
106   * Title structures must be immediately preceded by JSObjectMap structures for   * Title structure is always allocated as a field of JSScope.
  * maps that use titles for threadsafety.  This is enforced by assertion in  
  * jsscope.h; see bug 408416 for future remedies to this somewhat fragile  
  * architecture.  
107   */   */
108    #define TITLE_TO_SCOPE(title)                                                 \
109  #define TITLE_TO_MAP(title)                                                   \      ((JSScope *)((uint8 *) (title) - offsetof(JSScope, title)))
     ((JSObjectMap *)((char *)(title) - sizeof(JSObjectMap)))  
110    
111  /*  /*
112   * Atomic increment and decrement for a reference counter, given jsrefcount *p.   * Atomic increment and decrement for a reference counter, given jsrefcount *p.
# Line 119  Line 115 
115  #define JS_ATOMIC_INCREMENT(p)      PR_AtomicIncrement((PRInt32 *)(p))  #define JS_ATOMIC_INCREMENT(p)      PR_AtomicIncrement((PRInt32 *)(p))
116  #define JS_ATOMIC_DECREMENT(p)      PR_AtomicDecrement((PRInt32 *)(p))  #define JS_ATOMIC_DECREMENT(p)      PR_AtomicDecrement((PRInt32 *)(p))
117  #define JS_ATOMIC_ADD(p,v)          PR_AtomicAdd((PRInt32 *)(p), (PRInt32)(v))  #define JS_ATOMIC_ADD(p,v)          PR_AtomicAdd((PRInt32 *)(p), (PRInt32)(v))
118    #define JS_ATOMIC_SET(p,v)          PR_AtomicSet((PRInt32 *)(p), (PRInt32)(v))
119    
120  #define js_CurrentThreadId()        (jsword)PR_GetCurrentThread()  #define js_CurrentThreadId()        (jsword)PR_GetCurrentThread()
121  #define JS_NEW_LOCK()               PR_NewLock()  #define JS_NEW_LOCK()               PR_NewLock()
# Line 135  Line 132 
132    
133  #ifdef JS_DEBUG_TITLE_LOCKS  #ifdef JS_DEBUG_TITLE_LOCKS
134    
135  #define SET_OBJ_INFO(obj_, file_, line_)                                       \  #define JS_SET_OBJ_INFO(obj_, file_, line_)                                   \
136      SET_SCOPE_INFO(OBJ_SCOPE(obj_), file_, line_)      JS_SET_SCOPE_INFO(OBJ_SCOPE(obj_), file_, line_)
137    
138  #define SET_SCOPE_INFO(scope_, file_, line_)                                   \  #define JS_SET_SCOPE_INFO(scope_, file_, line_)                               \
139      js_SetScopeInfo(scope_, file_, line_)      js_SetScopeInfo(scope_, file_, line_)
140    
141  #endif  #endif
# Line 156  Line 153 
153   * are for optimizations above the JSObjectOps layer, under which object locks   * are for optimizations above the JSObjectOps layer, under which object locks
154   * normally hide.   * normally hide.
155   */   */
156  #define JS_LOCK_OBJ(cx,obj)       ((OBJ_SCOPE(obj)->title.ownercx == (cx))     \  #define JS_LOCK_OBJ(cx,obj)       ((OBJ_SCOPE(obj)->title.ownercx == (cx))    \
157                                     ? (void)0                                   \                                     ? (void)0                                  \
158                                     : (js_LockObj(cx, obj),                     \                                     : (js_LockObj(cx, obj),                    \
159                                        SET_OBJ_INFO(obj,__FILE__,__LINE__)))                                        JS_SET_OBJ_INFO(obj,__FILE__,__LINE__)))
160  #define JS_UNLOCK_OBJ(cx,obj)     ((OBJ_SCOPE(obj)->title.ownercx == (cx))     \  #define JS_UNLOCK_OBJ(cx,obj)     ((OBJ_SCOPE(obj)->title.ownercx == (cx))    \
161                                     ? (void)0 : js_UnlockObj(cx, obj))                                     ? (void)0 : js_UnlockObj(cx, obj))
162    
163  #define JS_LOCK_TITLE(cx,title)                                                \  #define JS_LOCK_TITLE(cx,title)                                               \
164      ((title)->ownercx == (cx) ? (void)0                                        \      ((title)->ownercx == (cx) ? (void)0                                       \
165       : (js_LockTitle(cx, (title)),                                             \       : (js_LockTitle(cx, (title)),                                            \
166          SET_TITLE_INFO(title,__FILE__,__LINE__)))          JS_SET_TITLE_INFO(title,__FILE__,__LINE__)))
167    
168  #define JS_UNLOCK_TITLE(cx,title) ((title)->ownercx == (cx) ? (void)0          \  #define JS_UNLOCK_TITLE(cx,title) ((title)->ownercx == (cx) ? (void)0         \
169                                     : js_UnlockTitle(cx, title))                                     : js_UnlockTitle(cx, title))
170    
171  #define JS_LOCK_SCOPE(cx,scope)   JS_LOCK_TITLE(cx,&(scope)->title)  #define JS_LOCK_SCOPE(cx,scope)   JS_LOCK_TITLE(cx,&(scope)->title)
172  #define JS_UNLOCK_SCOPE(cx,scope) JS_UNLOCK_TITLE(cx,&(scope)->title)  #define JS_UNLOCK_SCOPE(cx,scope) JS_UNLOCK_TITLE(cx,&(scope)->title)
173    
174  #define JS_TRANSFER_SCOPE_LOCK(cx, scope, newscope)                            \  #define JS_TRANSFER_SCOPE_LOCK(cx, scope, newscope)                           \
175      js_TransferTitle(cx, &scope->title, &newscope->title)      js_TransferTitle(cx, &scope->title, &newscope->title)
176    
177    
# Line 196  Line 193 
193  extern void js_SetSlotThreadSafe(JSContext *, JSObject *, uint32, jsval);  extern void js_SetSlotThreadSafe(JSContext *, JSObject *, uint32, jsval);
194  extern void js_InitLock(JSThinLock *);  extern void js_InitLock(JSThinLock *);
195  extern void js_FinishLock(JSThinLock *);  extern void js_FinishLock(JSThinLock *);
196  extern void js_FinishSharingTitle(JSContext *cx, JSTitle *title);  
197    /*
198     * This function must be called with the GC lock held.
199     */
200    extern void
201    js_ShareWaitingTitles(JSContext *cx);
202    
203    extern void
204    js_NudgeOtherContexts(JSContext *cx);
205    
206  #ifdef DEBUG  #ifdef DEBUG
207    
# Line 237  Line 242 
242  #define JS_ATOMIC_INCREMENT(p)      (++*(p))  #define JS_ATOMIC_INCREMENT(p)      (++*(p))
243  #define JS_ATOMIC_DECREMENT(p)      (--*(p))  #define JS_ATOMIC_DECREMENT(p)      (--*(p))
244  #define JS_ATOMIC_ADD(p,v)          (*(p) += (v))  #define JS_ATOMIC_ADD(p,v)          (*(p) += (v))
245    #define JS_ATOMIC_SET(p,v)          (*(p) = (v))
246    
247  #define JS_CurrentThreadId() 0  #define JS_CurrentThreadId() 0
248  #define JS_NEW_LOCK()               NULL  #define JS_NEW_LOCK()               NULL
# Line 284  Line 290 
290                                                      JS_NO_TIMEOUT)                                                      JS_NO_TIMEOUT)
291  #define JS_NOTIFY_REQUEST_DONE(rt)  JS_NOTIFY_CONDVAR((rt)->requestDone)  #define JS_NOTIFY_REQUEST_DONE(rt)  JS_NOTIFY_CONDVAR((rt)->requestDone)
292    
293  #ifndef SET_OBJ_INFO  #ifndef JS_SET_OBJ_INFO
294  #define SET_OBJ_INFO(obj,f,l)       ((void)0)  #define JS_SET_OBJ_INFO(obj,f,l)        ((void)0)
295  #endif  #endif
296  #ifndef SET_TITLE_INFO  #ifndef JS_SET_TITLE_INFO
297  #define SET_TITLE_INFO(title,f,l)   ((void)0)  #define JS_SET_TITLE_INFO(title,f,l)    ((void)0)
298  #endif  #endif
299    
300  #ifdef JS_THREADSAFE  #ifdef JS_THREADSAFE
# Line 296  Line 302 
302  extern JSBool  extern JSBool
303  js_CompareAndSwap(jsword *w, jsword ov, jsword nv);  js_CompareAndSwap(jsword *w, jsword ov, jsword nv);
304    
305    /* Atomically bitwise-or the mask into the word *w using compare and swap. */
306    extern void
307    js_AtomicSetMask(jsword *w, jsword mask);
308    
309    #define JS_ATOMIC_SET_MASK(w, mask) js_AtomicSetMask(w, mask)
310    
311  #else  #else
312    
313  static inline JSBool  static inline JSBool
# Line 304  Line 316 
316      return (*w == ov) ? *w = nv, JS_TRUE : JS_FALSE;      return (*w == ov) ? *w = nv, JS_TRUE : JS_FALSE;
317  }  }
318    
319  #endif  #define JS_ATOMIC_SET_MASK(w, mask) (*(w) |= (mask))
320    
321    #endif /* JS_THREADSAFE */
322    
323  JS_END_EXTERN_C  JS_END_EXTERN_C
324    

Legend:
Removed from v.459  
changed lines
  Added in v.460

  ViewVC Help
Powered by ViewVC 1.1.24