affinity.c (1842B)
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 * Test PR_GetThreadAffinityMask 16 * The function is called by each of local, global and global bound threads 17 * The test should be run on both single and multi-cpu systems 18 */ 19 static void PR_CALLBACK thread_start(void* arg) { 20 PRUint32 mask = 0; 21 22 if (PR_GetThreadAffinityMask(PR_GetCurrentThread(), &mask)) { 23 printf("\tthread_start: PR_GetCurrentThreadAffinityMask failed\n"); 24 } else { 25 printf("\tthread_start: AffinityMask = 0x%x\n", mask); 26 } 27 } 28 29 int main(int argc, char** argv) { 30 PRThread* t; 31 32 printf("main: creating local thread\n"); 33 34 t = PR_CreateThread(PR_USER_THREAD, thread_start, 0, PR_PRIORITY_NORMAL, 35 PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0); 36 37 if (NULL == t) { 38 printf("main: cannot create local thread\n"); 39 exit(1); 40 } 41 42 PR_JoinThread(t); 43 44 printf("main: creating global thread\n"); 45 t = PR_CreateThread(PR_USER_THREAD, thread_start, 0, PR_PRIORITY_NORMAL, 46 PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0); 47 48 if (NULL == t) { 49 printf("main: cannot create global thread\n"); 50 exit(1); 51 } 52 53 PR_JoinThread(t); 54 55 printf("main: creating global bound thread\n"); 56 t = PR_CreateThread(PR_USER_THREAD, thread_start, 0, PR_PRIORITY_NORMAL, 57 PR_GLOBAL_BOUND_THREAD, PR_JOINABLE_THREAD, 0); 58 59 if (NULL == t) { 60 printf("main: cannot create global bound thread\n"); 61 exit(1); 62 } 63 64 PR_JoinThread(t); 65 66 return 0; 67 }