|
16 | 16 |
|
17 | 17 | #include <algorithm>
|
18 | 18 | #include <chrono>
|
| 19 | +#include <cstring> |
19 | 20 | #include <functional>
|
20 | 21 | #include <memory>
|
21 | 22 | #include <stdexcept>
|
|
33 | 34 | #include "rosbag2_storage/storage_interfaces/read_write_interface.hpp"
|
34 | 35 |
|
35 | 36 | #include "logging.hpp"
|
| 37 | +#ifdef _WIN32 |
| 38 | +#include <windows.h> |
| 39 | +#else |
| 40 | +#include <unistd.h> |
| 41 | +#include <sys/resource.h> |
| 42 | +#endif |
36 | 43 |
|
37 | 44 | namespace rosbag2_compression
|
38 | 45 | {
|
@@ -62,6 +69,42 @@ SequentialCompressionWriter::~SequentialCompressionWriter()
|
62 | 69 |
|
63 | 70 | void SequentialCompressionWriter::compression_thread_fn()
|
64 | 71 | {
|
| 72 | + if (compression_options_.thread_nice_value) { |
| 73 | + |
| 74 | +#ifdef _WIN32 |
| 75 | + ROSBAG2_COMPRESSION_LOG_WARN_STREAM("Lowering of process priority is not implemented for windows"); |
| 76 | + |
| 77 | + /** |
| 78 | + * The implementation should look something like this |
| 79 | +
|
| 80 | + uint8_t nice_value = *compression_options_.thread_nice_value; |
| 81 | +
|
| 82 | + // this must match THREAD_PRIORITY_IDLE, THREAD_PRIORITY_LOWEST... |
| 83 | + DWORD dwThreadPri = *compression_options_.thread_nice_value; |
| 84 | +
|
| 85 | + if(!SetThreadPriority(GetCurrentThread(), dwThreadPri)) |
| 86 | + { |
| 87 | + ROSBAG2_COMPRESSION_LOG_WARN_STREAM( |
| 88 | + "Could not set nice value of compression thead to " << nice_value << " : " << std::strerror( |
| 89 | + errno)); |
| 90 | + } |
| 91 | + */ |
| 92 | + |
| 93 | +#else |
| 94 | + int wanted_nice_value = *compression_options_.thread_nice_value; |
| 95 | + |
| 96 | + int cur_nice_value = getpriority(PRIO_PROCESS, 0); |
| 97 | + |
| 98 | + int new_nice_value = nice(wanted_nice_value - cur_nice_value); |
| 99 | + if(new_nice_value == -1 || new_nice_value != wanted_nice_value) |
| 100 | + { |
| 101 | + ROSBAG2_COMPRESSION_LOG_WARN_STREAM( |
| 102 | + "Could not set nice value of compression thead to " << wanted_nice_value << " : " << std::strerror( |
| 103 | + errno)); |
| 104 | + } |
| 105 | +#endif |
| 106 | + } |
| 107 | + |
65 | 108 | // Every thread needs to have its own compression context for thread safety.
|
66 | 109 | auto compressor = compression_factory_->create_compressor(
|
67 | 110 | compression_options_.compression_format);
|
|
0 commit comments