btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / tests / system / kernel / port_wakeup_test_2.cpp
blob1ab7260b8141dde785beb105f5c8681dbc879c13
1 /*
2 * Copyright 2006, Marcus Overhagen, <marcus@overhagen.de>
3 * Distributed under the terms of the MIT License.
4 */
7 #include <OS.h>
8 #include <stdio.h>
9 #include <string.h>
16 port_id id;
17 char data[100];
19 int32
20 test_thread(void *)
22 ssize_t size;
23 int32 code;
25 // BeBook: does block when port is empty, and unblocks when port is written to or deleted
26 printf("read port...\n");
27 size = read_port(id, &code, data, sizeof(data));
28 printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size));
30 return 0;
34 int
35 main()
37 status_t s;
38 ssize_t size;
39 int32 code;
41 id = create_port(1, "test port");
42 printf("created port %ld\n", id);
44 s = write_port(id, 0x1234, data, 10);
45 printf("write port result 0x%08lx (%s)\n", s, strerror(s));
47 size = read_port(id, &code, data, sizeof(data));
48 printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size));
50 printf("read should block for 5 seconds now, as port is empty\n");
52 thread_id thread = spawn_thread(test_thread, "test thread", B_NORMAL_PRIORITY, NULL);
53 resume_thread(thread);
54 snooze(5000000);
56 printf("write port...\n");
57 s = write_port(id, 0x5678, data, 20);
58 printf("write port result 0x%08lx (%s)\n", s, strerror(s));
60 printf("waiting for thread to terminate\n");
61 wait_for_thread(thread, &s);
63 return 0;