phaser-server  0.0.4
sessionList.h
Go to the documentation of this file.
1 #ifndef SESSION_LIST_H
2 #define SESSION_LIST_H
8 #include <memory>
9 #include <list>
10 #include <mutex>
11 class Session;
12 
18 { public:
20  class ListKey
21  {
22  friend class SessionList;
23  public:
25  std::list<Session *> & GetList(void)
26  { return m_slist.m_sessions;
27  }
28 
30  ~ListKey(void)
31  { m_slist.m_lock.unlock();
32  }
33 
34  private:
36  ListKey(SessionList &slist) : m_slist(slist)
37  { m_slist.m_lock.lock();
38  }
39 
40  SessionList &m_slist;
41  };
42 
43  typedef std::unique_ptr<SessionList::ListKey> KeyPtr;
44 
46  KeyPtr TakeList(void)
47  { return KeyPtr(new ListKey(*this));
48  }
49 
50  private:
51  std::mutex m_lock;
52  std::list<Session *> m_sessions;
53 };
54 
55 #endif
A class that enforces serialized access to a list.
Definition: sessionList.h:21
~ListKey(void)
Destroy the key, which releases the lock.
Definition: sessionList.h:30
std::list< Session * > & GetList(void)
Get the list of session (and don't save the reference).
Definition: sessionList.h:25
Serialized use of a collection of sessions.
Definition: sessionList.h:18
KeyPtr TakeList(void)
Get the list serialization key.
Definition: sessionList.h:46
Manage one connection session with a client.
Definition: session.h:23