Commit 1b62ddd2 authored by Martin Karsten's avatar Martin Karsten

- reorganize init sequence for more robust statistics printing

parent 04218d80
......@@ -17,6 +17,7 @@
#include "libfibre/fibre.h"
#include <atomic>
#include <iostream>
#include <cxxabi.h> // see _lfAbort
#include <execinfo.h> // see _lfAbort
......@@ -48,32 +49,45 @@ static const char* DebugOptions[] = {
static_assert(sizeof(DebugOptions)/sizeof(char*) == DBG::Level::MaxLevel, "debug options mismatch");
static std::atomic<int> initCounter(0);
// bootstrap definitions
static std::atomic<int> _bootstrapCounter(0);
#if TESTING_ENABLE_STATISTICS
static std::ios ioFormatFlags(NULL);
#endif
static void FibreCleanup() {
#if TESTING_ENABLE_STATISTICS
std::cout.copyfmt(ioFormatFlags);
StatsObject::printAll(std::cout);
delete StatsObject::lst;
#endif
}
EventScope* FibreInit(size_t pollerCount, size_t workerCount) {
if (++initCounter == 1) {
_Bootstrapper::_Bootstrapper() {
if (++_bootstrapCounter == 1) {
#if TESTING_ENABLE_STATISTICS
ioFormatFlags.copyfmt(std::cout);
StatsObject::lst = new IntrusiveQueue<StatsObject>;
#endif
// register cleanup routine
SYSCALL(atexit(FibreCleanup));
// bootstrap system via event scope
char* env = getenv("FibreDebugString");
if (env) DBG::init(DebugOptions, env, false);
}
}
_Bootstrapper::~_Bootstrapper() {
if (--_bootstrapCounter == 0) {
#if TESTING_ENABLE_STATISTICS
if (StatsObject::lst) {
std::cout.copyfmt(ioFormatFlags);
StatsObject::printAll(std::cout);
delete StatsObject::lst;
}
#endif
}
}
static struct _Bootstrapper2 {
_Bootstrapper2() {
#if TESTING_ENABLE_STATISTICS
ioFormatFlags.copyfmt(std::cout); // doing this during _Bootstrapper::_Bootstrapper() is too early
#endif
}
} _lfBootstrap2;
// definition here ensures that boot strapper object has been created
EventScope* FibreInit(size_t pollerCount, size_t workerCount) {
return EventScope::bootstrap(pollerCount, workerCount);
}
......
......@@ -23,7 +23,14 @@
#define __LIBFIBRE__ 1
#endif
#include "libfibre/EventScope.h" // EventScope.h pulls in everything else
// bootstrap object needs to come first
static struct _Bootstrapper {
_Bootstrapper();
~_Bootstrapper();
} _lfBootstrap;
// EventScope.h pulls in everything else
#include "libfibre/EventScope.h"
typedef TaskLock FibreMutex;
typedef TaskCondition FibreCondition;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment