Interprocess.h 1001 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <boost/interprocess/sync/interprocess_mutex.hpp>
  2. #include <boost/interprocess/sync/interprocess_condition.hpp>
  3. #include <boost/interprocess/mapped_region.hpp>
  4. #include <boost/interprocess/shared_memory_object.hpp>
  5. struct ServerReady
  6. {
  7. bool ready;
  8. boost::interprocess::interprocess_mutex mutex;
  9. boost::interprocess::interprocess_condition cond;
  10. ServerReady()
  11. {
  12. ready = false;
  13. }
  14. void setToTrueAndNotify()
  15. {
  16. mutex.lock();
  17. ready = true;
  18. mutex.unlock();
  19. cond.notify_all();
  20. }
  21. };
  22. struct SharedMem
  23. {
  24. boost::interprocess::shared_memory_object smo;
  25. boost::interprocess::mapped_region mr;
  26. ServerReady *sr;
  27. SharedMem()
  28. :smo(boost::interprocess::open_or_create,"vcmi_memory",boost::interprocess::read_write),
  29. mr(smo,boost::interprocess::read_write)
  30. {
  31. smo.truncate(sizeof(ServerReady));
  32. sr = new(mr.get_address())ServerReady();
  33. };
  34. ~SharedMem()
  35. {
  36. boost::interprocess::shared_memory_object::remove("vcmi_memory");
  37. }
  38. };