Rev 1852 | Rev 2024 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1852 | Rev 2022 | ||
---|---|---|---|
Line 44... | Line 44... | ||
44 | #define READERS 50 |
44 | #define READERS 50 |
45 | #define WRITERS 50 |
45 | #define WRITERS 50 |
46 | 46 | ||
47 | static rwlock_t rwlock; |
47 | static rwlock_t rwlock; |
48 | 48 | ||
49 | SPINLOCK_INITIALIZE(lock); |
49 | static SPINLOCK_INITIALIZE(lock); |
50 | 50 | ||
51 | static waitq_t can_start; |
51 | static waitq_t can_start; |
52 | 52 | ||
53 | uint32_t seed = 0xdeadbeef; |
53 | static uint32_t seed = 0xdeadbeef; |
54 | 54 | ||
55 | static uint32_t random(uint32_t max); |
55 | static uint32_t random(uint32_t max); |
56 | 56 | ||
57 | static void writer(void *arg); |
57 | static void writer(void *arg); |
58 | static void reader(void *arg); |
58 | static void reader(void *arg); |
59 | static void failed(void); |
59 | static void failed(void); |
60 | 60 | ||
61 | uint32_t random(uint32_t max) |
61 | static uint32_t random(uint32_t max) |
62 | { |
62 | { |
63 | uint32_t rc; |
63 | uint32_t rc; |
64 | 64 | ||
65 | spinlock_lock(&lock); |
65 | spinlock_lock(&lock); |
66 | rc = seed % max; |
66 | rc = seed % max; |
Line 68... | Line 68... | ||
68 | spinlock_unlock(&lock); |
68 | spinlock_unlock(&lock); |
69 | return rc; |
69 | return rc; |
70 | } |
70 | } |
71 | 71 | ||
72 | 72 | ||
73 | void writer(void *arg) |
73 | static void writer(void *arg) |
74 | { |
74 | { |
75 | int rc, to; |
75 | int rc, to; |
76 | thread_detach(THREAD); |
76 | thread_detach(THREAD); |
77 | waitq_sleep(&can_start); |
77 | waitq_sleep(&can_start); |
78 | 78 | ||
Line 91... | Line 91... | ||
91 | 91 | ||
92 | rwlock_write_unlock(&rwlock); |
92 | rwlock_write_unlock(&rwlock); |
93 | printf("cpu%d, tid %d w-\n", CPU->id, THREAD->tid); |
93 | printf("cpu%d, tid %d w-\n", CPU->id, THREAD->tid); |
94 | } |
94 | } |
95 | 95 | ||
96 | void reader(void *arg) |
96 | static void reader(void *arg) |
97 | { |
97 | { |
98 | int rc, to; |
98 | int rc, to; |
99 | thread_detach(THREAD); |
99 | thread_detach(THREAD); |
100 | waitq_sleep(&can_start); |
100 | waitq_sleep(&can_start); |
101 | 101 | ||
Line 110... | Line 110... | ||
110 | thread_usleep(30000); |
110 | thread_usleep(30000); |
111 | rwlock_read_unlock(&rwlock); |
111 | rwlock_read_unlock(&rwlock); |
112 | printf("cpu%d, tid %d r-\n", CPU->id, THREAD->tid); |
112 | printf("cpu%d, tid %d r-\n", CPU->id, THREAD->tid); |
113 | } |
113 | } |
114 | 114 | ||
115 | void failed(void) |
115 | static void failed(void) |
116 | { |
116 | { |
117 | printf("Test failed prematurely.\n"); |
117 | printf("Test failed prematurely.\n"); |
118 | thread_exit(); |
118 | thread_exit(); |
119 | } |
119 | } |
120 | 120 | ||
121 | void test(void) |
121 | void test_rwlock4(void) |
122 | { |
122 | { |
123 | context_t ctx; |
123 | context_t ctx; |
124 | uint32_t i, k; |
124 | uint32_t i, k; |
125 | 125 | ||
126 | printf("Read/write locks test #4\n"); |
126 | printf("Read/write locks test #4\n"); |