Skip to content

Commit 78f8427

Browse files
committed
removed simple lock
1 parent 9cfe1cd commit 78f8427

File tree

2 files changed

+0
-131
lines changed

2 files changed

+0
-131
lines changed

libraries/fc/include/fc/filesystem.hpp

-33
Original file line numberDiff line numberDiff line change
@@ -225,38 +225,5 @@ namespace fc {
225225
temp_directory& operator=(temp_directory&& other);
226226
temp_directory(const fc::path& tempFolder = fc::temp_directory_path());
227227
};
228-
229-
230-
#if !defined(__APPLE__)
231-
// this code is known to work on linux and windows. It may work correctly on mac,
232-
// or it may need slight tweaks or extra includes. It's disabled now to avoid giving
233-
// a false sense of security.
234-
# define FC_HAS_SIMPLE_FILE_LOCK
235-
#endif
236-
#ifdef FC_HAS_SIMPLE_FILE_LOCK
237-
/** simple class which only allows one process to open any given file.
238-
* approximate usage:
239-
* int main() {
240-
* fc::simple_file_lock instance_lock("~/.my_app/.lock");
241-
* if (!instance_lock.try_lock()) {
242-
* elog("my_app is already running");
243-
* return 1;
244-
* }
245-
* // do stuff here, file will be unlocked when instance_lock goes out of scope
246-
* }
247-
*/
248-
class simple_lock_file
249-
{
250-
public:
251-
simple_lock_file(const path& lock_file_path);
252-
~simple_lock_file();
253-
bool try_lock();
254-
void unlock();
255-
private:
256-
class impl;
257-
std::unique_ptr<impl> my;
258-
};
259-
#endif // FC_HAS_SIMPLE_FILE_LOCK
260-
261228
}
262229

libraries/fc/src/filesystem.cpp

-98
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//#define BOOST_NO_SCOPED_ENUMS
21
#include <fc/filesystem.hpp>
32
#include <fc/exception/exception.hpp>
43
#include <fc/fwd_impl.hpp>
@@ -499,101 +498,4 @@ namespace fc {
499498
return appCurrentPath;
500499
}
501500

502-
503-
#ifdef FC_HAS_SIMPLE_FILE_LOCK
504-
class simple_lock_file::impl
505-
{
506-
public:
507-
#ifdef _WIN32
508-
HANDLE file_handle;
509-
#else
510-
int file_handle;
511-
#endif
512-
bool is_locked;
513-
path lock_file_path;
514-
515-
impl(const path& lock_file_path);
516-
~impl();
517-
518-
bool try_lock();
519-
void unlock();
520-
};
521-
522-
simple_lock_file::impl::impl(const path& lock_file_path) :
523-
#ifdef _WIN32
524-
file_handle(INVALID_HANDLE_VALUE),
525-
#else
526-
file_handle(-1),
527-
#endif
528-
is_locked(false),
529-
lock_file_path(lock_file_path)
530-
{}
531-
532-
simple_lock_file::impl::~impl()
533-
{
534-
unlock();
535-
}
536-
537-
bool simple_lock_file::impl::try_lock()
538-
{
539-
#ifdef _WIN32
540-
HANDLE fh = CreateFileA(lock_file_path.to_native_ansi_path().c_str(),
541-
GENERIC_READ | GENERIC_WRITE,
542-
0, 0,
543-
OPEN_ALWAYS, 0, NULL);
544-
if (fh == INVALID_HANDLE_VALUE)
545-
return false;
546-
is_locked = true;
547-
file_handle = fh;
548-
return true;
549-
#else
550-
int fd = open(lock_file_path.string().c_str(), O_RDWR|O_CREAT, 0644);
551-
if (fd < 0)
552-
return false;
553-
if (flock(fd, LOCK_EX|LOCK_NB) == -1)
554-
{
555-
close(fd);
556-
return false;
557-
}
558-
is_locked = true;
559-
file_handle = fd;
560-
return true;
561-
#endif
562-
}
563-
564-
void simple_lock_file::impl::unlock()
565-
{
566-
#ifdef WIN32
567-
CloseHandle(file_handle);
568-
file_handle = INVALID_HANDLE_VALUE;
569-
is_locked = false;
570-
#else
571-
flock(file_handle, LOCK_UN);
572-
close(file_handle);
573-
file_handle = -1;
574-
is_locked = false;
575-
#endif
576-
}
577-
578-
579-
simple_lock_file::simple_lock_file(const path& lock_file_path) :
580-
my(new impl(lock_file_path))
581-
{
582-
}
583-
584-
simple_lock_file::~simple_lock_file()
585-
{
586-
}
587-
588-
bool simple_lock_file::try_lock()
589-
{
590-
return my->try_lock();
591-
}
592-
593-
void simple_lock_file::unlock()
594-
{
595-
my->unlock();
596-
}
597-
#endif // FC_HAS_SIMPLE_FILE_LOCK
598-
599501
}

0 commit comments

Comments
 (0)