LoaderRunLoopCF.cpp [plain text]
#include "config.h"
#include "LoaderRunLoopCF.h"
#if USE(CFURLCONNECTION)
#include <CoreFoundation/CoreFoundation.h>
#include <limits>
#include <mutex>
#include <wtf/AutodrainedPool.h>
#include <wtf/Condition.h>
#include <wtf/Lock.h>
#include <wtf/MainThread.h>
#include <wtf/Threading.h>
namespace WebCore {
static CFRunLoopRef loaderRunLoopObject = 0;
static Lock loaderRunLoopMutex;
static StaticCondition loaderRunLoopConditionVariable;
static void emptyPerform(void*)
{
}
CFRunLoopRef loaderRunLoop()
{
ASSERT(isMainThread());
std::unique_lock<Lock> lock(loaderRunLoopMutex);
if (!loaderRunLoopObject) {
Thread::create("WebCore: CFNetwork Loader", [] {
{
std::lock_guard<Lock> lock(loaderRunLoopMutex);
loaderRunLoopObject = CFRunLoopGetCurrent();
CFRunLoopSourceContext ctxt = {0, (void*)1 , 0, 0, 0, 0, 0, 0, 0, emptyPerform};
CFRunLoopSourceRef bogusSource = CFRunLoopSourceCreate(0, 0, &ctxt);
CFRunLoopAddSource(loaderRunLoopObject, bogusSource, kCFRunLoopDefaultMode);
loaderRunLoopConditionVariable.notifyOne();
}
SInt32 result;
do {
AutodrainedPool pool;
result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, std::numeric_limits<double>::max(), true);
} while (result != kCFRunLoopRunStopped && result != kCFRunLoopRunFinished);
});
loaderRunLoopConditionVariable.wait(lock, [] { return loaderRunLoopObject; });
}
return loaderRunLoopObject;
}
}
#endif // USE(CFURLCONNECTION)