Diff
Modified: trunk/Source/WebKit2/ChangeLog (141036 => 141037)
--- trunk/Source/WebKit2/ChangeLog 2013-01-29 03:42:59 UTC (rev 141036)
+++ trunk/Source/WebKit2/ChangeLog 2013-01-29 03:47:01 UTC (rev 141037)
@@ -1,3 +1,28 @@
+2013-01-28 Anders Carlsson <ander...@apple.com>
+
+ Move Mach port handling from WorkQueue to Connection
+ https://bugs.webkit.org/show_bug.cgi?id=108140
+
+ Reviewed by Sam Weinig.
+
+ Instead of having WorkQueue know about Mach port sources, just fold that
+ functionality directly into Connection. This lets us get rid of the generic source
+ handling from WorkQueue.
+
+ * Platform/CoreIPC/Connection.h:
+ (Connection):
+ * Platform/CoreIPC/mac/ConnectionMac.cpp:
+ (CoreIPC::Connection::platformInvalidate):
+ (CoreIPC::createDataAvailableSource):
+ (CoreIPC):
+ (CoreIPC::Connection::open):
+ (CoreIPC::Connection::initializeDeadNameSource):
+ * Platform/WorkQueue.h:
+ (WorkQueue::dispatchQueue):
+ (WorkQueue):
+ * Platform/mac/WorkQueueMac.cpp:
+ (WorkQueue::platformInvalidate):
+
2013-01-28 Gyuyoung Kim <gyuyoung....@samsung.com>
Add StorageManager class to cmake ports
Modified: trunk/Source/WebKit2/Platform/CoreIPC/Connection.h (141036 => 141037)
--- trunk/Source/WebKit2/Platform/CoreIPC/Connection.h 2013-01-29 03:42:59 UTC (rev 141036)
+++ trunk/Source/WebKit2/Platform/CoreIPC/Connection.h 2013-01-29 03:47:01 UTC (rev 141037)
@@ -351,11 +351,15 @@
void exceptionSourceEventHandler();
mach_port_t m_sendPort;
+ dispatch_source_t m_deadNameSource;
+
mach_port_t m_receivePort;
+ dispatch_source_t m_receivePortDataAvailableSource;
// If setShouldCloseConnectionOnMachExceptions has been called, this has
// the exception port that exceptions from the other end will be sent on.
mach_port_t m_exceptionPort;
+ dispatch_source_t m_exceptionPortDataAvailableSource;
#if HAVE(XPC)
xpc_connection_t m_xpcConnection;
Modified: trunk/Source/WebKit2/Platform/CoreIPC/mac/ConnectionMac.cpp (141036 => 141037)
--- trunk/Source/WebKit2/Platform/CoreIPC/mac/ConnectionMac.cpp 2013-01-29 03:42:59 UTC (rev 141036)
+++ trunk/Source/WebKit2/Platform/CoreIPC/mac/ConnectionMac.cpp 2013-01-29 03:47:01 UTC (rev 141037)
@@ -58,21 +58,27 @@
ASSERT(m_receivePort);
// Unregister our ports.
- m_connectionQueue.unregisterMachPortEventHandler(m_sendPort);
+ dispatch_source_cancel(m_deadNameSource);
+ dispatch_release(m_deadNameSource);
+ m_deadNameSource = nullptr;
m_sendPort = MACH_PORT_NULL;
- m_connectionQueue.unregisterMachPortEventHandler(m_receivePort);
+ dispatch_source_cancel(m_receivePortDataAvailableSource);
+ dispatch_release(m_receivePortDataAvailableSource);
+ m_receivePortDataAvailableSource = nullptr;
m_receivePort = MACH_PORT_NULL;
if (m_exceptionPort) {
- m_connectionQueue.unregisterMachPortEventHandler(m_exceptionPort);
+ dispatch_source_cancel(m_exceptionPortDataAvailableSource);
+ dispatch_release(m_exceptionPortDataAvailableSource);
+ m_exceptionPortDataAvailableSource = nullptr;
m_exceptionPort = MACH_PORT_NULL;
}
#if HAVE(XPC)
if (m_xpcConnection) {
xpc_release(m_xpcConnection);
- m_xpcConnection = 0;
+ m_xpcConnection = nullptr;
}
#endif
}
@@ -98,6 +104,17 @@
#endif
}
+static dispatch_source_t createDataAvailableSource(mach_port_t receivePort, const WorkQueue& workQueue, const Function<void()>& function)
+{
+ dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_RECV, receivePort, 0, workQueue.dispatchQueue());
+ dispatch_source_set_event_handler(source, function);
+ dispatch_source_set_cancel_handler(source, ^{
+ mach_port_mod_refs(mach_task_self(), receivePort, MACH_PORT_RIGHT_RECEIVE, -1);
+ });
+
+ return source;
+}
+
bool Connection::open()
{
if (m_isServer) {
@@ -127,11 +144,13 @@
setMachPortQueueLength(m_receivePort, MACH_PORT_QLIMIT_LARGE);
// Register the data available handler.
- m_connectionQueue.registerMachPortEventHandler(m_receivePort, WorkQueue::MachPortDataAvailable, bind(&Connection::receiveSourceEventHandler, this));
+ m_receivePortDataAvailableSource = createDataAvailableSource(m_receivePort, m_connectionQueue, bind(&Connection::receiveSourceEventHandler, this));
+ dispatch_resume(m_receivePortDataAvailableSource);
// If we have an exception port, register the data available handler and send over the port to the other end.
if (m_exceptionPort) {
- m_connectionQueue.registerMachPortEventHandler(m_exceptionPort, WorkQueue::MachPortDataAvailable, bind(&Connection::exceptionSourceEventHandler, this));
+ m_exceptionPortDataAvailableSource = createDataAvailableSource(m_exceptionPort, m_connectionQueue, bind(&Connection::exceptionSourceEventHandler, this));
+ dispatch_resume(m_exceptionPortDataAvailableSource);
OwnPtr<MessageEncoder> encoder = MessageEncoder::create("IPC", "SetExceptionPort", 0);
encoder->encode(MachPort(m_exceptionPort, MACH_MSG_TYPE_MAKE_SEND));
@@ -251,7 +270,16 @@
void Connection::initializeDeadNameSource()
{
- m_connectionQueue.registerMachPortEventHandler(m_sendPort, WorkQueue::MachPortDeadNameNotification, bind(&Connection::connectionDidClose, this));
+ m_deadNameSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_SEND, m_sendPort, 0, m_connectionQueue.dispatchQueue());
+ dispatch_source_set_event_handler(m_deadNameSource, bind(&Connection::connectionDidClose, this));
+
+ mach_port_t sendPort = m_sendPort;
+ dispatch_source_set_cancel_handler(m_deadNameSource, ^{
+ // Release our send right.
+ mach_port_deallocate(mach_task_self(), sendPort);
+ });
+
+ dispatch_resume(m_deadNameSource);
}
static PassOwnPtr<MessageDecoder> createMessageDecoder(mach_msg_header_t* header)
Modified: trunk/Source/WebKit2/Platform/WorkQueue.h (141036 => 141037)
--- trunk/Source/WebKit2/Platform/WorkQueue.h 2013-01-29 03:42:59 UTC (rev 141036)
+++ trunk/Source/WebKit2/Platform/WorkQueue.h 2013-01-29 03:47:01 UTC (rev 141037)
@@ -74,18 +74,8 @@
void invalidate();
#if OS(DARWIN)
- enum MachPortEventType {
- // Fired when there is data on the given receive right.
- MachPortDataAvailable,
-
- // Fired when the receive right for this send right has been destroyed.
- MachPortDeadNameNotification
- };
-
- // Will execute the given function whenever the given mach port event fires.
- // Note that this will adopt the mach port and destroy it when the work queue is invalidated.
- void registerMachPortEventHandler(mach_port_t, MachPortEventType, const Function<void()>&);
- void unregisterMachPortEventHandler(mach_port_t);
+ dispatch_queue_t dispatchQueue() const { return m_dispatchQueue; }
+
#elif OS(WINDOWS)
void registerHandle(HANDLE, const Function<void()>&);
void unregisterAndCloseHandle(HANDLE);
@@ -110,13 +100,8 @@
void platformInvalidate();
#if OS(DARWIN)
-#if HAVE(DISPATCH_H)
static void executeFunction(void*);
- Mutex m_eventSourcesMutex;
- class EventSource;
- HashMap<mach_port_t, EventSource*> m_eventSources;
dispatch_queue_t m_dispatchQueue;
-#endif
#elif OS(WINDOWS)
class WorkItemWin : public ThreadSafeRefCounted<WorkItemWin> {
public:
Modified: trunk/Source/WebKit2/Platform/mac/WorkQueueMac.cpp (141036 => 141037)
--- trunk/Source/WebKit2/Platform/mac/WorkQueueMac.cpp 2013-01-29 03:42:59 UTC (rev 141036)
+++ trunk/Source/WebKit2/Platform/mac/WorkQueueMac.cpp 2013-01-29 03:47:01 UTC (rev 141037)
@@ -65,113 +65,6 @@
dispatch_after_f(delayTime, m_dispatchQueue, new WorkQueueAndFunction(this, function), executeFunction);
}
-class WorkQueue::EventSource {
-public:
- EventSource(MachPortEventType eventType, dispatch_source_t dispatchSource, const Function<void()>& function)
- : m_eventType(eventType)
- , m_dispatchSource(dispatchSource)
- , m_function(function)
- {
- }
-
- dispatch_source_t dispatchSource() const { return m_dispatchSource; }
-
- static void eventHandler(void* source)
- {
- EventSource* eventSource = static_cast<EventSource*>(source);
-
- eventSource->m_function();
- }
-
- static void cancelHandler(void* source)
- {
- EventSource* eventSource = static_cast<EventSource*>(source);
-
- mach_port_t machPort = dispatch_source_get_handle(eventSource->m_dispatchSource);
-
- switch (eventSource->m_eventType) {
- case MachPortDataAvailable:
- // Release our receive right.
- mach_port_mod_refs(mach_task_self(), machPort, MACH_PORT_RIGHT_RECEIVE, -1);
- break;
- case MachPortDeadNameNotification:
- // Release our send right.
- mach_port_deallocate(mach_task_self(), machPort);
- break;
- }
- }
-
- static void finalizeHandler(void* source)
- {
- EventSource* eventSource = static_cast<EventSource*>(source);
-
- delete eventSource;
- }
-
-private:
- MachPortEventType m_eventType;
-
- // This is a weak reference, since m_dispatchSource references the event source.
- dispatch_source_t m_dispatchSource;
-
- Function<void()> m_function;
-};
-
-void WorkQueue::registerMachPortEventHandler(mach_port_t machPort, MachPortEventType eventType, const Function<void()>& function)
-{
- ASSERT(machPort != MACH_PORT_NULL);
-
- dispatch_source_type_t sourceType = 0;
- switch (eventType) {
- case MachPortDataAvailable:
- sourceType = DISPATCH_SOURCE_TYPE_MACH_RECV;
- break;
- case MachPortDeadNameNotification:
- sourceType = DISPATCH_SOURCE_TYPE_MACH_SEND;
- break;
- }
-
- dispatch_source_t dispatchSource = dispatch_source_create(sourceType, machPort, 0, m_dispatchQueue);
-
- EventSource* eventSource = new EventSource(eventType, dispatchSource, function);
- dispatch_set_context(dispatchSource, eventSource);
-
- dispatch_source_set_event_handler_f(dispatchSource, &EventSource::eventHandler);
- dispatch_source_set_cancel_handler_f(dispatchSource, &EventSource::cancelHandler);
- dispatch_set_finalizer_f(dispatchSource, &EventSource::finalizeHandler);
-
- // Add the source to our set of sources.
- {
- MutexLocker locker(m_eventSourcesMutex);
-
- ASSERT(!m_eventSources.contains(machPort));
-
- m_eventSources.set(machPort, eventSource);
-
- // And start it!
- dispatch_resume(dispatchSource);
- }
-}
-
-void WorkQueue::unregisterMachPortEventHandler(mach_port_t machPort)
-{
- ASSERT(machPort != MACH_PORT_NULL);
-
- MutexLocker locker(m_eventSourcesMutex);
-
- HashMap<mach_port_t, EventSource*>::iterator it = m_eventSources.find(machPort);
- ASSERT(it != m_eventSources.end());
-
- ASSERT(m_eventSources.contains(machPort));
-
- EventSource* eventSource = it->value;
- // Cancel and release the source. It will be deleted in its finalize handler.
- dispatch_source_cancel(eventSource->dispatchSource());
- dispatch_release(eventSource->dispatchSource());
-
- m_eventSources.remove(it);
-}
-
void WorkQueue::platformInitialize(const char* name)
{
m_dispatchQueue = dispatch_queue_create(name, 0);
@@ -180,10 +73,5 @@
void WorkQueue::platformInvalidate()
{
-#if !ASSERT_DISABLED
- MutexLocker locker(m_eventSourcesMutex);
- ASSERT(m_eventSources.isEmpty());
-#endif
-
dispatch_release(m_dispatchQueue);
}