From 4edae3f518353bb21a02fcda2dfcff83c5a72fc3 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 26 Jan 2012 12:08:39 +0100 Subject: New onCommit scripting system. --- server/src/session.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'server/src/session.cc') diff --git a/server/src/session.cc b/server/src/session.cc index fcd138a..234f004 100644 --- a/server/src/session.cc +++ b/server/src/session.cc @@ -121,12 +121,21 @@ void Session::setIdle(bool idle) } } -void Session::commit() +void Session::commit() throw(LUAScript::Exception, Journal::Exception) { DEBUG(session, "[%p] commit(sessionid: '%s')\n", this, sessionid.c_str()); if(_journal != NULL) { - _journal->commit(); + try { + _journal->runOnCommitScripts(); + } catch(LUAScript::Exception &e) { + throw e; + } + try { + _journal->commit(); + } catch(Journal::Exception &e) { + throw e; + } delete _journal; _journal = NULL; } -- cgit v1.2.3 From ddd6826b161e2bb7735b152c15c9ba9bab79aa29 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 23 Feb 2012 10:41:20 +0100 Subject: Remove deadlock in session store. --- server/src/session.cc | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'server/src/session.cc') diff --git a/server/src/session.cc b/server/src/session.cc index 234f004..6bb4440 100644 --- a/server/src/session.cc +++ b/server/src/session.cc @@ -82,10 +82,20 @@ std::string Session::id() void Session::lock() { mutex.lock(); + DEBUG(session, "lock() %p (%s)\n", this, sessionid.c_str()); +} + +bool Session::trylock() +{ + bool r = mutex.trylock(); + DEBUG(session, "trylock() %p (%s) == %s\n", + this, sessionid.c_str(), r?"true":"false"); + return r; } void Session::unlock() { + DEBUG(session, "unlock() %p (%s)\n", this, sessionid.c_str()); mutex.unlock(); } @@ -299,17 +309,41 @@ size_t Sessions::size() void Sessions::store() { + Session *session = NULL; + std::string sessionid; + do { + session = NULL; + { + MutexAutolock lock(mutex); + std::map::iterator head = sessions.begin(); + if(head != sessions.end()) { + session = head->second; + sessionid = head->first; + if(session->trylock()) sessions.erase(sessionid); + else continue; + } + } + if(session != NULL) { + SessionSerialiser ser(env, Conf::session_path); + ser.save(session); + delete session; + } + } while(session != NULL); + + /* MutexAutolock lock(mutex); std::map::iterator i = sessions.begin(); while(i != sessions.end()) { SessionSerialiser ser(env, Conf::session_path); - ser.save(i->second); - delete i->second; - sessions.erase(i); + Session *s = i->second; + s->lock(); + ser.save(s); + delete s; i++; } sessions.clear(); + */ } std::vector Sessions::activeSessions() @@ -335,6 +369,7 @@ SessionAutounlock::SessionAutounlock(Session **s) SessionAutounlock::~SessionAutounlock() { + DEBUG(session, "SessionAutounlock(%p)\n", *session); if(*session) (*session)->unlock(); } -- cgit v1.2.3 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/session.cc | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'server/src/session.cc') 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++; } -- cgit v1.2.3 From 218e44449d06ea7e18e0acc5a2270bdcad3be41a Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 1 Mar 2012 15:38:04 +0100 Subject: oups --- server/src/session.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/src/session.cc') diff --git a/server/src/session.cc b/server/src/session.cc index 57499f9..477fb19 100644 --- a/server/src/session.cc +++ b/server/src/session.cc @@ -357,7 +357,7 @@ std::vector Sessions::activeSessions() Session *s = i->second; SessionInfo si; si.id = i->first; - si.templ = "LOCKED" + si.templ = "LOCKED"; if(s->trylock()) { // si.user = "simpson"; -- cgit v1.2.3 From 4c39b3361c7f873174a5c091943aa1e47861fb9f Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 12 Apr 2012 10:04:37 +0200 Subject: Add delay on trylock on session fail, before trying again. --- server/src/session.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'server/src/session.cc') diff --git a/server/src/session.cc b/server/src/session.cc index 477fb19..ea4d11c 100644 --- a/server/src/session.cc +++ b/server/src/session.cc @@ -55,6 +55,8 @@ Session::Session(Environment *e, patientid = pid; templ = t; + mutex.name = "session-" + sid; + DEBUG(session, "[%p] new Session(sessionid: '%s', patientid: '%s'," " template: '%s')\n", this, sid.c_str(), pid.c_str(), t.c_str()); @@ -312,6 +314,7 @@ void Sessions::store() Session *session = NULL; std::string sessionid; do { + bool waitcont = false; session = NULL; { MutexAutolock lock(mutex); @@ -319,10 +322,19 @@ void Sessions::store() if(head != sessions.end()) { session = head->second; sessionid = head->first; - if(session->trylock()) sessions.erase(sessionid); - else continue; + if(session->trylock()) { + sessions.erase(sessionid); + } else { + waitcont = true; + } } } + + if(waitcont) { + usleep(200000); // sleep 200ms + continue; + } + if(session != NULL) { SessionSerialiser ser(env, Conf::session_path); ser.save(session); -- cgit v1.2.3