Changeset 32808 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
May 2, 2008, 3:29:47 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Darin.

Make JavaScriptGlue and JavaScriptCore API functions implicitly call initializeThreading
for the sake of non-WebKit clients.

JavaScriptCore:

  • API/JSBase.cpp: (JSGarbageCollect):
  • API/JSContextRef.cpp: (JSGlobalContextCreate): These are the JavaScriptCore API bottlenecks. There are a few other JSStringRef and JSClassRef functions that can be called earlier, but they do not do anything that requires initializeThreading.
  • kjs/InitializeThreading.cpp: (KJS::doInitializeThreading): (KJS::initializeThreading): On Darwin, make the initialization happen under pthread_once, since there is no guarantee that non-WebKit clients won't try to call this function re-entrantly.
  • kjs/InitializeThreading.h:
  • wtf/Threading.h: Spell out initializeThreading contract.
  • wtf/ThreadingPthreads.cpp: (WTF::isMainThread): Make sure that results are correct on Darwin, even if threading was initialized from a secondary thread.

JavaScriptGlue:

  • JavaScriptGlue.cpp: (JSRunCreate): (JSCollect): (JSCreateJSArrayFromCFArray): (JSLockInterpreter): These are all possible JavaScriptGlue entry points.
Location:
trunk/JavaScriptCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSBase.cpp

    r32807 r32808  
    3030#include "APICast.h"
    3131#include <kjs/ExecState.h>
     32#include <kjs/InitializeThreading.h>
     33#include <kjs/interpreter.h>
    3234#include <kjs/JSGlobalObject.h>
    3335#include <kjs/JSLock.h>
    34 #include <kjs/interpreter.h>
    3536#include <kjs/object.h>
    3637
     
    7778}
    7879
    79 void JSGarbageCollect(JSContextRef)
     80void JSGarbageCollect(JSContextRef ctx)
    8081{
     82    // Unlikely, but it is legal to call JSGarbageCollect(0) before actually doing anything that would implicitly call initializeThreading().
     83    if (!ctx)
     84        initializeThreading();
     85
    8186    JSLock lock;
    8287
  • trunk/JavaScriptCore/API/JSContextRef.cpp

    r31962 r32808  
    2929
    3030#include "APICast.h"
     31#include "InitializeThreading.h"
    3132#include "JSCallbackObject.h"
    3233#include "JSClassRef.h"
     
    3940JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass)
    4041{
     42    initializeThreading();
     43
    4144    JSLock lock;
    4245
  • trunk/JavaScriptCore/ChangeLog

    r32807 r32808  
     12008-05-02  Alexey Proskuryakov  <[email protected]>
     2
     3        Reviewed by Darin.
     4
     5        Make JavaScriptGlue and JavaScriptCore API functions implicitly call initializeThreading
     6        for the sake of non-WebKit clients.
     7
     8        * API/JSBase.cpp:
     9        (JSGarbageCollect):
     10        * API/JSContextRef.cpp:
     11        (JSGlobalContextCreate):
     12        These are the JavaScriptCore API bottlenecks. There are a few other JSStringRef
     13        and JSClassRef functions that can be called earlier, but they do not do anything that
     14        requires initializeThreading.
     15
     16        * kjs/InitializeThreading.cpp:
     17        (KJS::doInitializeThreading):
     18        (KJS::initializeThreading):
     19        On Darwin, make the initialization happen under pthread_once, since there is no guarantee
     20        that non-WebKit clients won't try to call this function re-entrantly.
     21
     22        * kjs/InitializeThreading.h:
     23        * wtf/Threading.h:
     24        Spell out initializeThreading contract.
     25
     26        * wtf/ThreadingPthreads.cpp: (WTF::isMainThread): Make sure that results are correct on
     27        Darwin, even if threading was initialized from a secondary thread.
     28
    1292008-05-02  Alexey Proskuryakov  <[email protected]>
    230
  • trunk/JavaScriptCore/kjs/InitializeThreading.cpp

    r32807 r32808  
    4242namespace KJS {
    4343
    44 void initializeThreading()
     44#if PLATFORM(DARWIN)
     45static pthread_once_t initializeThreadingKeyOnce = PTHREAD_ONCE_INIT;
     46#endif
     47
     48static void initializeThreadingOnce()
    4549{
    4650    WTF::initializeThreading();
    4751#if USE(MULTIPLE_THREADS)
    48     if (!s_dtoaP5Mutex) {
    49         s_dtoaP5Mutex = new Mutex;
    50         Heap::threadHeap();
    51         UString::null();
    52         Identifier::initializeIdentifierThreading();
    53         CommonIdentifiers::shared();
    54         lexer();
    55         initDateMath();
    56         JSGlobalObject::threadClassInfoHashTables();
    57         JSGlobalObject::head();
     52    s_dtoaP5Mutex = new Mutex;
     53    Heap::threadHeap();
     54    UString::null();
     55    Identifier::initializeIdentifierThreading();
     56    CommonIdentifiers::shared();
     57    lexer();
     58    initDateMath();
     59    JSGlobalObject::threadClassInfoHashTables();
     60    JSGlobalObject::head();
     61#endif
     62}
     63
     64void initializeThreading()
     65{
     66#if PLATFORM(DARWIN)
     67    pthread_once(&initializeThreadingKeyOnce, initializeThreadingOnce);
     68#else
     69    static bool initializedThreading = false;
     70    if (!initializedThreading) {
     71        initializeThreadingOnce();
     72        initializedThreading = true;
    5873    }
    5974#endif
  • trunk/JavaScriptCore/kjs/InitializeThreading.h

    r31404 r32808  
    3232namespace KJS {
    3333
     34    // This function must be called from the main thread. It is safe to call it repeatedly.
     35    // Darwin is an exception to this rule: it is OK to call this function from any thread, even reentrantly.
    3436    void initializeThreading();
    3537
  • trunk/JavaScriptCore/wtf/Threading.h

    r31971 r32808  
    240240};
    241241
     242// This function must be called from the main thread. It is safe to call it repeatedly.
     243// Darwin is an exception to this rule: it is OK to call it from any thread, the only requirement is that the calls are not reentrant.
    242244void initializeThreading();
    243245
  • trunk/JavaScriptCore/wtf/ThreadingPthreads.cpp

    r31939 r32808  
    4040Mutex* atomicallyInitializedStaticMutex;
    4141
    42 static ThreadIdentifier mainThreadIdentifier;
     42static ThreadIdentifier mainThreadIdentifier; // More precisely, the thread that was the first to call initializeThreading().
    4343
    4444static Mutex& threadMapMutex()
     
    151151bool isMainThread()
    152152{
     153#if PLATFORM(DARWIN)
     154    return pthread_main_np();
     155#else
    153156    return currentThread() == mainThreadIdentifier;
     157#endif
    154158}
    155159
Note: See TracChangeset for help on using the changeset viewer.