lean4-htt/src/util/file_lock.h
Leonardo de Moura 4dc3764a02 feat(util,library,shell): basic locking mechanism
We still have to test on Windows.
see issue #925
2015-12-12 21:26:13 -08:00

33 lines
1 KiB
C++

/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include <string>
namespace lean {
/** \brief Helper class for creating an auxiliary lean file and locking it.
We use this object to prevent a lean process from reading a .olean (.ilean/.clean)
file while another one is writing. */
class file_lock {
std::string m_fname;
int m_fd;
public:
file_lock(char const * fname, bool exclusive);
file_lock(std::string const & fname, bool exclusive):file_lock(fname.c_str(), exclusive) {}
~file_lock();
};
class exclusive_file_lock : public file_lock {
public:
exclusive_file_lock(char const * fname):file_lock(fname, true) {}
exclusive_file_lock(std::string const & fname):file_lock(fname, true) {}
};
class shared_file_lock : public file_lock {
public:
shared_file_lock(char const * fname):file_lock(fname, false) {}
shared_file_lock(std::string const & fname):file_lock(fname, false) {}
};
}