Last change
on this file was 2, checked in by Dmitry A. Kuminov, 16 years ago |
Initially imported qt-all-opensource-src-4.5.1 from Trolltech.
|
File size:
1.2 KB
|
Line | |
---|
1 | /*
|
---|
2 | * $Id:$
|
---|
3 | * Solaris version
|
---|
4 | * by Wolfram Gloger 2004
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include <thread.h>
|
---|
8 | #include <stdio.h>
|
---|
9 |
|
---|
10 | #ifndef STACKSIZE
|
---|
11 | #define STACKSIZE 32768
|
---|
12 | #endif
|
---|
13 |
|
---|
14 | struct thread_st {
|
---|
15 | char *sp; /* stack pointer, can be 0 */
|
---|
16 | void (*func)(struct thread_st* st); /* must be set by user */
|
---|
17 | thread_id id;
|
---|
18 | int flags;
|
---|
19 | struct user_data u;
|
---|
20 | };
|
---|
21 |
|
---|
22 | static void
|
---|
23 | thread_init(void)
|
---|
24 | {
|
---|
25 | printf("Using Solaris threads.\n");
|
---|
26 | }
|
---|
27 |
|
---|
28 | static void *
|
---|
29 | thread_wrapper(void *ptr)
|
---|
30 | {
|
---|
31 | struct thread_st *st = (struct thread_st*)ptr;
|
---|
32 |
|
---|
33 | /*printf("begin %p\n", st->sp);*/
|
---|
34 | st->func(st);
|
---|
35 | /*printf("end %p\n", st->sp);*/
|
---|
36 | return NULL;
|
---|
37 | }
|
---|
38 |
|
---|
39 | /* Create a thread. */
|
---|
40 | static int
|
---|
41 | thread_create(struct thread_st *st)
|
---|
42 | {
|
---|
43 | st->flags = 0;
|
---|
44 | if(!st->sp)
|
---|
45 | st->sp = malloc(STACKSIZE);
|
---|
46 | if(!st->sp) return -1;
|
---|
47 | thr_create(st->sp, STACKSIZE, thread_wrapper, st, THR_NEW_LWP, &st->id);
|
---|
48 | return 0;
|
---|
49 | }
|
---|
50 |
|
---|
51 | /* Wait for one of several subthreads to finish. */
|
---|
52 | static void
|
---|
53 | wait_for_thread(struct thread_st st[], int n_thr,
|
---|
54 | int (*end_thr)(struct thread_st*))
|
---|
55 | {
|
---|
56 | int i;
|
---|
57 | thread_t id;
|
---|
58 |
|
---|
59 | thr_join(0, &id, NULL);
|
---|
60 | for(i=0; i<n_thr; i++)
|
---|
61 | if(id == st[i].id) {
|
---|
62 | if(end_thr)
|
---|
63 | end_thr(&st[i]);
|
---|
64 | break;
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | /*
|
---|
69 | * Local variables:
|
---|
70 | * tab-width: 4
|
---|
71 | * End:
|
---|
72 | */
|
---|
Note:
See
TracBrowser
for help on using the repository browser.