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(-) 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