Changeset 1126 in webkit for trunk/JavaScriptCore/kjs/ustring.cpp


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/ustring.cpp

    r1024 r1126  
    122122UString::Rep UString::Rep::null = { 0, 0, 1 };
    123123UString UString::null;
     124#ifdef APPLE_CHANGES
     125// FIXME: fix this once static initializers for pthread_once_t
     126pthread_once_t statBufferKeyOnce = {_PTHREAD_ONCE_SIG_init, {}};
     127pthread_key_t statBufferKey;
     128#else
    124129static char *statBuffer = 0L;
     130#endif
    125131
    126132UChar::UChar(const UCharReference &c)
     
    278284}
    279285
     286#ifdef APPLE_CHANGES
     287static void statBufferKeyCleanup(void *statBuffer)
     288{
     289  if (statBuffer != NULL)
     290    delete [] (char *)statBuffer;
     291}
     292
     293static void statBufferKeyInit(void)
     294{
     295  pthread_key_create(&statBufferKey, statBufferKeyCleanup);
     296}
     297#endif
     298
    280299char *UString::ascii() const
    281300{
     301#ifdef APPLE_CHANGES
     302  pthread_once(&statBufferKeyOnce, statBufferKeyInit);
     303  char *statBuffer = (char *)pthread_getspecific(statBufferKey);
     304#endif
    282305  if (statBuffer)
    283306    delete [] statBuffer;
     
    288311  statBuffer[size()] = '\0';
    289312
     313#ifdef APPLE_CHANGES
     314  pthread_setspecific(statBufferKey, statBuffer);
     315#endif
    290316  return statBuffer;
    291317}
Note: See TracChangeset for help on using the changeset viewer.