| Line |
Branch |
Exec |
Source |
| 1 |
|
|
// Copyright 2019 Max Planck Gesellschaft and New York University |
| 2 |
|
|
// Authors : Vincent Berenz, Maximilien Naveau |
| 3 |
|
|
|
| 4 |
|
|
#include "shared_memory/shared_memory.hpp" |
| 5 |
|
|
#include "shared_memory/condition_variable.hpp" |
| 6 |
|
|
#include "shared_memory/lock.hpp" |
| 7 |
|
|
#include "shared_memory/locked_condition_variable.hpp" |
| 8 |
|
|
#include "shared_memory/mutex.hpp" |
| 9 |
|
|
|
| 10 |
|
|
#include <pybind11/pybind11.h> |
| 11 |
|
|
#include <pybind11/stl.h> |
| 12 |
|
|
|
| 13 |
|
|
using namespace shared_memory; |
| 14 |
|
|
|
| 15 |
|
✗ |
PYBIND11_MODULE(shared_memory, m) |
| 16 |
|
|
{ |
| 17 |
|
|
// Mutex |
| 18 |
|
|
|
| 19 |
|
✗ |
pybind11::class_<Mutex>(m, "Mutex") |
| 20 |
|
✗ |
.def(pybind11::init<std::string, bool>()) |
| 21 |
|
✗ |
.def("unlock", &Mutex::unlock) |
| 22 |
|
✗ |
.def("lock", &Mutex::lock) |
| 23 |
|
✗ |
.def_static("clean", &Mutex::clean); |
| 24 |
|
|
|
| 25 |
|
|
// Lock |
| 26 |
|
|
|
| 27 |
|
✗ |
pybind11::class_<Lock>(m, "Lock").def(pybind11::init<Mutex&>()); |
| 28 |
|
|
|
| 29 |
|
|
// ConditionVariable |
| 30 |
|
|
|
| 31 |
|
✗ |
pybind11::class_<ConditionVariable>(m, "ConditionVariable") |
| 32 |
|
✗ |
.def(pybind11::init<std::string, bool>()) |
| 33 |
|
✗ |
.def("notify_all", &ConditionVariable::notify_all) |
| 34 |
|
✗ |
.def("notify_one", &ConditionVariable::notify_one) |
| 35 |
|
✗ |
.def("timed_wait", &ConditionVariable::timed_wait) |
| 36 |
|
✗ |
.def("wait", &ConditionVariable::wait) |
| 37 |
|
✗ |
.def_static("clean", &ConditionVariable::clean); |
| 38 |
|
|
|
| 39 |
|
|
// LockedConditionVariable |
| 40 |
|
|
|
| 41 |
|
✗ |
pybind11::class_<LockedConditionVariable>(m, "LockedConditionVariable") |
| 42 |
|
✗ |
.def(pybind11::init<std::string, bool>()) |
| 43 |
|
✗ |
.def("notify_all", &LockedConditionVariable::notify_all) |
| 44 |
|
✗ |
.def("notify_one", &LockedConditionVariable::notify_one) |
| 45 |
|
✗ |
.def("timed_wait", &LockedConditionVariable::timed_wait) |
| 46 |
|
✗ |
.def("wait", &LockedConditionVariable::wait) |
| 47 |
|
✗ |
.def("try_lock", &LockedConditionVariable::try_lock) |
| 48 |
|
✗ |
.def("unlock", &LockedConditionVariable::unlock) |
| 49 |
|
✗ |
.def("lock_scope", &LockedConditionVariable::lock_scope) |
| 50 |
|
✗ |
.def("unlock_scope", &LockedConditionVariable::unlock_scope) |
| 51 |
|
✗ |
.def_static("clean", &LockedConditionVariable::clean); |
| 52 |
|
|
|
| 53 |
|
|
// Shared memory |
| 54 |
|
|
|
| 55 |
|
|
// sharing a boolean |
| 56 |
|
✗ |
m.def("set_bool", [](std::string segment, std::string object, bool value) { |
| 57 |
|
✗ |
shared_memory::set<bool>(segment, object, value); |
| 58 |
|
✗ |
}); |
| 59 |
|
✗ |
m.def("get_bool", [](std::string segment, std::string object) { |
| 60 |
|
|
bool value; |
| 61 |
|
✗ |
shared_memory::get<bool>(segment, object, value); |
| 62 |
|
✗ |
return value; |
| 63 |
|
✗ |
}); |
| 64 |
|
|
|
| 65 |
|
✗ |
m.def("set_int", [](std::string segment, std::string object, int value) { |
| 66 |
|
✗ |
shared_memory::set<int>(segment, object, value); |
| 67 |
|
✗ |
}); |
| 68 |
|
✗ |
m.def("get_int", [](std::string segment, std::string object) { |
| 69 |
|
|
int value; |
| 70 |
|
✗ |
shared_memory::get<int>(segment, object, value); |
| 71 |
|
✗ |
return value; |
| 72 |
|
✗ |
}); |
| 73 |
|
|
|
| 74 |
|
✗ |
m.def("set_long_int", |
| 75 |
|
✗ |
[](std::string segment, std::string object, long int value) { |
| 76 |
|
✗ |
shared_memory::set<long int>(segment, object, value); |
| 77 |
|
✗ |
}); |
| 78 |
|
|
|
| 79 |
|
✗ |
m.def("get_long_int", [](std::string segment, std::string object) { |
| 80 |
|
|
long int value; |
| 81 |
|
✗ |
shared_memory::get<long int>(segment, object, value); |
| 82 |
|
✗ |
return value; |
| 83 |
|
✗ |
}); |
| 84 |
|
|
|
| 85 |
|
✗ |
m.def("set_double", |
| 86 |
|
✗ |
[](std::string segment, std::string object, double value) { |
| 87 |
|
✗ |
shared_memory::set<double>(segment, object, value); |
| 88 |
|
✗ |
}); |
| 89 |
|
✗ |
m.def("get_double", [](std::string segment, std::string object) { |
| 90 |
|
|
double value; |
| 91 |
|
✗ |
shared_memory::get<double>(segment, object, value); |
| 92 |
|
✗ |
return value; |
| 93 |
|
✗ |
}); |
| 94 |
|
|
|
| 95 |
|
✗ |
m.def("set_string", |
| 96 |
|
✗ |
[](std::string segment, std::string object, std::string value) { |
| 97 |
|
✗ |
shared_memory::set<std::string>(segment, object, value); |
| 98 |
|
✗ |
}); |
| 99 |
|
|
|
| 100 |
|
✗ |
m.def("get_string", [](std::string segment, std::string object) { |
| 101 |
|
✗ |
std::string value; |
| 102 |
|
✗ |
shared_memory::get<std::string>(segment, object, value); |
| 103 |
|
✗ |
return value; |
| 104 |
|
✗ |
}); |
| 105 |
|
|
|
| 106 |
|
✗ |
m.def("clear_shared_memory", [](std::string segment) { |
| 107 |
|
✗ |
shared_memory::clear_shared_memory(segment); |
| 108 |
|
✗ |
}); |
| 109 |
|
|
|
| 110 |
|
✗ |
m.def("wait_for_segment", [](std::string segment, int timeout_ms) { |
| 111 |
|
|
return shared_memory::wait_for_segment(segment, timeout_ms); |
| 112 |
|
✗ |
}); |
| 113 |
|
|
|
| 114 |
|
✗ |
m.def("disconnect_segment", [](std::string segment) { |
| 115 |
|
✗ |
return shared_memory::delete_segment(segment); |
| 116 |
|
✗ |
}); |
| 117 |
|
|
|
| 118 |
|
✗ |
m.def("delete_segment", [](std::string segment) { |
| 119 |
|
✗ |
return shared_memory::delete_segment(segment); |
| 120 |
|
✗ |
}); |
| 121 |
|
|
|
| 122 |
|
✗ |
m.def("delete_all_segments", |
| 123 |
|
✗ |
[]() { return shared_memory::delete_all_segments(); }); |
| 124 |
|
|
} |
| 125 |
|
|
|