Changeset 1126 in webkit for trunk/JavaScriptCore/kjs/value.h


Ignore:
Timestamp:
May 10, 2002, 9:41:01 AM (23 years ago)
Author:
mjs
Message:

Reviewed by: Ken Kocienda and Darin Adler

Fixed the following bug:

Radar 2890573 - JavaScriptCore needs to be thread-safe

Actually this is only a weak form of thread-safety - you can safely
use different interpreters from different threads at the same
time. If you try to use a single interpreter object from multiple
threads, you need to provide your own locking.

  • kjs/collector.h, kjs/collector.cpp: (Collector::lock, Collector::unlock): Trivial implementation of a recursive mutex. (Collector::allocate): Lock around the body of this function. (Collector::collect): Likewise. (Collector::finalCheck): Likewise. (Collector::numInterpreters): Likewise. (Collector::numGCNotAllowedObjects): Likewise. (Collector::numReferencedObjects): Likewise.
  • kjs/internal.cpp: (Parser::parse): use a mutex to lock around the whole parse, since it uses a bunch of global state. (InterpreterImp::InterpreterImp): Grab the Collector lock here, both the mutually exclude calls to the body of this function, and to protect the s_hook static member which the collector pokes at. (InterpreterImp::clear): Likewise.
  • kjs/ustring.cpp: (statBufferKeyCleanup, statBufferKeyInit, UString::ascii): Convert use of static variable
  • kjs/value.cpp: (ValueImp::ValueImp, ValueImp::mark, ValueImp::marked, ValueImp::setGcAllowed): Grab the GC lock around any flag changes.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/value.h

    r1024 r1126  
    9595    virtual ~ValueImp();
    9696
     97#ifdef APPLE_CHANGES
     98    // The collecter lock is not locked around the ref() and unref()
     99    // methods for the following reasons:
     100    //
     101    // - The only cases where chaging the refcount could possibly
     102    // affect the collector's behavior is incrementing from 0 to 1,
     103    // and decrementing from 1 to 0.
     104    //
     105    // - In the 0 to 1 case, the GC allowed flag will always be off
     106    // beforehand, and set right afterwards. And setting it grabs the
     107    // collector lock. So if this happens in the middle of GC, the
     108    // collector will see either a refcount 0 GC not allowed object,
     109    // or a refcount 1 GC not allowed object, and these cases are
     110    // treated exactly the same.
     111    //
     112    // - In the 1 to 0 case, the only possible bad effect is that the
     113    // object will live for one GC cycle longer than it should have
     114    // to, which is really not so bad.
     115    //
     116    // - In theory on some platforms increment or decrement could make
     117    // other threads see intermediate values that are different from
     118    // both the start and end value. If that turns out to really be
     119    // the case we will have to reconsider this scheme.
     120#endif
    97121    inline ValueImp* ref() { refcount++; return this; }
    98122    inline bool deref() { return (!--refcount); }
Note: See TracChangeset for help on using the changeset viewer.