Rev 2022 | Rev 2028 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2022 | Rev 2024 | ||
|---|---|---|---|
| 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 | static SPINLOCK_INITIALIZE(lock); |
44 | SPINLOCK_INITIALIZE(sem_lock); |
| 45 | 45 | ||
| 46 | static waitq_t can_start; |
46 | static waitq_t can_start; |
| 47 | 47 | ||
| 48 | static uint32_t seed = 0xdeadbeef; |
48 | static uint32_t seed = 0xdeadbeef; |
| 49 | 49 | ||
| Line 54... | Line 54... | ||
| 54 | 54 | ||
| 55 | static 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(&sem_lock); |
| 60 | rc = seed % max; |
60 | rc = seed % max; |
| 61 | seed = (((seed<<2) ^ (seed>>2)) * 487) + rc; |
61 | seed = (((seed<<2) ^ (seed>>2)) * 487) + rc; |
| 62 | spinlock_unlock(&lock); |
62 | spinlock_unlock(&sem_lock); |
| 63 | return rc; |
63 | return rc; |
| 64 | } |
64 | } |
| 65 | 65 | ||
| 66 | 66 | ||
| 67 | static void consumer(void *arg) |
67 | static void consumer(void *arg) |