diff options
Diffstat (limited to 'Source/WebKit2/Platform/win')
-rw-r--r-- | Source/WebKit2/Platform/win/RunLoopWin.cpp | 46 | ||||
-rw-r--r-- | Source/WebKit2/Platform/win/SharedMemoryWin.cpp | 26 |
2 files changed, 63 insertions, 9 deletions
diff --git a/Source/WebKit2/Platform/win/RunLoopWin.cpp b/Source/WebKit2/Platform/win/RunLoopWin.cpp index 0ca7d9b..21bc2e0 100644 --- a/Source/WebKit2/Platform/win/RunLoopWin.cpp +++ b/Source/WebKit2/Platform/win/RunLoopWin.cpp @@ -26,7 +26,12 @@ #include "config.h" #include "RunLoop.h" +#include "BinarySemaphore.h" #include "WorkItem.h" +#include <wtf/CurrentTime.h> + +using namespace CoreIPC; +using namespace std; static const UINT PerformWorkMessage = WM_USER + 1; static const LPWSTR kRunLoopMessageWindowClassName = L"RunLoopMessageWindow"; @@ -74,6 +79,47 @@ void RunLoop::run() } } +bool RunLoop::dispatchSentMessagesUntil(const Vector<HWND>& windows, CoreIPC::BinarySemaphore& semaphore, double absoluteTime) +{ + if (windows.isEmpty()) + return semaphore.wait(absoluteTime); + + HANDLE handle = semaphore.event(); + DWORD handleCount = 1; + + while (true) { + DWORD interval = absoluteTimeToWaitTimeoutInterval(absoluteTime); + if (!interval) { + // Consider the wait to have timed out, even if the semaphore is currently signaled. + // This matches the WTF::ThreadCondition implementation of BinarySemaphore::wait. + return false; + } + + DWORD result = ::MsgWaitForMultipleObjectsEx(handleCount, &handle, interval, QS_SENDMESSAGE, 0); + if (result == WAIT_OBJECT_0) { + // The semaphore was signaled. + return true; + } + if (result == WAIT_TIMEOUT) { + // absoluteTime was reached. + return false; + } + if (result == WAIT_OBJECT_0 + handleCount) { + // One or more sent messages are available. Process sent messages for all the windows + // we were given, since we don't have a way of knowing which window has available sent + // messages. + for (size_t i = 0; i < windows.size(); ++i) { + MSG message; + ::PeekMessageW(&message, windows[i], 0, 0, PM_NOREMOVE | PM_QS_SENDMESSAGE); + } + continue; + } + ASSERT_WITH_MESSAGE(result != WAIT_FAILED, "::MsgWaitForMultipleObjectsEx failed with error %lu", ::GetLastError()); + ASSERT_WITH_MESSAGE(false, "::MsgWaitForMultipleObjectsEx returned unexpected result %lu", result); + return false; + } +} + void RunLoop::stop() { ::PostQuitMessage(0); diff --git a/Source/WebKit2/Platform/win/SharedMemoryWin.cpp b/Source/WebKit2/Platform/win/SharedMemoryWin.cpp index ef83de7..50985e7 100644 --- a/Source/WebKit2/Platform/win/SharedMemoryWin.cpp +++ b/Source/WebKit2/Platform/win/SharedMemoryWin.cpp @@ -136,8 +136,7 @@ static DWORD accessRights(SharedMemory::Protection protection) case SharedMemory::ReadOnly: return FILE_MAP_READ; case SharedMemory::ReadWrite: - // FILE_MAP_WRITE implies read access, too. - return FILE_MAP_WRITE; + return FILE_MAP_READ | FILE_MAP_WRITE; } ASSERT_NOT_REACHED(); @@ -146,23 +145,32 @@ static DWORD accessRights(SharedMemory::Protection protection) PassRefPtr<SharedMemory> SharedMemory::create(const Handle& handle, Protection protection) { - if (handle.isNull()) + RefPtr<SharedMemory> memory = adopt(handle.m_handle, handle.m_size, protection); + if (!memory) + return 0; + + // The SharedMemory object now owns the HANDLE. + handle.m_handle = 0; + + return memory.release(); +} + +PassRefPtr<SharedMemory> SharedMemory::adopt(HANDLE handle, size_t size, Protection protection) +{ + if (!handle) return 0; DWORD desiredAccess = accessRights(protection); - void* baseAddress = ::MapViewOfFile(handle.m_handle, desiredAccess, 0, 0, handle.m_size); + void* baseAddress = ::MapViewOfFile(handle, desiredAccess, 0, 0, size); ASSERT_WITH_MESSAGE(baseAddress, "::MapViewOfFile failed with error %lu", ::GetLastError()); if (!baseAddress) return 0; RefPtr<SharedMemory> memory = adoptRef(new SharedMemory); - memory->m_size = handle.m_size; + memory->m_size = size; memory->m_data = baseAddress; - - // Adopt the HANDLE. - memory->m_handle = handle.m_handle; - handle.m_handle = 0; + memory->m_handle = handle; return memory.release(); } |