-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from jowillianto/feat/2/moderna-file-lock
Feat/2/moderna file lock
- Loading branch information
Showing
12 changed files
with
356 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
[submodule "lib/test-lib"] | ||
path = lib/test-lib | ||
url = https://github.com/jowillianto/test-lib | ||
[submodule "lib/pybind11"] | ||
[submodule "pybind11"] | ||
path = lib/pybind11 | ||
url = ../../pybind/pybind11 | ||
branch = stable | ||
url = https://github.com/pybind/pybind11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,65 @@ | ||
cmake_minimum_required(VERSION 3.28) | ||
project(multiprocessing_file_lock) | ||
project(moderna_file_lock) | ||
set (CMAKE_CXX_STANDARD 23) | ||
set (CMAKE_CXX_STANDARD_REQUIRED true) | ||
set (CMAKE_CXX_SCAN_FOR_MODULES true) | ||
|
||
find_package(Python3 3.7 REQUIRED COMPONENTS Interpreter Development) | ||
|
||
add_library(multiprocessing_file_lock) | ||
add_library(moderna_file_lock) | ||
file ( | ||
GLOB file_lock_ccm | ||
GLOB moderna_file_lock_src | ||
"${CMAKE_CURRENT_LIST_DIR}/src/*.ccm" | ||
) | ||
|
||
target_sources(multiprocessing_file_lock | ||
target_sources(moderna_file_lock | ||
PUBLIC | ||
FILE_SET CXX_MODULES FILES ${file_lock_ccm} | ||
FILE_SET CXX_MODULES FILES ${moderna_file_lock_src} | ||
) | ||
|
||
# PYTHON TARGET | ||
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/lib/pybind11/CMakeLists.txt) | ||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/lib/pybind11 EXCLUDE_FROM_ALL) | ||
add_library(multiprocessing_file_lock_python SHARED EXCLUDE_FROM_ALL) | ||
target_sources(multiprocessing_file_lock_python | ||
add_library(moderna_file_lock_python SHARED EXCLUDE_FROM_ALL) | ||
target_sources(moderna_file_lock_python | ||
PUBLIC | ||
${CMAKE_CURRENT_LIST_DIR}/python_wrapper/file_lock.cpp | ||
PUBLIC FILE_SET CXX_MODULES FILES ${file_lock_ccm} | ||
PUBLIC FILE_SET CXX_MODULES FILES ${moderna_file_lock_src} | ||
) | ||
target_include_directories(multiprocessing_file_lock_python | ||
target_include_directories(moderna_file_lock_python | ||
PUBLIC | ||
${pybind11_INCLUDE_DIRS} | ||
${Python_INCLUDE_DIRS} | ||
) | ||
target_link_libraries(multiprocessing_file_lock_python | ||
target_link_libraries(moderna_file_lock_python | ||
${pybind11_LIBRARIES} | ||
pybind11::module | ||
) | ||
set_target_properties(multiprocessing_file_lock_python PROPERTIES PREFIX "") | ||
set_target_properties(multiprocessing_file_lock_python PROPERTIES OUTPUT_NAME file_lock) | ||
set_target_properties(multiprocessing_file_lock_python PROPERTIES SUFFIX ".so") | ||
target_compile_options(multiprocessing_file_lock_python PRIVATE "-fPIC") | ||
set_target_properties(moderna_file_lock_python PROPERTIES PREFIX "") | ||
set_target_properties(moderna_file_lock_python PROPERTIES OUTPUT_NAME file_lock) | ||
set_target_properties(moderna_file_lock_python PROPERTIES SUFFIX ".so") | ||
target_compile_options(moderna_file_lock_python PRIVATE "-fPIC") | ||
endif() | ||
|
||
# TEST TARGET | ||
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/lib/test-lib/CMakeLists.txt) | ||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/lib/test-lib EXCLUDE_FROM_ALL) | ||
add_executable(multiprocessing_file_lock_test | ||
EXCLUDE_FROM_ALL | ||
${CMAKE_CURRENT_LIST_DIR}/tests/tests.cpp | ||
) | ||
target_link_libraries(multiprocessing_file_lock_test | ||
PRIVATE | ||
test_lib | ||
multiprocessing_file_lock | ||
) | ||
add_executable(multiprocessing_file_lock_test_leak_check | ||
EXCLUDE_FROM_ALL | ||
if( | ||
EXISTS ${CMAKE_CURRENT_LIST_DIR}/../test-lib/CMakeLists.txt | ||
AND EXISTS ${CMAKE_CURRENT_LIST_DIR}/../../cmake/CMakeLists.txt | ||
AND PROJECT_IS_TOP_LEVEL | ||
) | ||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../test-lib test-lib) | ||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../thread_plus thread_plus) | ||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../process process) | ||
include (CTest) | ||
include (${CMAKE_CURRENT_LIST_DIR}/../../cmake/CMakeLists.txt) | ||
add_test_asan_tsan_usan_ubsan ( | ||
moderna_file_lock_tests | ||
${CMAKE_CURRENT_LIST_DIR}/tests/tests.cpp | ||
"moderna_file_lock;moderna_test_lib;moderna_thread_plus;moderna_process" | ||
"TEST_CHILD=\"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_child\"" | ||
) | ||
target_link_libraries(multiprocessing_file_lock_test_leak_check | ||
PRIVATE | ||
test_lib | ||
multiprocessing_file_lock | ||
) | ||
target_compile_options(multiprocessing_file_lock_test_leak_check PRIVATE "-fsanitize=address") | ||
target_link_options(multiprocessing_file_lock_test_leak_check PRIVATE "-fsanitize=address") | ||
add_executable(test_child ${CMAKE_CURRENT_LIST_DIR}/tests/test_child.cpp) | ||
target_link_libraries(test_child moderna_file_lock) | ||
else() | ||
message("Test with moderna full library") | ||
endif() |
Submodule test-lib
deleted from
52c2ed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <string_view> | ||
#include <filesystem> | ||
#include <exception> | ||
#include <mutex> | ||
#include <iostream> | ||
#include <shared_mutex> | ||
import moderna.file_lock; | ||
|
||
template<moderna::file_lock::SharedMutex Mut> | ||
void act_or_exit(const Mut& m, std::string_view act_type) { | ||
if (act_type == "test_shared_lockable") { | ||
if (m.try_lock_shared()) { | ||
m.unlock_shared(); | ||
exit(0); | ||
} | ||
exit(1); | ||
} | ||
else if (act_type == "test_not_shared_lockable") { | ||
if (m.try_lock_shared()) { | ||
m.unlock_shared(); | ||
exit(1); | ||
} | ||
exit(0); | ||
} | ||
else if (act_type == "test_unique_lockable") { | ||
if (m.try_lock()) { | ||
m.unlock(); | ||
exit(0); | ||
} | ||
exit(1); | ||
} | ||
else if (act_type == "test_not_unique_lockable") { | ||
if (m.try_lock()) { | ||
m.unlock(); | ||
exit(1); | ||
} | ||
exit(0); | ||
} | ||
else | ||
throw std::bad_exception{ }; | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
if (argc != 4) { | ||
std::cerr<< "Wrong amount of arguments" <<std::endl; | ||
exit(1); | ||
} | ||
std::filesystem::path file_path { argv[1] }; | ||
std::string_view mut_type { argv[2] }; | ||
std::string_view act_type { argv[3] }; | ||
if (mut_type == "lf_mut") { | ||
act_or_exit(moderna::file_lock::LargeFileMutex{ file_path }, act_type); | ||
} | ||
else if (mut_type == "f_mut") { | ||
act_or_exit(moderna::file_lock::FileMutex{ file_path }, act_type); | ||
} | ||
else throw std::bad_exception{}; | ||
} |
Oops, something went wrong.