diff --git a/CMakeLists.txt b/CMakeLists.txt index f69308a..41e39bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) -project(CCLite VERSION 0.1.1 LANGUAGES Fortran) +project(CCLite VERSION 0.1.2 LANGUAGES C Fortran) set(CMAKE_Fortran_STANDARD 2018) set(CMAKE_Fortran_STANDARD_REQUIRED ON) @@ -18,6 +18,14 @@ set(CCL_COMMON_SOURCES add_library(ccl_common STATIC ${CCL_COMMON_SOURCES}) +add_library(ccl_ipc STATIC + src/ipc/ccl_ipc_names.f90 + src/ipc/ccl_ipc.f90 + src/ipc/cclite_ipc_win.c +) +target_include_directories(ccl_ipc PUBLIC include) +target_link_libraries(ccl_ipc PRIVATE ccl_common) + add_executable(cclite src/app/cclite_main.f90 ) @@ -38,6 +46,11 @@ add_executable(mock_fem_worker ) target_link_libraries(mock_fem_worker PRIVATE ccl_mock_common ccl_common) +add_executable(test_ipc_lifecycle + tests/interface/test_ipc_lifecycle.f90 +) +target_link_libraries(test_ipc_lifecycle PRIVATE ccl_ipc ccl_common) + add_test(NAME smoke_cclite_version COMMAND cclite --version) add_test(NAME smoke_cclite_help COMMAND cclite --help) add_test(NAME smoke_mock_sph_worker_version COMMAND mock_sph_worker --version) @@ -56,3 +69,5 @@ add_test(NAME check_invalid_ipc_type COMMAND cclite check ${CMAKE_SOURCE_DIR}/tests/data/v010_invalid_ipc.inp ) set_tests_properties(check_invalid_ipc_type PROPERTIES WILL_FAIL TRUE) + +add_test(NAME ipc_lifecycle COMMAND test_ipc_lifecycle) diff --git a/include/cclite_ipc.h b/include/cclite_ipc.h new file mode 100644 index 0000000..2f7a596 --- /dev/null +++ b/include/cclite_ipc.h @@ -0,0 +1,33 @@ +#ifndef CCLITE_IPC_H +#define CCLITE_IPC_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define CCL_IPC_SUCCESS 0 +#define CCL_IPC_CREATE_FAILED 2001 +#define CCL_IPC_OPEN_FAILED 2002 +#define CCL_IPC_MAP_FAILED 2003 +#define CCL_IPC_TIMEOUT 2004 +#define CCL_IPC_BAD_HANDLE 2005 +#define CCL_IPC_UNSUPPORTED 9001 + +int ccl_ipc_shm_create(const char *name, size_t byte_size, void **out_handle, void **out_payload); +int ccl_ipc_shm_open(const char *name, size_t byte_size, void **out_handle, void **out_payload); +int ccl_ipc_shm_close(void *handle); + +int ccl_ipc_event_create(const char *name, int initial_state, void **out_handle); +int ccl_ipc_event_open(const char *name, void **out_handle); +int ccl_ipc_event_wait(void *handle, int timeout_ms); +int ccl_ipc_event_signal(void *handle); +int ccl_ipc_event_reset(void *handle); +int ccl_ipc_event_close(void *handle); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/common/ccl_errors.f90 b/src/common/ccl_errors.f90 index aea36dd..4347bd2 100644 --- a/src/common/ccl_errors.f90 +++ b/src/common/ccl_errors.f90 @@ -13,7 +13,8 @@ module ccl_errors integer, parameter :: CCL_ERROR_IPC_OPEN_FAILED = CCL_ERROR_IPC_BASE + 2 integer, parameter :: CCL_ERROR_IPC_MAP_FAILED = CCL_ERROR_IPC_BASE + 3 integer, parameter :: CCL_ERROR_IPC_TIMEOUT = CCL_ERROR_IPC_BASE + 4 - integer, parameter :: CCL_ERROR_IPC_BAD_HEADER = CCL_ERROR_IPC_BASE + 5 + integer, parameter :: CCL_ERROR_IPC_BAD_HANDLE = CCL_ERROR_IPC_BASE + 5 + integer, parameter :: CCL_ERROR_IPC_BAD_HEADER = CCL_ERROR_IPC_BASE + 6 integer, parameter :: CCL_ERROR_WORKER_BASE = 3000 integer, parameter :: CCL_ERROR_WORKER_START_FAILED = CCL_ERROR_WORKER_BASE + 1 diff --git a/src/common/ccl_version.f90 b/src/common/ccl_version.f90 index 4cb1022..a1278ff 100644 --- a/src/common/ccl_version.f90 +++ b/src/common/ccl_version.f90 @@ -3,8 +3,8 @@ module ccl_version integer, parameter :: CCL_VERSION_MAJOR = 0 integer, parameter :: CCL_VERSION_MINOR = 1 - integer, parameter :: CCL_VERSION_PATCH = 1 - character(len=*), parameter :: CCL_VERSION_LABEL = "0.1.1" + integer, parameter :: CCL_VERSION_PATCH = 2 + character(len=*), parameter :: CCL_VERSION_LABEL = "0.1.2" contains diff --git a/src/ipc/ccl_ipc.f90 b/src/ipc/ccl_ipc.f90 new file mode 100644 index 0000000..729d503 --- /dev/null +++ b/src/ipc/ccl_ipc.f90 @@ -0,0 +1,187 @@ +module ccl_ipc + use iso_c_binding, only: c_char, c_int, c_ptr, c_size_t, c_associated, c_null_char, c_null_ptr + implicit none + + type :: CCL_Shared_Memory + type(c_ptr) :: native = c_null_ptr + type(c_ptr) :: payload = c_null_ptr + integer(c_size_t) :: byte_size = 0_c_size_t + end type CCL_Shared_Memory + + type :: CCL_Named_Event + type(c_ptr) :: native = c_null_ptr + end type CCL_Named_Event + + interface + integer(c_int) function ccl_ipc_shm_create_c(name, byte_size, out_handle, out_payload) & + bind(C, name="ccl_ipc_shm_create") + import :: c_char, c_int, c_ptr, c_size_t + character(kind=c_char), intent(in) :: name(*) + integer(c_size_t), value :: byte_size + type(c_ptr), intent(out) :: out_handle + type(c_ptr), intent(out) :: out_payload + end function ccl_ipc_shm_create_c + + integer(c_int) function ccl_ipc_shm_open_c(name, byte_size, out_handle, out_payload) & + bind(C, name="ccl_ipc_shm_open") + import :: c_char, c_int, c_ptr, c_size_t + character(kind=c_char), intent(in) :: name(*) + integer(c_size_t), value :: byte_size + type(c_ptr), intent(out) :: out_handle + type(c_ptr), intent(out) :: out_payload + end function ccl_ipc_shm_open_c + + integer(c_int) function ccl_ipc_shm_close_c(handle) bind(C, name="ccl_ipc_shm_close") + import :: c_int, c_ptr + type(c_ptr), value :: handle + end function ccl_ipc_shm_close_c + + integer(c_int) function ccl_ipc_event_create_c(name, initial_state, out_handle) & + bind(C, name="ccl_ipc_event_create") + import :: c_char, c_int, c_ptr + character(kind=c_char), intent(in) :: name(*) + integer(c_int), value :: initial_state + type(c_ptr), intent(out) :: out_handle + end function ccl_ipc_event_create_c + + integer(c_int) function ccl_ipc_event_open_c(name, out_handle) bind(C, name="ccl_ipc_event_open") + import :: c_char, c_int, c_ptr + character(kind=c_char), intent(in) :: name(*) + type(c_ptr), intent(out) :: out_handle + end function ccl_ipc_event_open_c + + integer(c_int) function ccl_ipc_event_wait_c(handle, timeout_ms) bind(C, name="ccl_ipc_event_wait") + import :: c_int, c_ptr + type(c_ptr), value :: handle + integer(c_int), value :: timeout_ms + end function ccl_ipc_event_wait_c + + integer(c_int) function ccl_ipc_event_signal_c(handle) bind(C, name="ccl_ipc_event_signal") + import :: c_int, c_ptr + type(c_ptr), value :: handle + end function ccl_ipc_event_signal_c + + integer(c_int) function ccl_ipc_event_reset_c(handle) bind(C, name="ccl_ipc_event_reset") + import :: c_int, c_ptr + type(c_ptr), value :: handle + end function ccl_ipc_event_reset_c + + integer(c_int) function ccl_ipc_event_close_c(handle) bind(C, name="ccl_ipc_event_close") + import :: c_int, c_ptr + type(c_ptr), value :: handle + end function ccl_ipc_event_close_c + end interface + +contains + + subroutine ccl_shm_create(name, byte_size, shm, ierr) + character(len=*), intent(in) :: name + integer(c_size_t), intent(in) :: byte_size + type(CCL_Shared_Memory), intent(out) :: shm + integer, intent(out) :: ierr + character(kind=c_char), allocatable :: c_name(:) + + call make_c_string(name, c_name) + ierr = ccl_ipc_shm_create_c(c_name, byte_size, shm%native, shm%payload) + if (ierr == 0) shm%byte_size = byte_size + end subroutine ccl_shm_create + + subroutine ccl_shm_open(name, byte_size, shm, ierr) + character(len=*), intent(in) :: name + integer(c_size_t), intent(in) :: byte_size + type(CCL_Shared_Memory), intent(out) :: shm + integer, intent(out) :: ierr + character(kind=c_char), allocatable :: c_name(:) + + call make_c_string(name, c_name) + ierr = ccl_ipc_shm_open_c(c_name, byte_size, shm%native, shm%payload) + if (ierr == 0) shm%byte_size = byte_size + end subroutine ccl_shm_open + + subroutine ccl_shm_close(shm, ierr) + type(CCL_Shared_Memory), intent(inout) :: shm + integer, intent(out) :: ierr + + if (.not. c_associated(shm%native)) then + ierr = 0 + return + end if + ierr = ccl_ipc_shm_close_c(shm%native) + shm%native = c_null_ptr + shm%payload = c_null_ptr + shm%byte_size = 0_c_size_t + end subroutine ccl_shm_close + + subroutine ccl_event_create(name, initial_state, event, ierr) + character(len=*), intent(in) :: name + logical, intent(in) :: initial_state + type(CCL_Named_Event), intent(out) :: event + integer, intent(out) :: ierr + character(kind=c_char), allocatable :: c_name(:) + integer(c_int) :: c_initial + + call make_c_string(name, c_name) + c_initial = 0_c_int + if (initial_state) c_initial = 1_c_int + ierr = ccl_ipc_event_create_c(c_name, c_initial, event%native) + end subroutine ccl_event_create + + subroutine ccl_event_open(name, event, ierr) + character(len=*), intent(in) :: name + type(CCL_Named_Event), intent(out) :: event + integer, intent(out) :: ierr + character(kind=c_char), allocatable :: c_name(:) + + call make_c_string(name, c_name) + ierr = ccl_ipc_event_open_c(c_name, event%native) + end subroutine ccl_event_open + + subroutine ccl_event_wait(event, timeout_ms, ierr) + type(CCL_Named_Event), intent(in) :: event + integer, intent(in) :: timeout_ms + integer, intent(out) :: ierr + + ierr = ccl_ipc_event_wait_c(event%native, int(timeout_ms, c_int)) + end subroutine ccl_event_wait + + subroutine ccl_event_signal(event, ierr) + type(CCL_Named_Event), intent(in) :: event + integer, intent(out) :: ierr + + ierr = ccl_ipc_event_signal_c(event%native) + end subroutine ccl_event_signal + + subroutine ccl_event_reset(event, ierr) + type(CCL_Named_Event), intent(in) :: event + integer, intent(out) :: ierr + + ierr = ccl_ipc_event_reset_c(event%native) + end subroutine ccl_event_reset + + subroutine ccl_event_close(event, ierr) + type(CCL_Named_Event), intent(inout) :: event + integer, intent(out) :: ierr + + if (.not. c_associated(event%native)) then + ierr = 0 + return + end if + ierr = ccl_ipc_event_close_c(event%native) + event%native = c_null_ptr + end subroutine ccl_event_close + + subroutine make_c_string(text, c_text) + character(len=*), intent(in) :: text + character(kind=c_char), allocatable, intent(out) :: c_text(:) + integer :: i + integer :: n + + n = len_trim(text) + allocate(c_text(n + 1)) + do i = 1, n + c_text(i) = text(i:i) + end do + c_text(n + 1) = c_null_char + end subroutine make_c_string + +end module ccl_ipc diff --git a/src/ipc/ccl_ipc_names.f90 b/src/ipc/ccl_ipc_names.f90 new file mode 100644 index 0000000..f3a3087 --- /dev/null +++ b/src/ipc/ccl_ipc_names.f90 @@ -0,0 +1,19 @@ +module ccl_ipc_names + implicit none + +contains + + subroutine ccl_ipc_make_name(prefix, role, solver_id, name) + character(len=*), intent(in) :: prefix + character(len=*), intent(in) :: role + character(len=*), intent(in) :: solver_id + character(len=*), intent(out) :: name + + if (len_trim(solver_id) > 0) then + write(name, '(a,"_",a,"_",a)') trim(prefix), trim(role), trim(solver_id) + else + write(name, '(a,"_",a)') trim(prefix), trim(role) + end if + end subroutine ccl_ipc_make_name + +end module ccl_ipc_names diff --git a/src/ipc/cclite_ipc_win.c b/src/ipc/cclite_ipc_win.c new file mode 100644 index 0000000..5428f70 --- /dev/null +++ b/src/ipc/cclite_ipc_win.c @@ -0,0 +1,272 @@ +#include "cclite_ipc.h" + +#include + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include + +typedef struct CCL_SharedMemoryHandle { + HANDLE mapping; + void *view; + size_t byte_size; +} CCL_SharedMemoryHandle; + +typedef struct CCL_EventHandle { + HANDLE event; +} CCL_EventHandle; + +static int map_shared_memory(HANDLE mapping, size_t byte_size, void **out_handle, void **out_payload) +{ + CCL_SharedMemoryHandle *handle = NULL; + void *view = NULL; + + if (mapping == NULL || out_handle == NULL || out_payload == NULL || byte_size == 0) { + return CCL_IPC_BAD_HANDLE; + } + + view = MapViewOfFile(mapping, FILE_MAP_ALL_ACCESS, 0, 0, byte_size); + if (view == NULL) { + CloseHandle(mapping); + return CCL_IPC_MAP_FAILED; + } + + handle = (CCL_SharedMemoryHandle *)calloc(1, sizeof(CCL_SharedMemoryHandle)); + if (handle == NULL) { + UnmapViewOfFile(view); + CloseHandle(mapping); + return CCL_IPC_CREATE_FAILED; + } + + handle->mapping = mapping; + handle->view = view; + handle->byte_size = byte_size; + *out_handle = handle; + *out_payload = view; + return CCL_IPC_SUCCESS; +} + +int ccl_ipc_shm_create(const char *name, size_t byte_size, void **out_handle, void **out_payload) +{ + HANDLE mapping = NULL; + DWORD size_low = 0; + DWORD size_high = 0; + + if (name == NULL || out_handle == NULL || out_payload == NULL || byte_size == 0) { + return CCL_IPC_BAD_HANDLE; + } + + size_low = (DWORD)(byte_size & 0xffffffffu); + size_high = (DWORD)((byte_size >> 32) & 0xffffffffu); + mapping = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, size_high, size_low, name); + if (mapping == NULL) { + return CCL_IPC_CREATE_FAILED; + } + + return map_shared_memory(mapping, byte_size, out_handle, out_payload); +} + +int ccl_ipc_shm_open(const char *name, size_t byte_size, void **out_handle, void **out_payload) +{ + HANDLE mapping = NULL; + + if (name == NULL || out_handle == NULL || out_payload == NULL || byte_size == 0) { + return CCL_IPC_BAD_HANDLE; + } + + mapping = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, name); + if (mapping == NULL) { + return CCL_IPC_OPEN_FAILED; + } + + return map_shared_memory(mapping, byte_size, out_handle, out_payload); +} + +int ccl_ipc_shm_close(void *raw_handle) +{ + CCL_SharedMemoryHandle *handle = (CCL_SharedMemoryHandle *)raw_handle; + + if (handle == NULL) { + return CCL_IPC_SUCCESS; + } + + if (handle->view != NULL) { + UnmapViewOfFile(handle->view); + } + if (handle->mapping != NULL) { + CloseHandle(handle->mapping); + } + free(handle); + return CCL_IPC_SUCCESS; +} + +int ccl_ipc_event_create(const char *name, int initial_state, void **out_handle) +{ + CCL_EventHandle *handle = NULL; + HANDLE event = NULL; + + if (name == NULL || out_handle == NULL) { + return CCL_IPC_BAD_HANDLE; + } + + event = CreateEventA(NULL, TRUE, initial_state ? TRUE : FALSE, name); + if (event == NULL) { + return CCL_IPC_CREATE_FAILED; + } + + handle = (CCL_EventHandle *)calloc(1, sizeof(CCL_EventHandle)); + if (handle == NULL) { + CloseHandle(event); + return CCL_IPC_CREATE_FAILED; + } + + handle->event = event; + *out_handle = handle; + return CCL_IPC_SUCCESS; +} + +int ccl_ipc_event_open(const char *name, void **out_handle) +{ + CCL_EventHandle *handle = NULL; + HANDLE event = NULL; + + if (name == NULL || out_handle == NULL) { + return CCL_IPC_BAD_HANDLE; + } + + event = OpenEventA(EVENT_MODIFY_STATE | SYNCHRONIZE, FALSE, name); + if (event == NULL) { + return CCL_IPC_OPEN_FAILED; + } + + handle = (CCL_EventHandle *)calloc(1, sizeof(CCL_EventHandle)); + if (handle == NULL) { + CloseHandle(event); + return CCL_IPC_CREATE_FAILED; + } + + handle->event = event; + *out_handle = handle; + return CCL_IPC_SUCCESS; +} + +int ccl_ipc_event_wait(void *raw_handle, int timeout_ms) +{ + CCL_EventHandle *handle = (CCL_EventHandle *)raw_handle; + DWORD result = 0; + + if (handle == NULL || handle->event == NULL) { + return CCL_IPC_BAD_HANDLE; + } + + result = WaitForSingleObject(handle->event, (DWORD)timeout_ms); + if (result == WAIT_OBJECT_0) { + return CCL_IPC_SUCCESS; + } + if (result == WAIT_TIMEOUT) { + return CCL_IPC_TIMEOUT; + } + return CCL_IPC_BAD_HANDLE; +} + +int ccl_ipc_event_signal(void *raw_handle) +{ + CCL_EventHandle *handle = (CCL_EventHandle *)raw_handle; + + if (handle == NULL || handle->event == NULL) { + return CCL_IPC_BAD_HANDLE; + } + return SetEvent(handle->event) ? CCL_IPC_SUCCESS : CCL_IPC_BAD_HANDLE; +} + +int ccl_ipc_event_reset(void *raw_handle) +{ + CCL_EventHandle *handle = (CCL_EventHandle *)raw_handle; + + if (handle == NULL || handle->event == NULL) { + return CCL_IPC_BAD_HANDLE; + } + return ResetEvent(handle->event) ? CCL_IPC_SUCCESS : CCL_IPC_BAD_HANDLE; +} + +int ccl_ipc_event_close(void *raw_handle) +{ + CCL_EventHandle *handle = (CCL_EventHandle *)raw_handle; + + if (handle == NULL) { + return CCL_IPC_SUCCESS; + } + if (handle->event != NULL) { + CloseHandle(handle->event); + } + free(handle); + return CCL_IPC_SUCCESS; +} + +#else + +int ccl_ipc_shm_create(const char *name, size_t byte_size, void **out_handle, void **out_payload) +{ + (void)name; + (void)byte_size; + (void)out_handle; + (void)out_payload; + return CCL_IPC_UNSUPPORTED; +} + +int ccl_ipc_shm_open(const char *name, size_t byte_size, void **out_handle, void **out_payload) +{ + (void)name; + (void)byte_size; + (void)out_handle; + (void)out_payload; + return CCL_IPC_UNSUPPORTED; +} + +int ccl_ipc_shm_close(void *handle) +{ + (void)handle; + return CCL_IPC_SUCCESS; +} + +int ccl_ipc_event_create(const char *name, int initial_state, void **out_handle) +{ + (void)name; + (void)initial_state; + (void)out_handle; + return CCL_IPC_UNSUPPORTED; +} + +int ccl_ipc_event_open(const char *name, void **out_handle) +{ + (void)name; + (void)out_handle; + return CCL_IPC_UNSUPPORTED; +} + +int ccl_ipc_event_wait(void *handle, int timeout_ms) +{ + (void)handle; + (void)timeout_ms; + return CCL_IPC_UNSUPPORTED; +} + +int ccl_ipc_event_signal(void *handle) +{ + (void)handle; + return CCL_IPC_UNSUPPORTED; +} + +int ccl_ipc_event_reset(void *handle) +{ + (void)handle; + return CCL_IPC_UNSUPPORTED; +} + +int ccl_ipc_event_close(void *handle) +{ + (void)handle; + return CCL_IPC_SUCCESS; +} + +#endif diff --git a/tests/interface/test_ipc_lifecycle.f90 b/tests/interface/test_ipc_lifecycle.f90 new file mode 100644 index 0000000..477daf5 --- /dev/null +++ b/tests/interface/test_ipc_lifecycle.f90 @@ -0,0 +1,80 @@ +program test_ipc_lifecycle + use iso_c_binding, only: c_f_pointer, c_int, c_size_t + use ccl_errors, only: CCL_SUCCESS, CCL_ERROR_IPC_TIMEOUT + use ccl_ipc, only: CCL_Named_Event, CCL_Shared_Memory, ccl_event_close, & + ccl_event_create, ccl_event_reset, ccl_event_signal, ccl_event_wait, & + ccl_shm_close, ccl_shm_create, ccl_shm_open + use ccl_ipc_names, only: ccl_ipc_make_name + implicit none + + integer :: ierr + type(CCL_Shared_Memory) :: owner_shm + type(CCL_Shared_Memory) :: peer_shm + type(CCL_Named_Event) :: event + character(len=128) :: shm_name + character(len=128) :: event_name + integer(c_int), pointer :: owner_values(:) + integer(c_int), pointer :: peer_values(:) + integer(c_size_t), parameter :: shm_bytes = 16_c_size_t + + call ccl_ipc_make_name("CCLITE_TEST_012", "SHM", "SPH", shm_name) + call ccl_ipc_make_name("CCLITE_TEST_012", "EVENT", "SPH", event_name) + + call ccl_shm_create(trim(shm_name), shm_bytes, owner_shm, ierr) + call require_success(ierr, "create shared memory") + call c_f_pointer(owner_shm%payload, owner_values, [4]) + owner_values = [1_c_int, 2_c_int, 3_c_int, 4_c_int] + + call ccl_shm_open(trim(shm_name), shm_bytes, peer_shm, ierr) + call require_success(ierr, "open shared memory") + call c_f_pointer(peer_shm%payload, peer_values, [4]) + if (any(peer_values /= owner_values)) then + call fail("shared memory payload mismatch") + end if + + call ccl_event_create(trim(event_name), .false., event, ierr) + call require_success(ierr, "create event") + call ccl_event_wait(event, 1, ierr) + if (ierr /= CCL_ERROR_IPC_TIMEOUT) then + call fail("unsignaled event should time out") + end if + + call ccl_event_signal(event, ierr) + call require_success(ierr, "signal event") + call ccl_event_wait(event, 1000, ierr) + call require_success(ierr, "wait signaled event") + + call ccl_event_reset(event, ierr) + call require_success(ierr, "reset event") + call ccl_event_wait(event, 1, ierr) + if (ierr /= CCL_ERROR_IPC_TIMEOUT) then + call fail("reset event should time out") + end if + + call ccl_event_close(event, ierr) + call require_success(ierr, "close event") + call ccl_shm_close(peer_shm, ierr) + call require_success(ierr, "close peer shared memory") + call ccl_shm_close(owner_shm, ierr) + call require_success(ierr, "close owner shared memory") + +contains + + subroutine require_success(ierr, what) + integer, intent(in) :: ierr + character(len=*), intent(in) :: what + + if (ierr /= CCL_SUCCESS) then + print '(a,i0)', trim(what) // " failed with ierr=", ierr + stop 1 + end if + end subroutine require_success + + subroutine fail(message) + character(len=*), intent(in) :: message + + print '(a)', trim(message) + stop 1 + end subroutine fail + +end program test_ipc_lifecycle diff --git a/todo.md b/todo.md index e37d40b..6264450 100644 --- a/todo.md +++ b/todo.md @@ -92,31 +92,31 @@ 目标:完成 Windows shared memory 和 named event 最小可用层。 -- [ ] T0121 定义 C IPC 薄层头文件。 +- [x] T0121 定义 C IPC 薄层头文件。 完成判据:声明 shared memory、event、error 和 handle 基础接口。 -- [ ] T0122 实现 shared memory create/open/map。 +- [x] T0122 实现 shared memory create/open/map。 完成判据:可创建命名共享内存并取得 payload 指针。 -- [ ] T0123 实现 shared memory unmap/close。 +- [x] T0123 实现 shared memory unmap/close。 完成判据:资源释放后同名测试可重复运行。 -- [ ] T0124 实现 named event create/open。 +- [x] T0124 实现 named event create/open。 完成判据:可创建 Windows manual-reset named event。 -- [ ] T0125 实现 named event wait/signal/reset/close。 +- [x] T0125 实现 named event wait/signal/reset/close。 完成判据:wait 支持 timeout,signal/reset 行为可测试。 -- [ ] T0126 建立 Fortran2018 IPC wrapper。 +- [x] T0126 建立 Fortran2018 IPC wrapper。 完成判据:Fortran 侧可调用 C IPC 薄层并取得状态码。 -- [ ] T0127 建立 IPC 资源命名规则。 +- [x] T0127 建立 IPC 资源命名规则。 完成判据:同一 case 的 command block、data block 和 event 名称可稳定生成。 -- [ ] T0128 增加 IPC 错误映射。 +- [x] T0128 增加 IPC 错误映射。 完成判据:create/open/map/wait 失败能转换为 CCLite 错误码。 -- [ ] T0129 增加 IPC 接口测试。 +- [x] T0129 增加 IPC 接口测试。 完成判据:覆盖 shared memory 生命周期、event wait/signal/reset、timeout 和重复释放。 # 5. 0.1.3 Command Block 与 Worker 协议