nsprpub/pr/tests/affinity.c

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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/. */
     6 #include "nspr.h"
     7 #include "pprthred.h"
     8 #include "plgetopt.h"
    10 #include <stdio.h>
    11 #include <stdlib.h>
    12 #include <string.h>
    14 #ifndef XP_BEOS
    16 /*
    17  * Test PR_GetThreadAffinityMask
    18  *		The function is called by each of local, global and global bound threads
    19  *		The test should be run on both single and multi-cpu systems
    20  */
    21 static void PR_CALLBACK thread_start(void *arg)
    22 {
    23 PRUint32 mask = 0;
    25 	if (PR_GetThreadAffinityMask(PR_GetCurrentThread(), &mask)) 
    26 		printf("\tthread_start: PR_GetCurrentThreadAffinityMask failed\n");
    27 	else
    28 		printf("\tthread_start: AffinityMask = 0x%x\n",mask);
    30 }
    32 int main(int argc, char **argv)
    33 {
    34 	PRThread *t;
    36 	printf("main: creating local thread\n");
    38 	t = PR_CreateThread(PR_USER_THREAD,
    39 				  thread_start, 0, 
    40 				  PR_PRIORITY_NORMAL,
    41 				  PR_LOCAL_THREAD,
    42 				  PR_JOINABLE_THREAD,
    43 				  0);
    45 	if (NULL == t) {
    46 		printf("main: cannot create local thread\n");
    47 		exit(1);
    48 	}
    50 	PR_JoinThread(t);
    52 	printf("main: creating global thread\n");
    53 	t = PR_CreateThread(PR_USER_THREAD,
    54 				  thread_start, 0, 
    55 				  PR_PRIORITY_NORMAL,
    56 				  PR_GLOBAL_THREAD,
    57 				  PR_JOINABLE_THREAD,
    58 				  0);
    60 	if (NULL == t) {
    61 		printf("main: cannot create global thread\n");
    62 		exit(1);
    63 	}
    65 	PR_JoinThread(t);
    67 	printf("main: creating global bound thread\n");
    68 	t = PR_CreateThread(PR_USER_THREAD,
    69 				  thread_start, 0, 
    70 				  PR_PRIORITY_NORMAL,
    71 				  PR_GLOBAL_BOUND_THREAD,
    72 				  PR_JOINABLE_THREAD,
    73 				  0);
    75 	if (NULL == t) {
    76 		printf("main: cannot create global bound thread\n");
    77 		exit(1);
    78 	}
    80 	PR_JoinThread(t);
    82     return 0;
    83 }
    85 #else /* !XP_BEOS */
    87 int main()
    88 {
    89 	printf( "This test is not supported on the BeOS\n" );
    90 	return 0;
    91 }
    92 #endif /* !XP_BEOS */

mercurial