2011-12-14 00:23:17 +03:00
|
|
|
#pragma once
|
|
|
|
|
2012-04-02 14:14:38 +03:00
|
|
|
#include <boost/interprocess/sync/scoped_lock.hpp>
|
2008-09-12 11:51:46 +03:00
|
|
|
#include <boost/interprocess/sync/interprocess_mutex.hpp>
|
|
|
|
#include <boost/interprocess/sync/interprocess_condition.hpp>
|
2009-01-11 00:08:18 +02:00
|
|
|
#include <boost/interprocess/mapped_region.hpp>
|
|
|
|
#include <boost/interprocess/shared_memory_object.hpp>
|
2008-09-12 11:51:46 +03:00
|
|
|
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* Interprocess.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-09-12 11:51:46 +03:00
|
|
|
struct ServerReady
|
|
|
|
{
|
|
|
|
bool ready;
|
|
|
|
boost::interprocess::interprocess_mutex mutex;
|
|
|
|
boost::interprocess::interprocess_condition cond;
|
|
|
|
|
|
|
|
ServerReady()
|
|
|
|
{
|
|
|
|
ready = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setToTrueAndNotify()
|
|
|
|
{
|
2012-02-20 00:03:43 +03:00
|
|
|
{
|
|
|
|
boost::unique_lock<boost::interprocess::interprocess_mutex> lock(mutex);
|
|
|
|
ready = true;
|
|
|
|
}
|
2008-09-12 11:51:46 +03:00
|
|
|
cond.notify_all();
|
|
|
|
}
|
|
|
|
};
|
2009-01-11 00:08:18 +02:00
|
|
|
|
|
|
|
struct SharedMem
|
|
|
|
{
|
|
|
|
boost::interprocess::shared_memory_object smo;
|
2009-01-31 00:23:13 +02:00
|
|
|
boost::interprocess::mapped_region *mr;
|
2009-01-11 00:08:18 +02:00
|
|
|
ServerReady *sr;
|
|
|
|
|
2009-05-07 20:20:41 +03:00
|
|
|
SharedMem() //c-tor
|
2009-01-31 00:23:13 +02:00
|
|
|
:smo(boost::interprocess::open_or_create,"vcmi_memory",boost::interprocess::read_write)
|
2009-01-11 00:08:18 +02:00
|
|
|
{
|
|
|
|
smo.truncate(sizeof(ServerReady));
|
2009-01-31 00:23:13 +02:00
|
|
|
mr = new boost::interprocess::mapped_region(smo,boost::interprocess::read_write);
|
|
|
|
sr = new(mr->get_address())ServerReady();
|
2009-01-11 00:08:18 +02:00
|
|
|
};
|
2009-05-07 20:20:41 +03:00
|
|
|
~SharedMem() //d-tor
|
2009-01-30 23:28:02 +02:00
|
|
|
{
|
2009-01-31 00:23:13 +02:00
|
|
|
delete mr;
|
2009-01-30 23:28:02 +02:00
|
|
|
boost::interprocess::shared_memory_object::remove("vcmi_memory");
|
|
|
|
}
|
2016-01-31 17:01:58 +02:00
|
|
|
};
|