Subversion Repositories HelenOS-historic

Rev

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

Rev 1658 Rev 1780
Line 48... Line 48...
48
 
48
 
49
SPINLOCK_INITIALIZE(lock);
49
SPINLOCK_INITIALIZE(lock);
50
 
50
 
51
static waitq_t can_start;
51
static waitq_t can_start;
52
 
52
 
53
__u32 seed = 0xdeadbeef;
53
uint32_t seed = 0xdeadbeef;
54
 
54
 
55
static __u32 random(__u32 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
__u32 random(__u32 max)
61
uint32_t random(uint32_t max)
62
{
62
{
63
    __u32 rc;
63
    uint32_t rc;
64
 
64
 
65
    spinlock_lock(&lock);  
65
    spinlock_lock(&lock);  
66
    rc = seed % max;
66
    rc = seed % max;
67
    seed = (((seed<<2) ^ (seed>>2)) * 487) + rc;
67
    seed = (((seed<<2) ^ (seed>>2)) * 487) + rc;
68
    spinlock_unlock(&lock);
68
    spinlock_unlock(&lock);
Line 119... Line 119...
119
}
119
}
120
 
120
 
121
void test(void)
121
void test(void)
122
{
122
{
123
    context_t ctx;
123
    context_t ctx;
124
    __u32 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");
127
   
127
   
128
    waitq_initialize(&can_start);
128
    waitq_initialize(&can_start);
129
    rwlock_initialize(&rwlock);
129
    rwlock_initialize(&rwlock);