Subversion Repositories HelenOS

Rev

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

Rev 3069 Rev 4227
Line 34... Line 34...
34
#include <atomic.h>
34
#include <atomic.h>
35
#include <proc/thread.h>
35
#include <proc/thread.h>
36
 
36
 
37
#include <arch.h>
37
#include <arch.h>
38
 
38
 
39
#define THREADS 5
39
#define THREADS  5
40
 
40
 
41
static atomic_t finish;
41
static atomic_t finish;
42
static atomic_t threads_finished;
42
static atomic_t threads_finished;
43
static bool sh_quiet;
-
 
44
 
43
 
45
static void threadtest(void *data)
44
static void threadtest(void *data)
46
{
45
{
47
    thread_detach(THREAD); 
46
    thread_detach(THREAD);
48
 
47
   
49
    while (atomic_get(&finish)) {
48
    while (atomic_get(&finish)) {
50
        if (!sh_quiet)
-
 
51
            printf("%" PRIu64 " ", THREAD->tid);
49
        TPRINTF("%" PRIu64 " ", THREAD->tid);
52
        thread_usleep(100000);
50
        thread_usleep(100000);
53
    }
51
    }
54
    atomic_inc(&threads_finished);
52
    atomic_inc(&threads_finished);
55
}
53
}
56
 
54
 
57
char * test_thread1(bool quiet)
55
char *test_thread1(void)
58
{
56
{
59
    unsigned int i, total = 0;
57
    unsigned int i, total = 0;
60
    sh_quiet = quiet;
-
 
61
   
58
   
62
    atomic_set(&finish, 1);
59
    atomic_set(&finish, 1);
63
    atomic_set(&threads_finished, 0);
60
    atomic_set(&threads_finished, 0);
64
 
61
   
65
    for (i = 0; i < THREADS; i++) {  
62
    for (i = 0; i < THREADS; i++) {  
66
        thread_t *t;
63
        thread_t *t;
67
        if (!(t = thread_create(threadtest, NULL, TASK, 0, "threadtest", false))) {
64
        if (!(t = thread_create(threadtest, NULL, TASK, 0, "threadtest", false))) {
68
            if (!quiet)
-
 
69
                printf("Could not create thread %d\n", i);
65
            TPRINTF("Could not create thread %d\n", i);
70
            break;
66
            break;
71
        }
67
        }
72
        thread_ready(t);
68
        thread_ready(t);
73
        total++;
69
        total++;
74
    }
70
    }
75
   
71
   
76
    if (!quiet)
-
 
77
        printf("Running threads for 10 seconds...\n");
72
    TPRINTF("Running threads for 10 seconds...\n");
78
    thread_sleep(10);
73
    thread_sleep(10);
79
   
74
   
80
    atomic_set(&finish, 0);
75
    atomic_set(&finish, 0);
81
    while (atomic_get(&threads_finished) < ((long) total)) {
76
    while (atomic_get(&threads_finished) < ((long) total)) {
82
        if (!quiet)
-
 
83
            printf("Threads left: %d\n", total - atomic_get(&threads_finished));
77
        TPRINTF("Threads left: %d\n", total - atomic_get(&threads_finished));
84
        thread_sleep(1);
78
        thread_sleep(1);
85
    }
79
    }
86
   
80
   
87
    return NULL;
81
    return NULL;
88
}
82
}