diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2012-04-12 10:04:37 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2012-04-12 10:04:37 +0200 |
commit | 4c39b3361c7f873174a5c091943aa1e47861fb9f (patch) | |
tree | a750a9996e3040adb52499bebffd0562df5e3a8f /server/src | |
parent | 218e44449d06ea7e18e0acc5a2270bdcad3be41a (diff) |
Add delay on trylock on session fail, before trying again.
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/session.cc | 16 |
1 files 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); |