Ignore:
Timestamp:
Sep 3, 2008, 9:37:00 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Darin Adler.

Implement callOnMainThreadAndWait().

This will be useful when a background thread needs to perform UI calls synchronously
(e.g. an openDatabase() call cannot return until the user answers to a confirmation dialog).

  • wtf/MainThread.cpp: (WTF::FunctionWithContext::FunctionWithContext): Added a ThreadCondition member. When non-zero, the condition is signalled after the function is called. (WTF::mainThreadFunctionQueueMutex): Renamed from functionQueueMutex, sinc this is no longer static. Changed to be initialized from initializeThreading() to avoid lock contention. (WTF::initializeMainThread): On non-Windows platforms, just call mainThreadFunctionQueueMutex. (WTF::dispatchFunctionsFromMainThread): Signal synchronous calls when done. (WTF::callOnMainThread): Updated for functionQueueMutex rename. (WTF::callOnMainThreadAndWait): Added.
  • wtf/MainThread.h: Added callOnMainThreadAndWait(); initializeMainThread() now exists on all platforms.
  • wtf/win/MainThreadWin.cpp: (WTF::initializeMainThread): Added a callOnMainThreadAndWait() call to initialize function queue mutex.
  • wtf/ThreadingGtk.cpp: (WTF::initializeThreading):
  • wtf/ThreadingPthreads.cpp: (WTF::initializeThreading):
  • wtf/ThreadingQt.cpp: (WTF::initializeThreading): Only initialize mainThreadIdentifier on non-Darwin platforms. It was not guaranteed to be accurate on Darwin.
File:
1 edited

Legend:

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

    r35598 r36056  
    3030#include "Threading.h"
    3131
    32 #include <wtf/HashMap.h>
    33 #include <wtf/MathExtras.h>
     32#include "HashMap.h"
     33#include "MainThread.h"
     34#include "MathExtras.h"
    3435
    3536#include <errno.h>
     
    4041Mutex* atomicallyInitializedStaticMutex;
    4142
    42 static ThreadIdentifier mainThreadIdentifier; // More precisely, the thread that was the first to call initializeThreading().
     43#if !PLATFORM(DARWIN)
     44static ThreadIdentifier mainThreadIdentifier; // The thread that was the first to call initializeThreading(), which must be the main thread.
     45#endif
    4346
    4447static Mutex& threadMapMutex()
     
    5457        threadMapMutex();
    5558        wtf_random_init();
     59#if !PLATFORM(DARWIN)
    5660        mainThreadIdentifier = currentThread();
     61#endif
     62        initializeMainThread();
    5763    }
    5864}
Note: See TracChangeset for help on using the changeset viewer.