Interprocess.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. {
  30. smo.truncate(sizeof(ServerReady));
  31. mr = new boost::interprocess::mapped_region(smo,boost::interprocess::read_write);
  32. sr = new(mr->get_address())ServerReady();
  33. };
  34. ~SharedMem()
  35. {
  36. delete mr;
  37. boost::interprocess::shared_memory_object::remove("vcmi_memory");
  38. }
  39. };