Rev 2022 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2022 | Rev 2028 | ||
---|---|---|---|
Line 37... | Line 37... | ||
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 | 41 | ||
42 | static void writer(void *arg); |
- | |
43 | static void failed(void); |
- | |
44 | - | ||
45 | static void writer(void *arg) |
42 | static void writer(void *arg) |
46 | { |
43 | { |
47 | 44 | ||
48 | thread_detach(THREAD); |
45 | thread_detach(THREAD); |
49 | 46 | ||
Line 56... | Line 53... | ||
56 | rwlock_read_lock(&rwlock); |
53 | rwlock_read_lock(&rwlock); |
57 | rwlock_read_unlock(&rwlock); |
54 | rwlock_read_unlock(&rwlock); |
58 | printf("Test passed.\n"); |
55 | printf("Test passed.\n"); |
59 | } |
56 | } |
60 | 57 | ||
61 | static void failed() |
- | |
62 | { |
- | |
63 | printf("Test failed prematurely.\n"); |
- | |
64 | thread_exit(); |
- | |
65 | } |
- | |
66 | - | ||
67 | void test_rwlock2(void) |
58 | char * test_rwlock2(void) |
68 | { |
59 | { |
69 | thread_t *thrd; |
60 | thread_t *thrd; |
70 | 61 | ||
71 | printf("Read/write locks test #2\n"); |
- | |
72 | - | ||
73 | rwlock_initialize(&rwlock); |
62 | rwlock_initialize(&rwlock); |
74 | 63 | ||
75 | rwlock_read_lock(&rwlock); |
64 | rwlock_read_lock(&rwlock); |
76 | rwlock_read_lock(&rwlock); |
65 | rwlock_read_lock(&rwlock); |
77 | rwlock_read_lock(&rwlock); |
66 | rwlock_read_lock(&rwlock); |
Line 79... | Line 68... | ||
79 | 68 | ||
80 | thrd = thread_create(writer, NULL, TASK, 0, "writer"); |
69 | thrd = thread_create(writer, NULL, TASK, 0, "writer"); |
81 | if (thrd) |
70 | if (thrd) |
82 | thread_ready(thrd); |
71 | thread_ready(thrd); |
83 | else |
72 | else |
84 | failed(); |
73 | return "Could not create thread"; |
85 | - | ||
86 | 74 | ||
87 | thread_sleep(1); |
75 | thread_sleep(1); |
88 | 76 | ||
89 | rwlock_read_unlock(&rwlock); |
77 | rwlock_read_unlock(&rwlock); |
90 | rwlock_read_unlock(&rwlock); |
78 | rwlock_read_unlock(&rwlock); |
91 | rwlock_read_unlock(&rwlock); |
79 | rwlock_read_unlock(&rwlock); |
92 | rwlock_read_unlock(&rwlock); |
80 | rwlock_read_unlock(&rwlock); |
93 | 81 | ||
- | 82 | return NULL; |
|
94 | } |
83 | } |