summaryrefslogtreecommitdiff
path: root/server/src/session.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/session.cc')
-rw-r--r--server/src/session.cc23
1 files changed, 15 insertions, 8 deletions
diff --git a/server/src/session.cc b/server/src/session.cc
index 8071d45..fcd138a 100644
--- a/server/src/session.cc
+++ b/server/src/session.cc
@@ -195,7 +195,7 @@ static bool fexists(const std::string &f)
return ret;
}
-Session *Sessions::newSession(std::string patientid, std::string templ)
+Session *Sessions::newLockedSession(std::string patientid, std::string templ)
throw(SessionAlreadyActive)
{
MutexAutolock lock(mutex);
@@ -209,6 +209,7 @@ Session *Sessions::newSession(std::string patientid, std::string templ)
DEBUG(session, "Patient/template matched session is already active.");
throw SessionAlreadyActive(session->id());
}
+ session->lock();
return session;
}
@@ -224,27 +225,33 @@ Session *Sessions::newSession(std::string patientid, std::string templ)
DEBUG(session, "Looked up session by id is already active.");
throw SessionAlreadyActive(session->id());
}
+ session->lock();
return session;
}
}
Session *session = new Session(env, "", patientid, templ);
sessions[session->id()] = session;
+ session->lock();
return session;
}
-Session *Sessions::session(std::string sessionid)
+Session *Sessions::lockedSession(std::string sessionid)
{
MutexAutolock lock(mutex);
- if(sessions.find(sessionid) != sessions.end())
- return sessions[sessionid];
+ if(sessions.find(sessionid) != sessions.end()) {
+ Session *s = sessions[sessionid];
+ s->lock();
+ return s;
+ }
std::string filename = getSessionFilename(Conf::session_path, sessionid);
if(fexists(filename)) {
SessionSerialiser ser(env, Conf::session_path);
Session *s = ser.load(sessionid);
sessions[s->id()] = s;
+ s->lock();
return s;
}
@@ -311,15 +318,15 @@ std::vector<std::string> Sessions::activeSessions()
return act;
}
-SessionAutolock::SessionAutolock(Session &s)
+SessionAutounlock::SessionAutounlock(Session **s)
: session(s)
{
- session.lock();
+ // session->lock();
}
-SessionAutolock::~SessionAutolock()
+SessionAutounlock::~SessionAutounlock()
{
- session.unlock();
+ if(*session) (*session)->unlock();
}
#ifdef TEST_SESSION