Skip to content

Commit

Permalink
fix #28
Browse files Browse the repository at this point in the history
  • Loading branch information
tmori committed Feb 21, 2024
1 parent 92cad67 commit 1f1ad7f
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 17 deletions.
15 changes: 13 additions & 2 deletions default-cmake-options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,21 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wimplicit-int")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")

if (MSVC)
add_compile_options(/wd4061 /wd4819)
add_compile_options(/wd4477 /wd4244 /wd4245)
add_compile_options(/wd4820 /wd4365)
add_compile_options(/wd4267)
add_compile_options(/wd4623 /wd4625 /wd4626 /wd5027 /wd5045) #nlohmann::json
add_compile_options(/wd4668)
add_compile_options(/wd4996)
add_compile_options(/wd5039)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-long-long")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")

endif()

set(BUILD_TYPE "release")
if (debug)
Expand Down
5 changes: 4 additions & 1 deletion sample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ project(hakoniwa-core

add_subdirectory(base-procs/hako-master)
add_subdirectory(base-procs/hako-asset)
add_subdirectory(base-procs/hako-cmd)
if(MSVC)
else()
add_subdirectory(base-procs/hako-cmd)
endif()
7 changes: 7 additions & 0 deletions sample/base-procs/hako-asset/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ add_executable(
src/hako_asset.cpp
)

if(MSVC)
target_link_libraries(
hako-asset
hako
)
else()
target_link_libraries(
hako-asset
hako
-pthread
)
endif()

#message(STATUS "HAKO_INTERFACE_DIR=" ${HAKO_INTERFACE_DIR})

Expand Down
4 changes: 4 additions & 0 deletions sample/base-procs/hako-asset/src/hako_asset.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include <hako.hpp>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#if WIN32
#else
#include <unistd.h>
#endif
#include <signal.h>
#include <iostream>
#include <string.h>
Expand Down
9 changes: 8 additions & 1 deletion sample/base-procs/hako-master/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ add_executable(
hako-master
src/hako_master.cpp
)

if(MSVC)
target_link_libraries(
hako-master
hako
)
else()
target_link_libraries(
hako-master
hako
-pthread
)
endif()


#message(STATUS "HAKO_INTERFACE_DIR=" ${HAKO_INTERFACE_DIR})

Expand Down
4 changes: 4 additions & 0 deletions sample/base-procs/hako-master/src/hako_master.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include <hako.hpp>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#if WIN32
#else
#include <unistd.h>
#endif
#include <signal.h>

static bool hako_master_is_end = false;
Expand Down
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ target_include_directories(
PRIVATE ${PROJECT_SOURCE_DIR}/hako
PRIVATE ${nlohmann_json_SOURCE_DIR}/single_include
)
if(WIN32)
if (MSVC)
elseif(WIN32)
target_link_libraries(hako stdc++)
else()
endif()
10 changes: 7 additions & 3 deletions src/hako/core/context/hako_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ namespace hako::core::context {
public:
HakoContext()
{
#ifdef _WIN32
this->pid_ = GetCurrentProcessId();
#else
this->pid_ = getpid();
#endif
}

pid_t get_pid()
pid_type get_pid()
{
return this->pid_;
}
Expand All @@ -20,15 +24,15 @@ namespace hako::core::context {
{
return (context.get_pid() == this->get_pid());
}
bool is_same(pid_t pid)
bool is_same(pid_type pid)
{
return (this->get_pid() == pid);
}

virtual ~HakoContext() {}

private:
pid_t pid_;
pid_type pid_;
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/hako/data/hako_base_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace hako::data {
} HakoAssetEventType;

typedef struct {
pid_t pid;
pid_type pid;
HakoTimeType ctime; /* usec: for asset simulation time */
HakoTimeType update_time; /* usec: for heartbeat check */
HakoAssetEventType event;
Expand Down
6 changes: 3 additions & 3 deletions src/hako/data/hako_master_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace hako::data {

typedef struct {
pid_t master_pid;
pid_type master_pid;
HakoSimulationStateType state;
HakoTimeSetType time_usec;
uint32_t asset_num;
Expand Down Expand Up @@ -68,7 +68,7 @@ namespace hako::data {
this->shmp_->unlock_memory(HAKO_SHARED_MEMORY_ID_0);
this->pdu_datap_ = std::make_shared<HakoPduData>(&this->master_datap_->pdu_meta_data, this->shmp_, this->get_shm_type());
}
pid_t get_master_pid()
pid_type get_master_pid()
{
return this->master_datap_->master_pid;
}
Expand Down Expand Up @@ -216,7 +216,7 @@ namespace hako::data {
{
HakoAssetIdType id = -1;
hako::core::context::HakoContext context;
pid_t pid = context.get_pid();
pid_type pid = context.get_pid();
for (int i = 0; i < HAKO_DATA_MAX_ASSET_NUM; i++) {
if (this->master_datap_->assets[i].type != HakoAsset_Unknown) {
if (this->master_datap_->assets_ev[i].pid == pid) {
Expand Down
10 changes: 9 additions & 1 deletion src/hako/utils/hako_clock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@

static inline HakoTimeType hako_get_clock()
{
#ifdef _WIN32
LARGE_INTEGER frequency, time;
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&time);
return (time.QuadPart * 1000000) / frequency.QuadPart;
#else
struct timespec tp;
clock_gettime(CLOCK_REALTIME, &tp);
return ( (tp.tv_sec * 1000 * 1000) + (tp.tv_nsec / 1000) );
return (tp.tv_sec * 1000000) + (tp.tv_nsec / 1000);
#endif
}

static inline bool hako_clock_is_timeout(HakoTimeType check_time, HakoTimeType timeout)
{
HakoTimeType ctime = hako_get_clock();
Expand Down
4 changes: 4 additions & 0 deletions src/hako/utils/hako_share/impl/hako_sem_flock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
//#include "utils/hako_logger.hpp"
#include "utils/hako_assert.hpp"
#include <stdlib.h>
#if WIN32
#else
#include <unistd.h>
#endif


#define HAKO_SEM_INX_MASTER 0
#define HAKO_SEM_INX_ASSETS 1
Expand Down
13 changes: 11 additions & 2 deletions src/hako/utils/hako_share/impl/win/os_file_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,17 @@ int win_create_rw(const char* filepath, WinHandleType *whp)

void* win_mmap(WinHandleType *whp)
{
if (whp == NULL) {
return NULL;
}
whp->map_handle = CreateFileMapping(whp->handle, 0, PAGE_READWRITE, 0, 0, 0);
if (whp->map_handle == NULL) {
return NULL;
}
whp->mmap_addr = MapViewOfFile(whp->map_handle, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
if (whp->mmap_addr == NULL) {
return NULL;
}
return whp->mmap_addr;
}

Expand Down Expand Up @@ -113,7 +122,7 @@ int win_pwrite(WinHandleType *whp, const void* buf, size_t count, off_t offset)
if (ret == FALSE) {
DWORD err = GetLastError();
printf("win_pwrite error:%ld\n", err);
return -err;
return - (int)err;
}
return 0;
}
Expand All @@ -125,7 +134,7 @@ int win_pread(WinHandleType *whp, void* buf, size_t count, off_t offset)
if (ret == FALSE) {
DWORD err = GetLastError();
printf("win_pwrite error:%ld\n", err);
return -err;
return -(int)err;
}
return 0;
}
9 changes: 7 additions & 2 deletions src/include/types/hako_osdeps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@
#include <sys/mman.h>
#include <fcntl.h>
#include <sys/file.h>

typedef pid_t pid_type;
#else

#include "windows.h"

#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
typedef DWORD pid_type;
static inline void usleep(long microseconds) {
Sleep(microseconds / 1000);
}
#endif /* OS_TYPE */

#endif /* _HAKO_OSDEPS_HPP_ */

0 comments on commit 1f1ad7f

Please sign in to comment.