Bug 1825055 [wpt PR 39247] - Add support for allowing elements with display:contents...
[gecko.git] / nsprpub / pr / tests / logger.c
blobee28d41d7ca430e2ca1eaf61a86b22fd5a8bf936
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 /*
7 * File: logger.c
8 * Description: test program for logging's basic functions
9 */
11 #include "prinit.h"
12 #include "prlog.h"
13 #include "prlock.h"
14 #include "prcvar.h"
15 #include "prthread.h"
16 #include "prinrval.h"
18 #include <stdio.h>
20 /* lth. re-define PR_LOG() */
21 #if 0
22 #undef PR_LOG_TEST
23 #undef PR_LOG
24 #define PR_LOG_TEST(_module,_level) ((_module)->level <= (_level))
25 #define PR_LOG(_module,_level,_args) \
26 { \
27 if (PR_LOG_TEST(_module,_level)) \
28 PR_LogPrint _args ; \
30 #endif
33 static void Error(const char* msg)
35 printf("\t%s\n", msg);
36 } /* Error */
38 static void PR_CALLBACK forked(void *arg)
40 PRIntn i;
41 PRLock *ml;
42 PRCondVar *cv;
44 PR_LogPrint("%s logging creating mutex\n", (const char*)arg);
45 ml = PR_NewLock();
46 PR_LogPrint("%s logging creating condition variable\n", (const char*)arg);
47 cv = PR_NewCondVar(ml);
49 PR_LogPrint("%s waiting on condition timeout 10 times\n", (const char*)arg);
50 for (i = 0; i < 10; ++i)
52 PR_Lock(ml);
53 PR_WaitCondVar(cv, PR_SecondsToInterval(1));
54 PR_Unlock(ml);
57 PR_LogPrint("%s logging destroying condition variable\n", (const char*)arg);
58 PR_DestroyCondVar(cv);
59 PR_LogPrint("%s logging destroying mutex\n", (const char*)arg);
60 PR_DestroyLock(ml);
61 PR_LogPrint("%s forked thread exiting\n", (const char*)arg);
64 static void UserLogStuff( void )
66 PRLogModuleInfo *myLM;
67 PRIntn i;
69 myLM = PR_NewLogModule( "userStuff" );
70 if (! myLM )
72 printf("UserLogStuff(): can't create new log module\n" );
73 return;
76 PR_LOG( myLM, PR_LOG_NOTICE, ("Log a Notice %d\n", 1 ));
78 for (i = 0; i < 10 ; i++ )
80 PR_LOG( myLM, PR_LOG_DEBUG, ("Log Debug number: %d\n", i));
81 PR_Sleep( 300 );
84 } /* end UserLogStuff() */
86 int main(int argc, char **argv)
88 PRThread *thread;
90 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
91 PR_STDIO_INIT();
93 if (argc > 1)
95 if (!PR_SetLogFile(argv[1]))
97 Error("Access: Cannot create log file");
98 goto exit;
102 /* Start logging something here */
103 PR_LogPrint("%s logging into %s\n", argv[0], argv[1]);
105 PR_LogPrint("%s creating new thread\n", argv[0]);
108 ** Now change buffering.
110 PR_SetLogBuffering( 65500 );
111 thread = PR_CreateThread(
112 PR_USER_THREAD, forked, (void*)argv[0], PR_PRIORITY_NORMAL,
113 PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
114 PR_LogPrint("%s joining thread\n", argv[0]);
116 UserLogStuff();
118 PR_JoinThread(thread);
120 PR_LogFlush();
121 return 0;
123 exit:
124 return -1;
127 /* logger.c */