Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
2011-02-11 Anders Carlsson <andersca@apple.com>
        Reviewed by Adam Roben.

        Add a SyncMessageState class to CoreIPC::Connection
        https://bugs.webkit.org/show_bug.cgi?id=54309

        SyncMessageState objects are shared between all connections scheduled on
        a given run loop. It will be used to keep track of state when waiting
        for replies for a synchronous message.

        * Platform/CoreIPC/Connection.cpp:
        (CoreIPC::Connection::SyncMessageState::syncMessageStateMap):
        (CoreIPC::Connection::SyncMessageState::syncMessageStateMapMutex):
        Add a global RunLoop -> SyncMessageState map and a mutex for locking.

        (CoreIPC::Connection::SyncMessageState::getOrCreate):
        Look in the map for an existing SyncMessageState object and create a new
        one if none is found.

        (CoreIPC::Connection::SyncMessageState::SyncMessageState):
        Initialize m_runLoop.

        (CoreIPC::Connection::SyncMessageState::~SyncMessageState):
        Remove the object from the map.


Canonical link: https://commits.webkit.org/68376@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@78368 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Anders Carlsson committed Feb 11, 2011
1 parent 6438a52 commit a1c6b11
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Source/WebKit2/ChangeLog
@@ -1,3 +1,29 @@
2011-02-11 Anders Carlsson <andersca@apple.com>

Reviewed by Adam Roben.

Add a SyncMessageState class to CoreIPC::Connection
https://bugs.webkit.org/show_bug.cgi?id=54309

SyncMessageState objects are shared between all connections scheduled on
a given run loop. It will be used to keep track of state when waiting
for replies for a synchronous message.

* Platform/CoreIPC/Connection.cpp:
(CoreIPC::Connection::SyncMessageState::syncMessageStateMap):
(CoreIPC::Connection::SyncMessageState::syncMessageStateMapMutex):
Add a global RunLoop -> SyncMessageState map and a mutex for locking.

(CoreIPC::Connection::SyncMessageState::getOrCreate):
Look in the map for an existing SyncMessageState object and create a new
one if none is found.

(CoreIPC::Connection::SyncMessageState::SyncMessageState):
Initialize m_runLoop.

(CoreIPC::Connection::SyncMessageState::~SyncMessageState):
Remove the object from the map.

2011-02-11 Enrica Casucci <enrica@apple.com>

Reviewed by Darin Adler.
Expand Down
51 changes: 51 additions & 0 deletions Source/WebKit2/Platform/CoreIPC/Connection.cpp
Expand Up @@ -35,6 +35,57 @@ using namespace std;

namespace CoreIPC {

class Connection::SyncMessageState : public RefCounted<Connection::SyncMessageState> {
public:
static PassRefPtr<SyncMessageState> getOrCreate(RunLoop*);
~SyncMessageState();

private:
explicit SyncMessageState(RunLoop*);

RunLoop* m_runLoop;

typedef HashMap<RunLoop*, SyncMessageState*> SyncMessageStateMap;
static SyncMessageStateMap& syncMessageStateMap()
{
DEFINE_STATIC_LOCAL(SyncMessageStateMap, syncMessageStateMap, ());
return syncMessageStateMap;
}

static Mutex& syncMessageStateMapMutex()
{
DEFINE_STATIC_LOCAL(Mutex, syncMessageStateMapMutex, ());
return syncMessageStateMapMutex;
}
};

PassRefPtr<Connection::SyncMessageState> Connection::SyncMessageState::getOrCreate(RunLoop* runLoop)
{
MutexLocker locker(syncMessageStateMapMutex());
pair<SyncMessageStateMap::iterator, bool> result = syncMessageStateMap().add(runLoop, 0);

if (!result.second)
return result.first->second;

RefPtr<SyncMessageState> syncMessageState = adoptRef(new SyncMessageState(runLoop));
result.first->second = syncMessageState.get();

return syncMessageState.release();
}

Connection::SyncMessageState::SyncMessageState(RunLoop* runLoop)
: m_runLoop(runLoop)
{
}

Connection::SyncMessageState::~SyncMessageState()
{
MutexLocker locker(syncMessageStateMapMutex());

ASSERT(syncMessageStateMap().contains(m_runLoop));
syncMessageStateMap().remove(m_runLoop);
}

PassRefPtr<Connection> Connection::createServerConnection(Identifier identifier, Client* client, RunLoop* clientRunLoop)
{
return adoptRef(new Connection(identifier, true, client, clientRunLoop));
Expand Down
4 changes: 4 additions & 0 deletions Source/WebKit2/Platform/CoreIPC/Connection.h
Expand Up @@ -259,6 +259,10 @@ class Connection : public ThreadSafeShared<Connection> {

BinarySemaphore m_waitForSyncReplySemaphore;

class SyncMessageState;
friend class SyncMessageState;
RefPtr<SyncMessageState> m_syncMessageState;

Mutex m_syncReplyStateMutex;
bool m_shouldWaitForSyncReplies;
Vector<PendingSyncReply> m_pendingSyncReplies;
Expand Down

0 comments on commit a1c6b11

Please sign in to comment.