Subversion Repositories HelenOS-historic

Rev

Rev 1658 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1658 Rev 1780
Line 43... Line 43...
43
 
43
 
44
SPINLOCK_INITIALIZE(lock);
44
SPINLOCK_INITIALIZE(lock);
45
 
45
 
46
static waitq_t can_start;
46
static waitq_t can_start;
47
 
47
 
48
__u32 seed = 0xdeadbeef;
48
uint32_t seed = 0xdeadbeef;
49
 
49
 
50
static __u32 random(__u32 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
__u32 random(__u32 max)
55
uint32_t random(uint32_t max)
56
{
56
{
57
    __u32 rc;
57
    uint32_t rc;
58
 
58
 
59
    spinlock_lock(&lock);  
59
    spinlock_lock(&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(&lock);
Line 93... Line 93...
93
    thread_exit();
93
    thread_exit();
94
}
94
}
95
 
95
 
96
void test(void)
96
void test(void)
97
{
97
{
98
    __u32 i, k;
98
    uint32_t i, k;
99
   
99
   
100
    printf("Semaphore test #2\n");
100
    printf("Semaphore test #2\n");
101
   
101
   
102
    waitq_initialize(&can_start);
102
    waitq_initialize(&can_start);
103
    semaphore_initialize(&sem, 5);
103
    semaphore_initialize(&sem, 5);