2015-03-17 Zan Dobersek <zdobersek@igalia.com>
+ [WK2] Use C++ lambdas in IPC::Connection
+ https://bugs.webkit.org/show_bug.cgi?id=138018
+
+ Reviewed by Anders Carlsson.
+
+ Replace uses of WTF::bind() in the IPC::Connection class with C++ lambdas.
+
+ * Platform/IPC/Connection.cpp:
+ (IPC::Connection::dispatchWorkQueueMessageReceiverMessage):
+ (IPC::Connection::invalidate):
+ (IPC::Connection::sendMessage):
+ (IPC::Connection::processIncomingMessage): Simplify the error messages so we
+ don't have to format strings on-the-fly, removing the issues of cross-thread
+ string copying altogether.
+ (IPC::Connection::dispatchDidReceiveInvalidMessage): The parameters are now
+ of the StringReference type.
+ (IPC::Connection::enqueueIncomingMessage):
+ * Platform/IPC/Connection.h:
+ * Platform/IPC/mac/ConnectionMac.mm:
+ (IPC::Connection::receiveSourceEventHandler):
+ * Platform/IPC/unix/ConnectionUnix.cpp:
+ (IPC::Connection::open):
+
+2015-03-17 Zan Dobersek <zdobersek@igalia.com>
+
[CMake] Use a forwarding header for ANGLE's ShaderLang.h to avoid picking up ANGLE's EGL headers
https://bugs.webkit.org/show_bug.cgi?id=142530
});
}
-void Connection::dispatchWorkQueueMessageReceiverMessage(WorkQueueMessageReceiver* workQueueMessageReceiver, MessageDecoder* incomingMessageDecoder)
+void Connection::dispatchWorkQueueMessageReceiverMessage(WorkQueueMessageReceiver& workQueueMessageReceiver, MessageDecoder& decoder)
{
- std::unique_ptr<MessageDecoder> decoder(incomingMessageDecoder);
-
- if (!decoder->isSyncMessage()) {
- workQueueMessageReceiver->didReceiveMessage(*this, *decoder);
+ if (!decoder.isSyncMessage()) {
+ workQueueMessageReceiver.didReceiveMessage(*this, decoder);
return;
}
uint64_t syncRequestID = 0;
- if (!decoder->decode(syncRequestID) || !syncRequestID) {
+ if (!decoder.decode(syncRequestID) || !syncRequestID) {
// We received an invalid sync message.
// FIXME: Handle this.
- decoder->markInvalid();
+ decoder.markInvalid();
return;
}
#if HAVE(DTRACE)
- auto replyEncoder = std::make_unique<MessageEncoder>("IPC", "SyncMessageReply", syncRequestID, incomingMessageDecoder->UUID());
+ auto replyEncoder = std::make_unique<MessageEncoder>("IPC", "SyncMessageReply", syncRequestID, decoder.UUID());
#else
auto replyEncoder = std::make_unique<MessageEncoder>("IPC", "SyncMessageReply", syncRequestID);
#endif
// Hand off both the decoder and encoder to the work queue message receiver.
- workQueueMessageReceiver->didReceiveSyncMessage(*this, *decoder, replyEncoder);
+ workQueueMessageReceiver.didReceiveSyncMessage(*this, decoder, replyEncoder);
// FIXME: If the message was invalid, we should send back a SyncMessageError.
- ASSERT(!decoder->isInvalid());
+ ASSERT(!decoder.isInvalid());
if (replyEncoder)
sendSyncReply(WTF::move(replyEncoder));
return;
}
- // Reset the client.
- m_client = 0;
+ m_client = nullptr;
- m_connectionQueue->dispatch(WTF::bind(&Connection::platformInvalidate, this));
+ RefPtr<Connection> protectedThis(this);
+ m_connectionQueue->dispatch([protectedThis] {
+ protectedThis->platformInvalidate();
+ });
}
void Connection::markCurrentlyDispatchedMessageAsInvalid()
}
// FIXME: We should add a boolean flag so we don't call this when work has already been scheduled.
- m_connectionQueue->dispatch(WTF::bind(&Connection::sendOutgoingMessages, this));
+ RefPtr<Connection> protectedThis(this);
+ m_connectionQueue->dispatch([protectedThis] {
+ protectedThis->sendOutgoingMessages();
+ });
return true;
}
}
if (!m_workQueueMessageReceivers.isValidKey(message->messageReceiverName())) {
- if (message->messageReceiverName().isEmpty() && message->messageName().isEmpty()) {
- // Something went wrong when decoding the message. Encode the message length so we can figure out if this
- // happens for certain message lengths.
- CString messageReceiverName = "<unknown message>";
- CString messageName = String::format("<message length: %zu bytes>", message->length()).utf8();
-
- m_clientRunLoop.dispatch(bind(&Connection::dispatchDidReceiveInvalidMessage, this, messageReceiverName, messageName));
- return;
- }
-
- m_clientRunLoop.dispatch(bind(&Connection::dispatchDidReceiveInvalidMessage, this, message->messageReceiverName().toString(), message->messageName().toString()));
+ RefPtr<Connection> protectedThis(this);
+ StringReference messageReceiverName = message->messageReceiverName();
+ StringCapture capturedMessageReceiverName(messageReceiverName.isEmpty() ? "<unknown message receiver>" : String(messageReceiverName.data(), messageReceiverName.size()));
+ StringReference messageName = message->messageName();
+ StringCapture capturedMessageName(messageName.isEmpty() ? "<unknown message>" : String(messageName.data(), messageName.size()));
+
+ m_clientRunLoop.dispatch([protectedThis, capturedMessageReceiverName, capturedMessageName] {
+ protectedThis->dispatchDidReceiveInvalidMessage(capturedMessageReceiverName.string().utf8(), capturedMessageName.string().utf8());
+ });
return;
}
auto it = m_workQueueMessageReceivers.find(message->messageReceiverName());
if (it != m_workQueueMessageReceivers.end()) {
- it->value.first->dispatch(bind(&Connection::dispatchWorkQueueMessageReceiverMessage, this, it->value.second, message.release()));
+ RefPtr<Connection> protectedThis(this);
+ RefPtr<WorkQueueMessageReceiver>& workQueueMessageReceiver = it->value.second;
+ MessageDecoder* decoderPtr = message.release();
+ it->value.first->dispatch([protectedThis, workQueueMessageReceiver, decoderPtr] {
+ std::unique_ptr<MessageDecoder> decoder(decoderPtr);
+ protectedThis->dispatchWorkQueueMessageReceiverMessage(*workQueueMessageReceiver, *decoder);
+ });
return;
}
m_incomingMessages.append(WTF::move(incomingMessage));
}
- m_clientRunLoop.dispatch(WTF::bind(&Connection::dispatchOneMessage, this));
+ RefPtr<Connection> protectedThis(this);
+ m_clientRunLoop.dispatch([protectedThis] {
+ protectedThis->dispatchOneMessage();
+ });
}
void Connection::dispatchMessage(MessageDecoder& decoder)
}
}
+ RefPtr<Connection> protectedThis(this);
m_isConnected = true;
#if PLATFORM(GTK)
- RefPtr<Connection> protector(this);
m_connectionQueue->registerSocketEventHandler(m_socketDescriptor,
- [=] {
- protector->readyReadHandler();
+ [protectedThis] {
+ protectedThis->readyReadHandler();
},
- [=] {
- protector->connectionDidClose();
+ [protectedThis] {
+ protectedThis->connectionDidClose();
});
#elif PLATFORM(EFL)
- RefPtr<Connection> protector(this);
m_connectionQueue->registerSocketEventHandler(m_socketDescriptor,
- [protector] {
- protector->readyReadHandler();
+ [protectedThis] {
+ protectedThis->readyReadHandler();
});
#endif
- // Schedule a call to readyReadHandler. Data may have arrived before installation of the signal
- // handler.
- m_connectionQueue->dispatch(WTF::bind(&Connection::readyReadHandler, this));
+ // Schedule a call to readyReadHandler. Data may have arrived before installation of the signal handler.
+ m_connectionQueue->dispatch([protectedThis] {
+ protectedThis->readyReadHandler();
+ });
return true;
}