Added object counter for main engine thread.

Fixed counter allocation reentrancy problem.


git-svn-id: http://yate.null.ro/svn/yate/trunk@5780 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2014-02-19 11:40:50 +00:00
parent e5cfa7a2ff
commit 11a07cc613
2 changed files with 7 additions and 1 deletions

View File

@ -238,6 +238,7 @@ static String s_startMsg;
static SharedVars s_vars; static SharedVars s_vars;
static Mutex s_hooksMutex(true,"HooksList"); static Mutex s_hooksMutex(true,"HooksList");
static ObjList s_hooks; static ObjList s_hooks;
static NamedCounter* s_counter = 0;
const TokenDict Engine::s_callAccept[] = { const TokenDict Engine::s_callAccept[] = {
{"accept", Engine::Accept}, {"accept", Engine::Accept},
@ -867,12 +868,14 @@ static bool logFileOpen()
} }
return false; return false;
} }
static int engineRun(EngineLoop loop = 0) static int engineRun(EngineLoop loop = 0)
{ {
time_t t = ::time(0); time_t t = ::time(0);
s_startMsg << "Yate (" << ::getpid() << ") is starting " << ::ctime(&t); s_startMsg << "Yate (" << ::getpid() << ") is starting " << ::ctime(&t);
s_startMsg.trimSpaces(); s_startMsg.trimSpaces();
Output("%s",s_startMsg.c_str()); Output("%s",s_startMsg.c_str());
Thread::setCurrentObjCounter((s_counter = GenObject::getObjCounter("engine")));
int retcode = Engine::self()->engineInit(); int retcode = Engine::self()->engineInit();
if (!retcode) if (!retcode)
retcode = (loop ? loop() : Engine::self()->run()); retcode = (loop ? loop() : Engine::self()->run());

View File

@ -881,8 +881,11 @@ NamedCounter* GenObject::getObjCounter(const String& name, bool create)
return 0; return 0;
Lock mylock(s_countersMutex); Lock mylock(s_countersMutex);
NamedCounter* cnt = static_cast<NamedCounter*>(s_counters[name]); NamedCounter* cnt = static_cast<NamedCounter*>(s_counters[name]);
if (create && !cnt) if (create && !cnt) {
NamedCounter* saved = Thread::setCurrentObjCounter(0);
s_counters.append(cnt = new NamedCounter(name)); s_counters.append(cnt = new NamedCounter(name));
Thread::setCurrentObjCounter(saved);
}
return cnt; return cnt;
} }