Subversion Repositories HelenOS

Rev

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

Rev 4153 Rev 4263
Line 48... Line 48...
48
static 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
    uint32_t rc;
52
    uint32_t rc;
53
 
53
   
54
    spinlock_lock(&sem_lock);  
54
    spinlock_lock(&sem_lock);
55
    rc = seed % max;
55
    rc = seed % max;
56
    seed = (((seed << 2) ^ (seed >> 2)) * 487) + rc;
56
    seed = (((seed << 2) ^ (seed >> 2)) * 487) + rc;
57
    spinlock_unlock(&sem_lock);
57
    spinlock_unlock(&sem_lock);
58
    return rc;
58
    return rc;
59
}
59
}
Line 65... Line 65...
65
    thread_detach(THREAD);
65
    thread_detach(THREAD);
66
   
66
   
67
    waitq_sleep(&can_start);
67
    waitq_sleep(&can_start);
68
   
68
   
69
    to = random(20000);
69
    to = random(20000);
70
    printf("cpu%u, tid %" PRIu64 " down+ (%d)\n", CPU->id, THREAD->tid, to);
70
    TPRINTF("cpu%u, tid %" PRIu64 " down+ (%d)\n", CPU->id, THREAD->tid, to);
71
    rc = semaphore_down_timeout(&sem, to);
71
    rc = semaphore_down_timeout(&sem, to);
72
    if (SYNCH_FAILED(rc)) {
72
    if (SYNCH_FAILED(rc)) {
73
        printf("cpu%u, tid %" PRIu64 " down!\n", CPU->id, THREAD->tid);
73
        TPRINTF("cpu%u, tid %" PRIu64 " down!\n", CPU->id, THREAD->tid);
74
        return;
74
        return;
75
    }
75
    }
76
   
76
   
77
    printf("cpu%u, tid %" PRIu64 " down=\n", CPU->id, THREAD->tid);
77
    TPRINTF("cpu%u, tid %" PRIu64 " down=\n", CPU->id, THREAD->tid);   
78
    thread_usleep(random(30000));
78
    thread_usleep(random(30000));
79
   
79
   
80
    semaphore_up(&sem);
80
    semaphore_up(&sem);
81
    printf("cpu%u, tid %" PRIu64 " up\n", CPU->id, THREAD->tid);
81
    TPRINTF("cpu%u, tid %" PRIu64 " up\n", CPU->id, THREAD->tid);
82
}
82
}
83
 
83
 
84
char * test_semaphore2(bool quiet)
84
char *test_semaphore2(void)
85
{
85
{
86
    uint32_t i, k;
86
    uint32_t i, k;
87
   
87
   
88
    waitq_initialize(&can_start);
88
    waitq_initialize(&can_start);
89
    semaphore_initialize(&sem, 5);
89
    semaphore_initialize(&sem, 5);
90
   
90
   
91
    thread_t *thrd;
91
    thread_t *thrd;
92
   
92
   
93
    k = random(7) + 1;
93
    k = random(7) + 1;
94
    printf("Creating %" PRIu32 " consumers\n", k);
94
    TPRINTF("Creating %" PRIu32 " consumers\n", k);
95
    for (i = 0; i < k; i++) {
95
    for (i = 0; i < k; i++) {
96
        thrd = thread_create(consumer, NULL, TASK, 0, "consumer", false);
96
        thrd = thread_create(consumer, NULL, TASK, 0, "consumer", false);
97
        if (thrd)
97
        if (thrd)
98
            thread_ready(thrd);
98
            thread_ready(thrd);
99
        else
99
        else
100
            printf("Error creating thread\n");
100
            TPRINTF("Error creating thread\n");
101
    }
101
    }
102
   
102
   
103
    thread_usleep(20000);
103
    thread_usleep(20000);
104
    waitq_wakeup(&can_start, WAKEUP_ALL);
104
    waitq_wakeup(&can_start, WAKEUP_ALL);
105
   
105