summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--project2/sessionShm.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/project2/sessionShm.cpp b/project2/sessionShm.cpp
index e4c9d16..8064142 100644
--- a/project2/sessionShm.cpp
+++ b/project2/sessionShm.cpp
@@ -24,13 +24,14 @@ class SessionShmData {
SessionValues svs;
time_t expiryTime;
- static boost::interprocess::managed_mapped_file shm;
+ static boost::interprocess::managed_mapped_file & shm();
+ static boost::shared_ptr<boost::interprocess::managed_mapped_file> _shm;
friend class SessionContainerShm;
};
const char * shmFile = "/tmp/project2.sessions";
-boost::interprocess::managed_mapped_file SessionShmData::shm(open_or_create, shmFile, 1024 * 1024);
+boost::shared_ptr<boost::interprocess::managed_mapped_file> SessionShmData::_shm;
SessionContainerShm::SessionContainerShm()
{
@@ -44,8 +45,8 @@ void
SessionContainerShm::CleanUp()
{
std::set<std::string> toDelete;
- for (managed_mapped_file::const_named_iterator i = SessionShmData::shm.named_begin();
- i != SessionShmData::shm.named_end(); i++) {
+ for (managed_mapped_file::const_named_iterator i = SessionShmData::shm().named_begin();
+ i != SessionShmData::shm().named_end(); i++) {
const SessionShmData * s = static_cast<const SessionShmData *>(i->value());
if (s) {
if (s->expiryTime < time(NULL)) {
@@ -54,7 +55,7 @@ SessionContainerShm::CleanUp()
}
}
for(std::set<std::string>::const_iterator s = toDelete.begin(); s != toDelete.end(); s++) {
- SessionShmData::shm.destroy<const SessionShmData>(s->c_str());
+ SessionShmData::shm().destroy<const SessionShmData>(s->c_str());
}
}
@@ -65,7 +66,7 @@ SessionContainerShm::getSession(boost::uuids::uuid & sid)
sid = boost::uuids::random_generator()();
}
return SessionPtr(new SessionShm(
- SessionShmData::shm.find_or_construct<SessionShmData>(boost::lexical_cast<std::string>(sid).c_str())()));
+ SessionShmData::shm().find_or_construct<SessionShmData>(boost::lexical_cast<std::string>(sid).c_str())()));
}
SessionShm::SessionShm(SessionShmData * d) : data(d)
@@ -89,7 +90,7 @@ SessionShm::ExpiryTime() const
}
SessionShmData::SessionShmData() :
- svs(std::less<SKey>(), AllocatorValueType(shm.get_segment_manager()))
+ svs(std::less<SKey>(), AllocatorValueType(shm().get_segment_manager()))
{
}
@@ -97,6 +98,16 @@ SessionShmData::~SessionShmData()
{
}
+boost::interprocess::managed_mapped_file &
+SessionShmData::shm()
+{
+ if (!_shm) {
+ _shm = boost::shared_ptr<boost::interprocess::managed_mapped_file>(
+ new boost::interprocess::managed_mapped_file(open_or_create, shmFile, 1024 * 1024));
+ }
+ return *_shm;
+}
+
Glib::ustring
SessionShm::GetValue(const Glib::ustring & name) const
{