summaryrefslogtreecommitdiff
path: root/source/tests
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2023-09-15 15:17:24 +0200
committerMitya Selivanov <automainint@guattari.tech>2023-09-15 15:17:24 +0200
commitfb6c9ff7f21e46edf8a7d72cc77769966a3f6a05 (patch)
tree5df26b1b6d478c73c5ebe144fc293cbfe1ec1b83 /source/tests
parent93bf289d04b1f029787f51824fbc42136a8285b0 (diff)
downloadkit-fb6c9ff7f21e46edf8a7d72cc77769966a3f6a05.zip
shared_memory: win32 impl
Diffstat (limited to 'source/tests')
-rw-r--r--source/tests/test_interprocess.c29
1 files changed, 16 insertions, 13 deletions
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 <stdio.h>
-#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