Rev 2787 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2787 | Rev 4377 | ||
---|---|---|---|
Line 32... | Line 32... | ||
32 | #include <print.h> |
32 | #include <print.h> |
33 | #include <proc/thread.h> |
33 | #include <proc/thread.h> |
34 | 34 | ||
35 | #include <synch/rwlock.h> |
35 | #include <synch/rwlock.h> |
36 | 36 | ||
37 | #define READERS 50 |
37 | #define READERS 50 |
38 | #define WRITERS 50 |
38 | #define WRITERS 50 |
39 | 39 | ||
40 | static rwlock_t rwlock; |
40 | static rwlock_t rwlock; |
41 | static bool sh_quiet; |
- | |
42 | 41 | ||
43 | static void writer(void *arg) |
42 | static void writer(void *arg) |
44 | { |
43 | { |
45 | if (!sh_quiet) |
- | |
46 | printf("Trying to lock rwlock for writing....\n"); |
44 | TPRINTF("Trying to lock rwlock for writing....\n"); |
47 | 45 | ||
48 | rwlock_write_lock(&rwlock); |
46 | rwlock_write_lock(&rwlock); |
49 | rwlock_write_unlock(&rwlock); |
47 | rwlock_write_unlock(&rwlock); |
50 | 48 | ||
51 | if (!sh_quiet) |
- | |
52 | printf("Trying to lock rwlock for reading....\n"); |
49 | TPRINTF("Trying to lock rwlock for reading....\n"); |
53 | 50 | ||
54 | rwlock_read_lock(&rwlock); |
51 | rwlock_read_lock(&rwlock); |
55 | rwlock_read_unlock(&rwlock); |
52 | rwlock_read_unlock(&rwlock); |
56 | } |
53 | } |
57 | 54 | ||
58 | char * test_rwlock2(bool quiet) |
55 | char *test_rwlock2(void) |
59 | { |
56 | { |
60 | thread_t *thrd; |
57 | thread_t *thrd; |
61 | sh_quiet = quiet; |
- | |
62 | 58 | ||
63 | rwlock_initialize(&rwlock); |
59 | rwlock_initialize(&rwlock); |
64 | 60 | ||
- | 61 | rwlock_read_lock(&rwlock); |
|
65 | rwlock_read_lock(&rwlock); |
62 | rwlock_read_lock(&rwlock); |
66 | rwlock_read_lock(&rwlock); |
63 | rwlock_read_lock(&rwlock); |
67 | rwlock_read_lock(&rwlock); |
64 | rwlock_read_lock(&rwlock); |
68 | rwlock_read_lock(&rwlock); |
- | |
69 | 65 | ||
70 | thrd = thread_create(writer, NULL, TASK, 0, "writer", false); |
66 | thrd = thread_create(writer, NULL, TASK, 0, "writer", false); |
71 | if (thrd) |
67 | if (thrd) |
72 | thread_ready(thrd); |
68 | thread_ready(thrd); |
73 | else |
69 | else |
74 | return "Could not create thread"; |
70 | return "Could not create thread"; |
75 | 71 | ||
76 | thread_sleep(1); |
72 | thread_sleep(1); |
77 | 73 | ||
78 | rwlock_read_unlock(&rwlock); |
74 | rwlock_read_unlock(&rwlock); |
79 | rwlock_read_unlock(&rwlock); |
75 | rwlock_read_unlock(&rwlock); |
80 | rwlock_read_unlock(&rwlock); |
76 | rwlock_read_unlock(&rwlock); |