From fb6c9ff7f21e46edf8a7d72cc77769966a3f6a05 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Fri, 15 Sep 2023 15:17:24 +0200 Subject: shared_memory: win32 impl --- source/tests/test_interprocess.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'source/tests/test_interprocess.c') diff --git a/source/tests/test_interprocess.c b/source/tests/test_interprocess.c index 30a8779..fece68f 100644 --- a/source/tests/test_interprocess.c +++ b/source/tests/test_interprocess.c @@ -3,24 +3,20 @@ #include -#ifdef _WIN32 -int main() { - return 0; -} -#else -# define NAME "kit_test_interprocess" +#define NAME "kit_test_interprocess" enum { SIZE = 64 }; enum { STATE_INIT, STATE_READY, STATE_DONE }; int run_writer() { - kit_shared_memory_t mem = kit_shared_memory_create(SZ(NAME), SIZE); + kit_shared_memory_t mem = kit_shared_memory_open( + SZ(NAME), SIZE, KIT_SHARED_MEMORY_CREATE); if (mem.status != KIT_OK) { - printf("%s: kit_shared_memory_create failed.\n", __FUNCTION__); + printf("%s: kit_shared_memory_open failed.\n", __FUNCTION__); fflush(stdout); - return mem.status; + return 1; } mem.bytes[0] = STATE_INIT; @@ -33,12 +29,19 @@ int run_writer() { } int run_reader() { - kit_shared_memory_t mem = kit_shared_memory_open(SZ(NAME), SIZE); + kit_shared_memory_t mem; + for (;;) { + mem = kit_shared_memory_open(SZ(NAME), SIZE, + KIT_SHARED_MEMORY_OPEN); + if (mem.status == KIT_OK) + break; + thrd_yield(); + } if (mem.status != KIT_OK) { printf("%s: kit_shared_memory_open failed.\n", __FUNCTION__); fflush(stdout); - return mem.status; + return 1; } while (mem.bytes[0] != STATE_READY) thrd_yield(); @@ -54,7 +57,8 @@ int run_reader() { mem.bytes[0] = STATE_DONE; - status |= kit_shared_memory_close(&mem); + if (kit_shared_memory_close(&mem) != KIT_OK) + status = 1; return status; } @@ -90,4 +94,3 @@ int main(int argc, char **argv) { printf("Invalid command line argument \"%s\"\n", argv[1]); return 1; } -#endif -- cgit v1.2.3