From 72b7d402e36ac2235e89c3b099a634f3fb5e5770 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 1 Mar 2012 15:36:13 +0100 Subject: activeSessions rewrite to prevent deadlock. --- server/src/admin_connection.cc | 14 ++++---------- server/src/session.cc | 20 +++++++++++++++++--- server/src/session.h | 12 +++++++++++- 3 files changed, 32 insertions(+), 14 deletions(-) (limited to 'server') diff --git a/server/src/admin_connection.cc b/server/src/admin_connection.cc index f761023..1522627 100644 --- a/server/src/admin_connection.cc +++ b/server/src/admin_connection.cc @@ -59,17 +59,11 @@ static std::string admin_listactivesessions(Environment &env) { std::string str; - std::vector act = env.sessions.activeSessions(); - std::vector::iterator i = act.begin(); + std::vector act = env.sessions.activeSessions(); + std::vector::iterator i = act.begin(); while(i != act.end()) { - // NOTE: Returned session is returned in locked state! - Session *s = NULL; - SessionAutounlock l(&s); - s = env.sessions.lockedSession(*i); - if(s) { - str += "Session " + *i + ": "+s->templ+" on "+s->patientid+" "+ - std::string(s->idle()?"[idle]":"[active]")+"\n"; - } + str += "Session " + i->id + ": "+i->templ+" on "+i->patientid+" "+ + std::string(i->idle?"[idle]":"[active]")+"\n"; i++; } diff --git a/server/src/session.cc b/server/src/session.cc index 6bb4440..57499f9 100644 --- a/server/src/session.cc +++ b/server/src/session.cc @@ -346,15 +346,29 @@ void Sessions::store() */ } -std::vector Sessions::activeSessions() +std::vector Sessions::activeSessions() { MutexAutolock lock(mutex); - std::vector act; + std::vector act; std::map::iterator i = sessions.begin(); while(i != sessions.end()) { - act.push_back(i->first); + Session *s = i->second; + SessionInfo si; + si.id = i->first; + si.templ = "LOCKED" + + if(s->trylock()) { + // si.user = "simpson"; + // si.course = s->course; + si.patientid = s->patientid; + si.templ = s->templ; + si.idle = s->idle(); + // si.ondisc = false; + s->unlock(); + } + act.push_back(si); i++; } diff --git a/server/src/session.h b/server/src/session.h index 9ad84b5..1cb3041 100644 --- a/server/src/session.h +++ b/server/src/session.h @@ -132,7 +132,17 @@ public: // // Admin methods // - std::vector activeSessions(); + class SessionInfo { + public: + std::string id; + std::string patientid; + std::string user; + std::string course; + std::string templ; + bool idle; + bool ondisc; + }; + std::vector activeSessions(); private: std::map sessions; -- cgit v1.2.3