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.
43 lines
1.2 KiB
43 lines
1.2 KiB
// This file is under GNU General Public License 3.0
|
|
// see LICENSE.txt
|
|
|
|
#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
|
|
|