Skip to content

Commit

Permalink
Merge pull request #23 from toppers/mmap
Browse files Browse the repository at this point in the history
Mmap
  • Loading branch information
tmori authored Feb 11, 2024
2 parents 279132c + 2ddf970 commit e48d579
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 13 deletions.
9 changes: 7 additions & 2 deletions build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ mkdir -p cmake-build
cd cmake-build
if [ ${OPT} = "test" ]
then
cmake -D test=true -D debug=true -D gcov=true .. ${OS_OPT}
if [ ${OS_TYPE} = "posix" ]
then
cmake -D test=true -D debug=true -D gcov=true .. ${OS_OPT}
else
cmake -G "Unix Makefiles" -D WIN32=true -D test=true -D debug=true -D gcov=true .. ${OS_OPT}
fi

make
make test
Expand All @@ -45,7 +50,7 @@ else
then
cmake -D test=false -D debug=true -D gcov=false ..
else
cmake .. -G "MSYS Makefiles"
cmake .. -G "Unix Makefiles" -D WIN32=true
fi
make
fi
Expand Down
17 changes: 13 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ project(hakoniwa-core
set(OS_TYPE "posix")
if(WIN32)
set(OS_TYPE "win")
elseif(MSYS)
set(OS_TYPE "win")
endif(WIN32)
MESSAGE(STATUS "OS_TYPE=" ${OS_TYPE})

include(FetchContent)
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz DOWNLOAD_EXTRACT_TIMESTAMP true)
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz )
FetchContent_MakeAvailable(json)

add_library(
Expand All @@ -30,13 +32,18 @@ add_library(

#for sem && shared memory
hako/utils/hako_share/impl/hako_shared_memory_factory.cpp
hako/utils/hako_share/impl/posix/hako_shared_memory_shm.cpp
hako/utils/hako_share/impl/posix/hako_sem.cpp

hako/utils/hako_share/impl/${OS_TYPE}/os_file_io.cpp
hako/utils/hako_string.cpp
hako/utils/hako_logger.cpp
)
# POSIX特有のファイルをWIN32ではない場合にのみ追加
if(NOT WIN32)
target_sources(hako PRIVATE
hako/utils/hako_share/impl/posix/hako_shared_memory_shm.cpp
hako/utils/hako_share/impl/posix/hako_sem.cpp
)
endif()

target_include_directories(
hako
Expand All @@ -46,4 +53,6 @@ target_include_directories(
PRIVATE ${PROJECT_SOURCE_DIR}/hako
PRIVATE ${nlohmann_json_SOURCE_DIR}/single_include
)

if(WIN32)
target_link_libraries(hako stdc++)
endif()
13 changes: 10 additions & 3 deletions src/hako/core/rpc/hako_internal_rpc.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#include "core/rpc/hako_internal_rpc.hpp"
#include "core/context/hako_context.hpp"
#ifdef WIN32
using hako::utils::sem::flock::asset_up;
using hako::utils::sem::flock::asset_down;
#else
using hako::utils::sem::asset_up;
using hako::utils::sem::asset_down;
#endif

void hako::core::rpc::HakoInternalRpc::register_callback(hako::data::HakoAssetEventType event_id, void (*callback) ())
{
Expand Down Expand Up @@ -28,7 +35,7 @@ void hako::core::rpc::HakoInternalRpc::stop()
// nothing to do
}
else {
hako::utils::sem::asset_up(this->master_data_->get_semid(), this->asset_id_);
asset_up(this->master_data_->get_semid(), this->asset_id_);
this->proxy_thread_->join();
this->proxy_thread_ = nullptr;
}
Expand All @@ -37,7 +44,7 @@ void hako::core::rpc::HakoInternalRpc::proxy_thread()
{
//hako::utils::logger::get("core")->info("HakoInternalRpc: monitor_thread start: asset[{0}]", this->asset_id_);
while (true) {
hako::utils::sem::asset_down(this->master_data_->get_semid(), this->asset_id_);
asset_down(this->master_data_->get_semid(), this->asset_id_);
auto* asset = this->master_data_->get_asset_event_nolock(this->asset_id_);
if (asset == nullptr) {
break;
Expand All @@ -61,7 +68,7 @@ void hako::core::rpc::notify(std::shared_ptr<data::HakoMasterData> master_data,
return;
}
if (!context.is_same(asset_ev->pid)) {
hako::utils::sem::asset_up(master_data->get_semid(), asset_id);
asset_up(master_data->get_semid(), asset_id);
return;
}
switch (event_id) {
Expand Down
4 changes: 4 additions & 0 deletions src/hako/data/hako_master_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
#include "utils/hako_string.hpp"
#include "utils/hako_assert.hpp"
#include "utils/hako_clock.hpp"
#ifdef WIN32
#include "utils/hako_share/hako_sem_flock.hpp"
#else
#include "utils/hako_share/hako_sem.hpp"
#endif
#include "core/context/hako_context.hpp"
#include "data/hako_pdu_data.hpp"
#include <string.h>
Expand Down
1 change: 1 addition & 0 deletions src/hako/utils/hako_assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _HAKO_ASSERT_HPP_

#include "types/hako_types.hpp"
#include <cassert>
//#include "utils/hako_logger.hpp"


Expand Down
10 changes: 6 additions & 4 deletions src/hako/utils/hako_share/impl/hako_shared_memory_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

std::shared_ptr<hako::utils::HakoSharedMemory> hako::utils::hako_shared_memory_create(const std::string& type)
{
if (type == "shm") {
return std::make_shared<hako::utils::HakoSharedMemoryShm>();
}
else if (type == "mmap") {
if (type == "mmap") {
return std::make_shared<hako::utils::HakoSharedMemoryMmap>();
}
#ifndef WIN32
else if (type == "shm") {
return std::make_shared<hako::utils::HakoSharedMemoryShm>();
}
#endif
else
{
return nullptr;
Expand Down

0 comments on commit e48d579

Please sign in to comment.