1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/tests/affinity.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,92 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nspr.h" 1.10 +#include "pprthred.h" 1.11 +#include "plgetopt.h" 1.12 + 1.13 +#include <stdio.h> 1.14 +#include <stdlib.h> 1.15 +#include <string.h> 1.16 + 1.17 +#ifndef XP_BEOS 1.18 + 1.19 +/* 1.20 + * Test PR_GetThreadAffinityMask 1.21 + * The function is called by each of local, global and global bound threads 1.22 + * The test should be run on both single and multi-cpu systems 1.23 + */ 1.24 +static void PR_CALLBACK thread_start(void *arg) 1.25 +{ 1.26 +PRUint32 mask = 0; 1.27 + 1.28 + if (PR_GetThreadAffinityMask(PR_GetCurrentThread(), &mask)) 1.29 + printf("\tthread_start: PR_GetCurrentThreadAffinityMask failed\n"); 1.30 + else 1.31 + printf("\tthread_start: AffinityMask = 0x%x\n",mask); 1.32 + 1.33 +} 1.34 + 1.35 +int main(int argc, char **argv) 1.36 +{ 1.37 + PRThread *t; 1.38 + 1.39 + printf("main: creating local thread\n"); 1.40 + 1.41 + t = PR_CreateThread(PR_USER_THREAD, 1.42 + thread_start, 0, 1.43 + PR_PRIORITY_NORMAL, 1.44 + PR_LOCAL_THREAD, 1.45 + PR_JOINABLE_THREAD, 1.46 + 0); 1.47 + 1.48 + if (NULL == t) { 1.49 + printf("main: cannot create local thread\n"); 1.50 + exit(1); 1.51 + } 1.52 + 1.53 + PR_JoinThread(t); 1.54 + 1.55 + printf("main: creating global thread\n"); 1.56 + t = PR_CreateThread(PR_USER_THREAD, 1.57 + thread_start, 0, 1.58 + PR_PRIORITY_NORMAL, 1.59 + PR_GLOBAL_THREAD, 1.60 + PR_JOINABLE_THREAD, 1.61 + 0); 1.62 + 1.63 + if (NULL == t) { 1.64 + printf("main: cannot create global thread\n"); 1.65 + exit(1); 1.66 + } 1.67 + 1.68 + PR_JoinThread(t); 1.69 + 1.70 + printf("main: creating global bound thread\n"); 1.71 + t = PR_CreateThread(PR_USER_THREAD, 1.72 + thread_start, 0, 1.73 + PR_PRIORITY_NORMAL, 1.74 + PR_GLOBAL_BOUND_THREAD, 1.75 + PR_JOINABLE_THREAD, 1.76 + 0); 1.77 + 1.78 + if (NULL == t) { 1.79 + printf("main: cannot create global bound thread\n"); 1.80 + exit(1); 1.81 + } 1.82 + 1.83 + PR_JoinThread(t); 1.84 + 1.85 + return 0; 1.86 +} 1.87 + 1.88 +#else /* !XP_BEOS */ 1.89 + 1.90 +int main() 1.91 +{ 1.92 + printf( "This test is not supported on the BeOS\n" ); 1.93 + return 0; 1.94 +} 1.95 +#endif /* !XP_BEOS */