nsprpub/pr/tests/short_thread.c

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

     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 <stdio.h>
     7 #include "nspr.h"
     8 #include "plgetopt.h"
    10 /*
    11  * Create a thread that exits right away; useful for testing race conditions in thread
    12  * creation
    13  */
    15 int _debug_on = 0;
    16 #define DPRINTF(arg) if (_debug_on) printf arg
    18 static void housecleaning(void *cur_time);
    20 int main (int argc, char **argv)
    21 {
    22 	static PRIntervalTime thread_start_time;
    23 	static PRThread *housekeeping_tid = NULL;
    24 	PLOptStatus os;
    25 	PLOptState *opt = PL_CreateOptState(argc, argv, "d");
    27 	while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    28 	{
    29 		if (PL_OPT_BAD == os) continue;
    30 		switch (opt->option)
    31 		{
    32 			case 'd':  /* debug mode */
    33 				_debug_on = 1;
    34 				break;
    35 			default:
    36 				break;
    37 		}
    38 	}
    39 	PL_DestroyOptState(opt);
    41 	if (( housekeeping_tid = 
    42 		PR_CreateThread (PR_USER_THREAD, housecleaning,  (void*)&thread_start_time,
    43 						 PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0)) 
    44 																		== NULL ) {
    45 		fprintf(stderr,
    46 			"simple_test: Error - PR_CreateThread failed: (%ld, %ld)\n",
    47 									  PR_GetError(), PR_GetOSError());
    48 		exit( 1 );
    49 	}
    50 	PR_Cleanup();
    51 	return(0);
    52 }
    54 static void
    55 housecleaning (void *cur_time) 
    56 {
    57   DPRINTF(("Child Thread exiting\n"));
    58 }

mercurial