diff options
author | neal <neal> | 2008-01-15 11:00:22 +0000 |
---|---|---|
committer | neal <neal> | 2008-01-15 11:00:22 +0000 |
commit | 9fbae31db65fbe7f4a36faa56cb6a08585fa4fa2 (patch) | |
tree | b817709b20fee996bb9f4b7a95272bad2f92fccc /ruth | |
parent | 8596032ca1a6ca09c674e37092439d8f977b9041 (diff) |
hurd/
2008-01-15 Neal H. Walfield <neal@gnu.org>
* futex.h (futex_wait): New file.
* Makefile.am (includehurd_HEADERS): Add futex.h.
* headers.m4: Link $(BUILDIR)/include/hurd/futex.h to futex.h.
* RPC: Add futex message id assignment.
* folio.h (struct folio): Add field wait_queue. Remove field
checksum (for now).
viengoos/
2008-01-15 Neal H. Walfield <neal@gnu.org>
* object.h (struct thread): New forward.
(object_wait_queue_head): New declaration.
(object_wait_queue_tail): New declaration.
(object_wait_queue_next): New declaration.
(object_wait_queue_prev): New declaration.
(object_wait_queue_enqueue): New declaration.
(object_wait_queue_dequeue): New declaration.
(object_wait_queue_for_each): New macro.
* object.c (object_wait_queue): New function.
(object_wait_queue_head): Likewise.
(object_wait_queue_tail): Likewise.
(object_wait_queue_next): Likewise.
(object_wait_queue_prev): Likewise.
(object_wait_queue_check): Likewise.
(object_wait_queue_enqueue): Likewise.
(object_wait_queue_dequeue): Likewise.
* thread.h (struct wait_queue_node): New structure.
(struct thread): Add fields wait_queue_head, wait_queue_tail,
futex_block, futex_offset and wait_queue.
* thread.c (thread_deinit): If THREAD is enqueue on a wait queue,
dequeue it.
* rm.h: Include <hurd/futex.h>.
(rm_method_id_string): Handle the RM_futex case.
* server.c: Include <hurd/futex.h>.
(server_loop): Implement the rm_futex method.
ruth/
2008-01-15 Neal H. Walfield <neal@gnu.org>
* ruth.c: Include <hurd/futex.h>.
(main) Test futex implementation.
Diffstat (limited to 'ruth')
-rw-r--r-- | ruth/ChangeLog | 5 | ||||
-rw-r--r-- | ruth/ruth.c | 77 |
2 files changed, 82 insertions, 0 deletions
diff --git a/ruth/ChangeLog b/ruth/ChangeLog index a941b2f..05b5aa9 100644 --- a/ruth/ChangeLog +++ b/ruth/ChangeLog @@ -1,3 +1,8 @@ +2008-01-15 Neal H. Walfield <neal@gnu.org> + + * ruth.c: Include <hurd/futex.h>. + (main) Test futex implementation. + 2008-01-01 Neal H. Walfield <neal@gnu.org> * ruth.c (main): Remove activity_properties test. Replace with diff --git a/ruth/ruth.c b/ruth/ruth.c index c4fcfe1..d79ed1e 100644 --- a/ruth/ruth.c +++ b/ruth/ruth.c @@ -32,6 +32,7 @@ #include <hurd/as.h> #include <hurd/storage.h> #include <hurd/activity.h> +#include <hurd/futex.h> #include <bit-array.h> #include <string.h> @@ -348,6 +349,7 @@ main (int argc, char *argv[]) { printf ("Checking pthread library... "); +#undef N #define N 4 pthread_t threads[N]; @@ -567,6 +569,81 @@ main (int argc, char *argv[]) } { + printf ("Checking futex implementation... "); + +#undef N +#define N 4 +#undef FACTOR +#define FACTOR 10 + pthread_t threads[N]; + + int futex1 = 0; + int futex2 = 1; + + void *start (void *arg) + { + int i; + + for (i = 0; i < FACTOR; i ++) + { + long ret = futex_wait (&futex1, 0); + assert (ret == 0); + + ret = futex_wait (&futex2, 1); + assert (ret == 0); + } + + return arg; + } + + int i; + for (i = 0; i < N; i ++) + { + debug (5, "Creating thread %d", i); + error_t err = pthread_create (&threads[i], NULL, start, + (void *) (uintptr_t) i); + assert (err == 0); + } + + for (i = 0; i < FACTOR; i ++) + { + int count = 0; + while (count < N) + { + long ret = futex_wake (&futex1, 1); + count += ret; + + ret = futex_wake (&futex1, N); + count += ret; + } + assert (count == N); + + count = 0; + while (count < N) + { + long ret = futex_wake (&futex2, 1); + count += ret; + + ret = futex_wake (&futex2, N); + count += ret; + } + assert (count == N); + } + + for (i = 0; i < N; i ++) + { + void *status = (void *) 1; + debug (5, "Waiting on thread %d", i); + error_t err = pthread_join (threads[i], &status); + assert (err == 0); + assert ((uintptr_t) status == (uintptr_t) i); + debug (5, "Joined %d", i); + } + + printf ("ok.\n"); + } + + { addr_t addr = as_alloc (PAGESIZE_LOG2, 1, true); assert (! ADDR_IS_VOID (addr)); |