Changeset 38411 in webkit for trunk/JavaScriptCore/wtf


Ignore:
Timestamp:
Nov 14, 2008, 5:29:33 PM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Darin Alder.

https://bugs.webkit.org/show_bug.cgi?id=21810
Remove use of static C++ objects that are destroyed at exit time (destructors)

Create DEFINE_STATIC_LOCAL macro. Change static local objects to leak to avoid
exit-time destructor. Update code that was changed to fix this issue that ran
into a gcc bug (<rdar://problem/6354696> Codegen issue with C++ static reference
in gcc build 5465). Also typdefs for template types needed to be added in some
cases so the type could make it through the macro successfully.

Basically code of the form:
static T m;
becomes:
DEFINE_STATIC_LOCAL(T, m, ());

Also any code of the form:
static T& m = *new T;
also becomes:
DEFINE_STATIC_LOCAL(T, m, ());

Location:
trunk/JavaScriptCore/wtf
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/MainThread.cpp

    r38101 r38411  
    3030#include "MainThread.h"
    3131
     32#include "StdLibExtras.h"
    3233#include "Threading.h"
    3334#include "Vector.h"
     
    5455Mutex& mainThreadFunctionQueueMutex()
    5556{
    56     static Mutex& staticMutex = *new Mutex;
     57    DEFINE_STATIC_LOCAL(Mutex, staticMutex, ());
    5758    return staticMutex;
    5859}
     
    6061static FunctionQueue& functionQueue()
    6162{
    62     static FunctionQueue& staticFunctionQueue = *new FunctionQueue;
     63    DEFINE_STATIC_LOCAL(FunctionQueue, staticFunctionQueue, ());
    6364    return staticFunctionQueue;
    6465}
  • trunk/JavaScriptCore/wtf/ThreadingPthreads.cpp

    r38101 r38411  
    3030#include "Threading.h"
    3131
     32#include "StdLibExtras.h"
     33
    3234#if USE(PTHREADS)
    3335
     
    4143namespace WTF {
    4244
     45typedef HashMap<ThreadIdentifier, pthread_t> ThreadMap;
     46
    4347static Mutex* atomicallyInitializedStaticMutex;
    4448
     
    4953static Mutex& threadMapMutex()
    5054{
    51     static Mutex& mutex = *new Mutex;
     55    DEFINE_STATIC_LOCAL(Mutex, mutex, ());
    5256    return mutex;
    5357}
     
    7781}
    7882
    79 static HashMap<ThreadIdentifier, pthread_t>& threadMap()
    80 {
    81     static HashMap<ThreadIdentifier, pthread_t>& map = *new HashMap<ThreadIdentifier, pthread_t>;
     83static ThreadMap& threadMap()
     84{
     85    DEFINE_STATIC_LOCAL(ThreadMap, map, ());
    8286    return map;
    8387}
     
    98102    MutexLocker locker(threadMapMutex());
    99103
    100     HashMap<ThreadIdentifier, pthread_t>::iterator i = threadMap().begin();
     104    ThreadMap::iterator i = threadMap().begin();
    101105    for (; i != threadMap().end(); ++i) {
    102106        if (pthread_equal(i->second, pthreadHandle))
Note: See TracChangeset for help on using the changeset viewer.