PityTest11 is a very flexible C++11 peer-to-peer test framework supporting hierarchically structured test suites, multi-processing, logging, IPC, synchronization and more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

40 lines
1.2 KiB

#include "fs_mutex.hh"
#include <pEp/std_utils.hh>
#include <fstream>
namespace pEp {
namespace PityTest11 {
fs_mutex::fs_mutex(std::string mutexpath) : mutexpath{ Utils::path_get_abs(mutexpath) } {}
void fs_mutex::aquire() const
{
if (mutexpath.empty()) {
throw std::runtime_error("no mutexpath set");
} else {
std::string mutex_file = mutexpath;
while (Utils::path_exists(mutex_file)) {
Utils::sleep_millis(2);
}
std::ofstream msgfile = Utils::file_create(mutexpath);
}
}
void fs_mutex::release() const
{
if (mutexpath.empty()) {
throw std::runtime_error("no mutexpath set");
} else {
try {
Utils::path_delete(mutexpath);
// Give others a chance to pickup
Utils::sleep_millis(4);
} catch (...) {
// pEpLogClass("Error releasing fsmutex");
}
}
}
} // namespace PityTest11
} // namespace pEp