testLoggerConcurrency.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "config.h"
00031
00032 #include "ace/Thread.h"
00033 #include <ace/Trace.h>
00034
00035
00036
00037 #include "Logger.hpp"
00038
00039 using namespace std;
00040 using namespace mermaid::support::logging;
00041 using boost::shared_ptr;
00042
00043
00044 shared_ptr<Logger> logger;
00045
00046
00047
00048
00049
00050 static void* outputFlicker (void* arg);
00051
00052
00053
00054
00055
00056 static void* prefixFlicker (void* arg);
00057
00058
00059
00060
00061
00062 static void* repeatLogger (void* arg);
00063
00064
00065
00066
00067
00068 int main()
00069 {
00070 ACE_Trace::stop_tracing();
00071
00072 logger = ThreadSafeLogger::build();
00073 logger->enableAllLogLevels (TerminalOutput::build());
00074
00075 ACE_thread_t *threadID = new ACE_thread_t[12];
00076 ACE_hthread_t *threadHandles = new ACE_hthread_t[12];
00077
00078 ACE_Thread::spawn_n (threadID,
00079 4,
00080 (ACE_THR_FUNC) repeatLogger,
00081 0,
00082 THR_JOINABLE | THR_NEW_LWP,
00083 ACE_DEFAULT_THREAD_PRIORITY,
00084 0, 0, threadHandles);
00085
00086 ACE_Thread::spawn_n (threadID + 4,
00087 4,
00088 (ACE_THR_FUNC) outputFlicker,
00089 0,
00090 THR_JOINABLE | THR_NEW_LWP,
00091 ACE_DEFAULT_THREAD_PRIORITY,
00092 0, 0, threadHandles + 4);
00093
00094 ACE_Thread::spawn_n (threadID + 8,
00095 4,
00096 (ACE_THR_FUNC) prefixFlicker,
00097 0,
00098 THR_JOINABLE | THR_NEW_LWP,
00099 ACE_DEFAULT_THREAD_PRIORITY,
00100 0, 0, threadHandles + 8);
00101
00102
00103
00104 #if 0
00105 ACE_Thread::spawn ( (ACE_THR_FUNC) repeatLogger);
00106 ACE_Thread::spawn ( (ACE_THR_FUNC) repeatLogger);
00107 ACE_Thread::spawn ( (ACE_THR_FUNC) repeatLogger);
00108 ACE_Thread::spawn ( (ACE_THR_FUNC) repeatLogger);
00109 ACE_Thread::spawn ( (ACE_THR_FUNC) outputFlicker);
00110 ACE_Thread::spawn ( (ACE_THR_FUNC) outputFlicker);
00111 ACE_Thread::spawn ( (ACE_THR_FUNC) outputFlicker);
00112 ACE_Thread::spawn ( (ACE_THR_FUNC) outputFlicker);
00113 ACE_Thread::spawn ( (ACE_THR_FUNC) prefixFlicker);
00114 ACE_Thread::spawn ( (ACE_THR_FUNC) prefixFlicker);
00115 ACE_Thread::spawn ( (ACE_THR_FUNC) prefixFlicker);
00116 ACE_Thread::spawn ( (ACE_THR_FUNC) prefixFlicker);
00117 #endif
00118
00119 repeatLogger (0);
00120
00121 for (int i = 0; i < 12; i++)
00122 ACE_Thread::join (threadHandles[i]);
00123
00124 return 0;
00125 }
00126
00127 static void* outputFlicker (void* arg)
00128 {
00129 for (int i = 0; i < 1000; i++) {
00130 logger->disableAllLogLevels();
00131 LSTEP (logger, "This is " << i);
00132 logger->enableAllLogLevels (TerminalOutput::build());
00133 LSTEP (logger, "This is " << i);
00134 }
00135 return 0;
00136 }
00137
00138 static void* prefixFlicker (void* arg)
00139 {
00140 for (int i = 0; i < 1000; i++) {
00141 logger->setPrefix ("PREFIX");
00142 LSTEP (logger, "This is " << i);
00143 logger->setPrefix ("");
00144 LSTEP (logger, "This is " << i);
00145 }
00146 return 0;
00147 }
00148
00149 static void* repeatLogger (void* arg)
00150 {
00151 for (int i = 0; i < 1000; i++) {
00152 LSTEP (logger, "This is " << i);
00153 }
00154 return 0;
00155 }