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()
|
|
|
|
{
|
|
|
|
mutex.lock();
|
|
|
|
ready = true;
|
|
|
|
mutex.unlock();
|
|
|
|
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;
|
|
|
|
|
|
|
|
SharedMem()
|
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-01-30 23:28:02 +02:00
|
|
|
~SharedMem()
|
|
|
|
{
|
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");
|
|
|
|
}
|
2009-01-11 00:08:18 +02:00
|
|
|
};
|