1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #include "nspr.h"
7 #include "pprthred.h"
8 #include "plgetopt.h"
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13
14
15 /*
16 * Test PR_GetThreadAffinityMask
17 * The function is called by each of local, global and global bound threads
18 * The test should be run on both single and multi-cpu systems
19 */
thread_start(void * arg)20 static void PR_CALLBACK thread_start(void *arg)
21 {
22 PRUint32 mask = 0;
23
24 if (PR_GetThreadAffinityMask(PR_GetCurrentThread(), &mask)) {
25 printf("\tthread_start: PR_GetCurrentThreadAffinityMask failed\n");
26 }
27 else {
28 printf("\tthread_start: AffinityMask = 0x%x\n",mask);
29 }
30
31 }
32
main(int argc,char ** argv)33 int main(int argc, char **argv)
34 {
35 PRThread *t;
36
37 printf("main: creating local thread\n");
38
39 t = PR_CreateThread(PR_USER_THREAD,
40 thread_start, 0,
41 PR_PRIORITY_NORMAL,
42 PR_LOCAL_THREAD,
43 PR_JOINABLE_THREAD,
44 0);
45
46 if (NULL == t) {
47 printf("main: cannot create local thread\n");
48 exit(1);
49 }
50
51 PR_JoinThread(t);
52
53 printf("main: creating global thread\n");
54 t = PR_CreateThread(PR_USER_THREAD,
55 thread_start, 0,
56 PR_PRIORITY_NORMAL,
57 PR_GLOBAL_THREAD,
58 PR_JOINABLE_THREAD,
59 0);
60
61 if (NULL == t) {
62 printf("main: cannot create global thread\n");
63 exit(1);
64 }
65
66 PR_JoinThread(t);
67
68 printf("main: creating global bound thread\n");
69 t = PR_CreateThread(PR_USER_THREAD,
70 thread_start, 0,
71 PR_PRIORITY_NORMAL,
72 PR_GLOBAL_BOUND_THREAD,
73 PR_JOINABLE_THREAD,
74 0);
75
76 if (NULL == t) {
77 printf("main: cannot create global bound thread\n");
78 exit(1);
79 }
80
81 PR_JoinThread(t);
82
83 return 0;
84 }
85