Rev 1787 | Rev 2024 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1787 | Rev 2022 | ||
---|---|---|---|
Line 39... | Line 39... | ||
39 | #include <synch/synch.h> |
39 | #include <synch/synch.h> |
40 | #include <synch/spinlock.h> |
40 | #include <synch/spinlock.h> |
41 | 41 | ||
42 | static semaphore_t sem; |
42 | static semaphore_t sem; |
43 | 43 | ||
44 | SPINLOCK_INITIALIZE(lock); |
44 | static SPINLOCK_INITIALIZE(lock); |
45 | 45 | ||
46 | static waitq_t can_start; |
46 | static waitq_t can_start; |
47 | 47 | ||
48 | uint32_t seed = 0xdeadbeef; |
48 | static uint32_t seed = 0xdeadbeef; |
49 | 49 | ||
50 | static uint32_t random(uint32_t max); |
50 | static uint32_t random(uint32_t max); |
51 | 51 | ||
52 | static void consumer(void *arg); |
52 | static void consumer(void *arg); |
53 | static void failed(void); |
53 | static void failed(void); |
54 | 54 | ||
55 | uint32_t random(uint32_t max) |
55 | static uint32_t random(uint32_t max) |
56 | { |
56 | { |
57 | uint32_t rc; |
57 | uint32_t rc; |
58 | 58 | ||
59 | spinlock_lock(&lock); |
59 | spinlock_lock(&lock); |
60 | rc = seed % max; |
60 | rc = seed % max; |
Line 62... | Line 62... | ||
62 | spinlock_unlock(&lock); |
62 | spinlock_unlock(&lock); |
63 | return rc; |
63 | return rc; |
64 | } |
64 | } |
65 | 65 | ||
66 | 66 | ||
67 | void consumer(void *arg) |
67 | static void consumer(void *arg) |
68 | { |
68 | { |
69 | int rc, to; |
69 | int rc, to; |
70 | 70 | ||
71 | thread_detach(THREAD); |
71 | thread_detach(THREAD); |
72 | 72 | ||
Line 85... | Line 85... | ||
85 | 85 | ||
86 | semaphore_up(&sem); |
86 | semaphore_up(&sem); |
87 | printf("cpu%d, tid %d up\n", CPU->id, THREAD->tid); |
87 | printf("cpu%d, tid %d up\n", CPU->id, THREAD->tid); |
88 | } |
88 | } |
89 | 89 | ||
90 | void failed(void) |
90 | static void failed(void) |
91 | { |
91 | { |
92 | printf("Test failed prematurely.\n"); |
92 | printf("Test failed prematurely.\n"); |
93 | thread_exit(); |
93 | thread_exit(); |
94 | } |
94 | } |
95 | 95 | ||
96 | void test(void) |
96 | void test_semaphore2(void) |
97 | { |
97 | { |
98 | uint32_t i, k; |
98 | uint32_t i, k; |
99 | 99 | ||
100 | printf("Semaphore test #2\n"); |
100 | printf("Semaphore test #2\n"); |
101 | 101 |