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

    r1024 r1126  
    689689ProgramNode *Parser::progNode = 0;
    690690int Parser::sid = 0;
     691#ifdef APPLE_CHANGES
     692static pthread_mutex_t parserLock = {_PTHREAD_MUTEX_SIG_init, {}};
     693#endif
    691694
    692695ProgramNode *Parser::parse(const UChar *code, unsigned int length, int *sourceId,
    693696                           int *errLine, UString *errMsg)
    694697{
     698#ifdef APPLE_CHANGES
     699  pthread_mutex_lock(&parserLock);
     700#endif
    695701  if (errLine)
    696702    *errLine = -1;
     
    721727#endif
    722728    delete prog;
     729#ifdef APPLE_CHANGES
     730    pthread_mutex_unlock(&parserLock);
     731#endif
    723732    return 0;
    724733  }
    725734
     735#ifdef APPLE_CHANGES
     736  pthread_mutex_unlock(&parserLock);
     737#endif
    726738  return prog;
    727739}
     
    765777  // add this interpreter to the global chain
    766778  // as a root set for garbage collection
     779#ifdef APPLE_CHANGES
     780  Collector::lock();
     781#endif
    767782  if (s_hook) {
    768783    prev = s_hook;
     
    775790    globalInit();
    776791  }
     792#ifdef APPLE_CHANGES
     793  Collector::unlock();
     794#endif
    777795
    778796  m_interpreter = interp;
     
    927945  //fprintf(stderr,"InterpreterImp::clear\n");
    928946  // remove from global chain (see init())
     947#ifdef APPLE_CHANGES
     948  Collector::lock();
     949#endif
    929950  next->prev = prev;
    930951  prev->next = next;
     
    936957    globalClear();
    937958  }
     959#ifdef APPLE_CHANGES
     960  Collector::unlock();
     961#endif
    938962}
    939963
Note: See TracChangeset for help on using the changeset viewer.