| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/** |
| 2 |
|
|
* @file stress_get_raw_boost_efficient.cpp |
| 3 |
|
|
* @author Vincent Berenz |
| 4 |
|
|
* @license License BSD-3-Clause |
| 5 |
|
|
* @copyright Copyright (c) 2019, New York University and Max Planck |
| 6 |
|
|
* Gesellschaft. |
| 7 |
|
|
* @date 2019-05-22 |
| 8 |
|
|
* |
| 9 |
|
|
* @brief Use the raw boost API in order to compare the efficiency of the new |
| 10 |
|
|
* API compare to the standard boost API |
| 11 |
|
|
*/ |
| 12 |
|
|
#include <boost/interprocess/managed_shared_memory.hpp> |
| 13 |
|
|
#include <boost/interprocess/sync/named_mutex.hpp> |
| 14 |
|
|
#include "shared_memory/benchmarks/benchmark_common.hh" |
| 15 |
|
|
|
| 16 |
|
✗ |
void cleaning_memory(int) |
| 17 |
|
|
{ |
| 18 |
|
✗ |
RUNNING = false; |
| 19 |
|
✗ |
boost::interprocess::named_mutex::remove(SHM_NAME.c_str()); |
| 20 |
|
|
} |
| 21 |
|
|
|
| 22 |
|
✗ |
int main() |
| 23 |
|
|
{ |
| 24 |
|
✗ |
boost::interprocess::named_mutex::remove(SHM_NAME.c_str()); |
| 25 |
|
|
|
| 26 |
|
|
// exiting on ctrl+c |
| 27 |
|
|
struct sigaction exiting; |
| 28 |
|
✗ |
exiting.sa_handler = cleaning_memory; |
| 29 |
|
✗ |
sigemptyset(&exiting.sa_mask); |
| 30 |
|
✗ |
exiting.sa_flags = 0; |
| 31 |
|
✗ |
sigaction(SIGINT, &exiting, nullptr); |
| 32 |
|
|
|
| 33 |
|
|
boost::interprocess::managed_shared_memory segment{ |
| 34 |
|
|
boost::interprocess::open_or_create, |
| 35 |
|
|
SHM_NAME.c_str(), |
| 36 |
|
✗ |
SHARED_MEMORY_SIZE}; |
| 37 |
|
|
|
| 38 |
|
|
boost::interprocess::named_mutex mutex{boost::interprocess::open_or_create, |
| 39 |
|
✗ |
SHM_OBJECT_NAME.c_str()}; |
| 40 |
|
|
|
| 41 |
|
|
std::pair<double*, std::size_t> object = |
| 42 |
|
✗ |
segment.find<double>(SHM_OBJECT_NAME.c_str()); |
| 43 |
|
|
|
| 44 |
|
✗ |
int count = 0; |
| 45 |
|
✗ |
RUNNING = true; |
| 46 |
|
✗ |
MeasureTime meas_time; |
| 47 |
|
✗ |
while (RUNNING && count < MAX_NUNMBER_OF_ITERATION) |
| 48 |
|
|
{ |
| 49 |
|
✗ |
mutex.lock(); |
| 50 |
|
✗ |
for (size_t i = 0; i < object.second; i++) |
| 51 |
|
|
{ |
| 52 |
|
✗ |
DATA[i] = (object.first)[i]; |
| 53 |
|
|
} |
| 54 |
|
✗ |
mutex.unlock(); |
| 55 |
|
|
|
| 56 |
|
✗ |
++count; |
| 57 |
|
✗ |
if (count % NUMBER_OR_MEASURED_ITERATIONS == 0) |
| 58 |
|
|
{ |
| 59 |
|
✗ |
meas_time.update(); |
| 60 |
|
✗ |
std::cout << meas_time << std::endl; |
| 61 |
|
|
} |
| 62 |
|
|
} |
| 63 |
|
✗ |
return 0; |
| 64 |
|
|
} |
| 65 |
|
|
|