| 195 | #endif |
| 196 | |
| 197 | std::unique_ptr<SharedMemory> makeSharedMemory(const ProjID proj_id, const uint64_t size) |
| 198 | { |
| 199 | OSRMLockFile lock_file(proj_id); |
| 200 | try |
| 201 | { |
| 202 | if (!std::filesystem::exists(lock_file.to_path())) |
| 203 | { |
| 204 | if (size == 0) |
| 205 | { |
| 206 | throw util::exception("Lock file does not exist, exiting. " + SOURCE_REF); |
| 207 | } |
| 208 | else |
| 209 | { |
| 210 | std::ofstream ofs(lock_file.to_path()); |
| 211 | } |
| 212 | } |
| 213 | return std::make_unique<SharedMemory>(proj_id, size); |
| 214 | } |
| 215 | catch (const interprocess_exception &e) |
| 216 | { |
| 217 | util::Log(logERROR) << "Error while attempting to allocate shared memory: " << e.what() |
| 218 | << ", code: " << e.get_error_code() |
| 219 | << ", lock file: " << lock_file.to_path(); |
| 220 | throw util::exception(e.what() + SOURCE_REF); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | // Try to use a directory for lock files. Creates it if needed. |
| 225 | // Returns true on success, false if the directory cannot be used. |
no test coverage detected