void Join() { void *status; int result = pthread_join(m_ThreadID, &status); if(result != 0) { ReportErrorAndExit(result, "pthread_join"); } }
void Wait(TCLock &lock) { TCLockImpl *lockImpl = (TCLockImpl *)(lock.m_Impl); int result = pthread_cond_wait( &m_CV, lockImpl->GetMutexPtr() ); if(result != 0) { ReportErrorAndExit( result, "pthread_cond_wait" ); } }
TCThreadImpl(TCCallable &callable) : m_Callable(callable) { int result = pthread_create(&m_ThreadID, NULL, RunThread, (void *)this); if(result != 0) { ReportErrorAndExit(result, "pthread_create"); } }
TCLockImpl(TCMutex &mutex) : m_MutexPtr(((TCMutexImpl *)(mutex.m_Impl))->GetMutex()) { int result = pthread_mutex_lock( m_MutexPtr ); if(result != 0) { ReportErrorAndExit(result, "pthread_mutex_lock"); } }
void TCThread::Yield() { #if defined(__APPLE__) || defined(__MINGW32__) int result = sched_yield(); #else int result = pthread_yield(); #endif if(result != 0) { ReportErrorAndExit(result, "pthread_yield"); } }
void burstyParser(int &h, char *argv[], int &argc, unsigned int flowId, SumRandom ** OnPeriod, SumRandom ** OffPeriod, TDistro & OnPeriodDistro, TDistro & OffPeriodDistro) { Real a, b; switch (argv[h][0]) { case 'C': if ((argc < 4) || (strtod(argv[h + 1],NULL) <= 0.)) ReportErrorAndExit("Protocol Parser", "Invalid settings for the On/Off periods", programName, flowId); delete (*OnPeriod); OnPeriodDistro = pdConstant; ConstantRV = new Constant(1); *OnPeriod = new SumRandom(atoi(argv[h + 1]) * (*ConstantRV)); h += 2; argc -= 2; break; case 'U': if ((argc < 5) || (strtod(argv[h+1],NULL) <= 0.) || (strtod(argv[h+2],NULL) <= strtod(argv[h+1],NULL)) ) ReportErrorAndExit("Protocol Parser", "Invalid settings for the On/Off periods", programName, flowId); delete (*OnPeriod); OnPeriodDistro = pdUniform; a = strtod(argv[h+2],NULL); b = strtod(argv[h+1],NULL) - a ; UniformRV = new Uniform; *OnPeriod = new SumRandom( b * (*UniformRV) + a); h += 3; argc -= 3; break; case 'E': if ((argc < 4) || (strtod(argv[h+1],NULL) <= 0.)) ReportErrorAndExit("Protocol Parser", "Invalid settings for the On/Off periods", programName, flowId); delete (*OnPeriod); OnPeriodDistro = pdExponential; ExponentialRV = new Exponential; *OnPeriod = new SumRandom(strtod(argv[h+1],NULL) * (*ExponentialRV)); h += 2; argc -= 2; break; case 'V': if ((argc < 5) || (strtod(argv[h + 1], NULL) <= 0) || (strtod(argv[h + 2], NULL) <= 0)) ReportErrorAndExit("Protocol Parser", "Invalid settings for the On/Off periods", programName, flowId); a = (Real) strtod(argv[h + 1], NULL); b = (Real) strtod(argv[h + 2], NULL); ParetoRV = new Pareto(a); delete (*OnPeriod); OnPeriodDistro = pdPareto; *OnPeriod = new SumRandom(b * (*ParetoRV)); h += 3; argc -= 3; break; case 'Y': if ((argc < 5) || (strtod(argv[h + 2], NULL) <= 0)) ReportErrorAndExit("Protocol Parser", "Invalid settings for the On/Off periods", programName, flowId); b = strtod(argv[h + 1], NULL); a = strtod(argv[h + 2], NULL); CauchyRV = new Cauchy; delete (*OnPeriod); OnPeriodDistro = pdCauchy; *OnPeriod = new SumRandom(a * (*CauchyRV) + b); h += 3; argc -= 3; break; case 'N': if ((argc < 5) || (argv[h + 2] <= 0)) ReportErrorAndExit("Protocol Parser", "Invalid settings for the On/Off periods", programName, flowId); b = strtod(argv[h + 1], NULL); a = strtod(argv[h + 2], NULL); delete (*OnPeriod); OnPeriodDistro = pdNormal; NormalRV = new Normal; *OnPeriod = new SumRandom(a * (*NormalRV) + b); h += 3; argc -= 3; break; case 'O': if ((argc < 4) || (strtod(argv[h + 1], NULL) <= 0)) ReportErrorAndExit("Protocol Parser", "Invalid settings for the On/Off periods", programName, flowId); a = strtod(argv[h + 1], NULL); delete (*OnPeriod); PoissonRV = new Poisson(a); OnPeriodDistro = pdPoisson; *OnPeriod = new SumRandom( 1 * (*PoissonRV)); h += 2; argc -= 2; break; case 'G': if ((argc < 5) || (strtod(argv[h + 1], NULL) <= 0) || (strtod(argv[h + 2], NULL) <= 0)) ReportErrorAndExit("Protocol Parser", "Invalid settings for the On/Off periods", programName, flowId); a = (Real) strtod(argv[h + 1], NULL); b = (Real) strtod(argv[h + 2], NULL); delete (*OnPeriod); GammaRV = new Gamma(a); OnPeriodDistro = pdGamma; *OnPeriod = new SumRandom(b * (*GammaRV)); h += 3; argc -= 3; break; case 'W': if ((argc < 5) || (strtod(argv[h + 1], NULL) <= 0) || (strtod(argv[h + 2], NULL) <= 0)) ReportErrorAndExit("Protocol Parser", "Invalid settings for the On/Off periods", programName, flowId); a = (Real) strtod(argv[h+1],NULL); b = (Real) strtod(argv[h+2],NULL); delete (*OnPeriod); WeibullRV = new Weibull(a,b); OnPeriodDistro = pdWeibull; *OnPeriod = new SumRandom( 1 * (*WeibullRV)); h += 3; argc -= 3; break; default: ReportErrorAndExit("Protocol Parser", "Invalid settings for the On/Off periods", programName, flowId); break; } switch (argv[h][0]) { case 'C': if ((argc < 2) || (strtod(argv[h + 1],NULL) <= 0.)) ReportErrorAndExit("Protocol Parser", "Invalid settings for the Off/Off periods", programName, flowId); delete (*OffPeriod); OffPeriodDistro = pdConstant; ConstantRV = new Constant(1); *OffPeriod = new SumRandom(atoi(argv[h + 1]) * (*ConstantRV)); h += 2; argc -= 2; break; case 'U': if ((argc < 3) || (strtod(argv[h+1],NULL) <= 0.) || (strtod(argv[h+2],NULL) <= strtod(argv[h+1],NULL)) ) ReportErrorAndExit("Protocol Parser", "Invalid settings for the Off/Off periods", programName, flowId); delete (*OffPeriod); OffPeriodDistro = pdUniform; a = strtod(argv[h+2],NULL); b = strtod(argv[h+1],NULL) - a ; UniformRV = new Uniform; *OffPeriod = new SumRandom( b * (*UniformRV) + a); h += 3; argc -= 3; break; case 'E': if ((argc < 2) || (strtod(argv[h+1],NULL) <= 0.)) ReportErrorAndExit("Protocol Parser", "Invalid settings for the Off/Off periods", programName, flowId); delete (*OffPeriod); OffPeriodDistro = pdExponential; ExponentialRV = new Exponential; *OffPeriod = new SumRandom(strtod(argv[h+1],NULL) * (*ExponentialRV)); h += 2; argc -= 2; break; case 'V': if ((argc < 3) || (strtod(argv[h + 1], NULL) <= 0) || (strtod(argv[h + 2], NULL) <= 0)) ReportErrorAndExit("Protocol Parser", "Invalid settings for the Off/Off periods", programName, flowId); a = (Real) strtod(argv[h + 1], NULL); b = (Real) strtod(argv[h + 2], NULL); ParetoRV = new Pareto(a); delete (*OffPeriod); OffPeriodDistro = pdPareto; *OffPeriod = new SumRandom(b * (*ParetoRV)); h += 3; argc -= 3; break; case 'Y': if ((argc < 3) || (strtod(argv[h + 2], NULL) <= 0)) ReportErrorAndExit("Protocol Parser", "Invalid settings for the Off/Off periods", programName, flowId); b = strtod(argv[h + 1], NULL); a = strtod(argv[h + 2], NULL); CauchyRV = new Cauchy; delete (*OffPeriod); OffPeriodDistro = pdCauchy; *OffPeriod = new SumRandom(a * (*CauchyRV) + b); h += 3; argc -= 3; break; case 'N': if ((argc < 3) || (argv[h + 2] <= 0)) ReportErrorAndExit("Protocol Parser", "Invalid settings for the Off/Off periods", programName, flowId); b = strtod(argv[h + 1], NULL); a = strtod(argv[h + 2], NULL); delete (*OffPeriod); OffPeriodDistro = pdNormal; NormalRV = new Normal; *OffPeriod = new SumRandom(a * (*NormalRV) + b); h += 3; argc -= 3; break; case 'O': if ((argc < 2) || (strtod(argv[h + 1], NULL) <= 0)) ReportErrorAndExit("Protocol Parser", "Invalid settings for the Off/Off periods", programName, flowId); a = strtod(argv[h + 1], NULL); delete (*OffPeriod); PoissonRV = new Poisson(a); OffPeriodDistro = pdPoisson; *OffPeriod = new SumRandom( 1 * (*PoissonRV)); h += 2; argc -= 2; break; case 'G': if ((argc < 3) || (strtod(argv[h + 1], NULL) <= 0) || (strtod(argv[h + 2], NULL) <= 0)) ReportErrorAndExit("Protocol Parser", "Invalid settings for the Off/Off periods", programName, flowId); a = (Real) strtod(argv[h + 1], NULL); b = (Real) strtod(argv[h + 2], NULL); delete (*OffPeriod); GammaRV = new Gamma(a); OffPeriodDistro = pdGamma; *OffPeriod = new SumRandom(b * (*GammaRV)); h += 3; argc -= 3; break; case 'W': if ((argc < 3) || (strtod(argv[h + 1], NULL) <= 0) || (strtod(argv[h + 2], NULL) <= 0)) ReportErrorAndExit("Protocol Parser", "Invalid settings for the On/Off periods", programName, flowId); a = (Real) strtod(argv[h+1],NULL); b = (Real) strtod(argv[h+2],NULL); delete (*OffPeriod); WeibullRV = new Weibull(a,b); OffPeriodDistro = pdWeibull; *OffPeriod = new SumRandom( 1 * (*WeibullRV)); h += 3; argc -= 3; break; default: ReportErrorAndExit("Protocol Parser", "Invalid settings for the On/Off periods", programName, flowId); break; } }
void voIPParser(int h, char *argv[], int &argc, unsigned int flowId, SumRandom ** pIntArriv, SumRandom ** pPktSize, TDistro & IntArrivDistro, TDistro & PktSizeDistro) { char codec[10]; strcpy(codec, "G.711.1"); Real samples = 1.0; Real framesize = 80.0; Real VAD = 1.0; Real header = 12.0; Real pkts = 100.0; argv++; argc--; while (argc > 0) { if (argv[h][0] == '-') { char *tail; switch (argv[h][1]) { case 'x': if (argc < 2) ReportErrorAndExit("VoIP parser", "Invalid Codec Type", programName, flowId); if (strcmp(argv[h + 1], "G.711.1") == 0) { strcpy(codec, "G.711"); framesize = 80.0; samples = 1.0; pkts = 100.0; } else if (strcmp(argv[h + 1], "G.711.2") == 0) { strcpy(codec, "G.711"); framesize = 80.0; samples = 2.0; pkts = 50.0; } else if (strcmp(argv[h + 1], "G.729.2") == 0) { strcpy(codec, "G.729"); framesize = 10.0; samples = 2.0; pkts = 50.0; } else if (strcmp(argv[h + 1], "G.729.3") == 0) { strcpy(codec, "G.729"); framesize = 10.0; samples = 3.0; pkts = 33.0; } else if (strcmp(argv[h + 1], "G.723.1") == 0) { strcpy(codec, argv[h + 1]); framesize = 30.0; samples = 1.0; pkts = 26.0; } else ReportErrorAndExit("VoIP parser", "Invalid Codec Type", programName, flowId); h += 2; argc -= 2; break; case 'h': if (argc < 2) ReportErrorAndExit("VoIP parser", "Invalid Protocol Type", programName, flowId); if (strcmp(argv[h + 1], "RTP") == 0) header = 12.0; else if (strcmp(argv[h + 1], "CRTP") == 0) header = 2; else ReportErrorAndExit("VoIP parser", "Invalid Protocol Type (RTP or CRTP)", programName, flowId); h += 2; argc -= 2; break; case 'V': if ((argv[h][2] == 'A') && (argv[h][3] == 'D')) VAD = 0.65; else ReportErrorAndExit("VoIP parser", "Invalid Option (VAD)", programName, flowId); h += 1; argc -= 1; break; default: tail = (char *) malloc(sizeof("Unknown option ") + sizeof(argv[0])); ReportErrorAndExit("VoIP parser", strcat(strcpy(tail, "Unknown option "), argv[0]), programName, flowId); break; } } else { char temp[sizeof("What is ?") + sizeof(argv[h])]; ReportErrorAndExit("VoIP parser", strcat(strcat(strcpy(temp, "What is "), argv[0]), " ?"), programName, flowId); } } delete(*pPktSize); PktSizeDistro = pdConstant; ConstantRV = new Constant(1); *pPktSize = new SumRandom((VAD * framesize * samples) * (*ConstantRV) + header); delete(*pIntArriv); IntArrivDistro = pdConstant; ConstantRV = new Constant(1); *pIntArriv = new SumRandom(1000.0 / pkts * (*ConstantRV)); printf ("Voice Codec: %s\t\nFramesize: %4.2f\t\nSamples: %4.0f\t\nPackets per sec.: %4.0f\t\n", codec, framesize, samples, pkts); if (VAD == 1) printf("VAD: No\n"); else printf("VAD: Si\n"); }
void NotifyAll() { int result = pthread_cond_broadcast( &m_CV ); if(result != 0) { ReportErrorAndExit( result, "pthread_cond_broadcast" ); } }
void NotifyOne() { int result = pthread_cond_signal( &m_CV ); if(result != 0) { ReportErrorAndExit( result, "pthread_cond_signal" ); } }
virtual ~TCConditionVariableImpl() { int result = pthread_cond_destroy( &m_CV ); if(result != 0) { ReportErrorAndExit(result, "pthread_cond_destroy"); } }
TCConditionVariableImpl() { int result = pthread_cond_init( &m_CV, NULL ); if(result != 0) { ReportErrorAndExit(result, "pthread_cond_init"); } }
virtual ~TCLockImpl() { int result = pthread_mutex_unlock( m_MutexPtr ); if(result != 0) { ReportErrorAndExit(result, "pthread_mutex_unlock"); } }
virtual ~TCMutexImpl() { int result = pthread_mutex_destroy( &m_Mutex ); if(result != 0) { ReportErrorAndExit(result, "pthread_mutex_destroy"); } }
TCMutexImpl() : TCThreadBaseImpl() { int result = pthread_mutex_init( &m_Mutex, NULL ); if(result != 0) { ReportErrorAndExit(result, "pthread_mutex_init"); } }