for bug-searching:

set frontend type before starting the thread. This means that the thread type will be output correctly in the error message.

return errno string of pthread functions called in thread start
This commit is contained in:
Bernhard Amann 2012-06-25 14:54:15 -07:00
parent c3b9a2a29c
commit c7338a0731
3 changed files with 14 additions and 9 deletions

View file

@ -255,10 +255,10 @@ ReaderBackend* Manager::CreateBackend(ReaderFrontend* frontend, bro_int_t type)
assert(ir->factory);
frontend->ty_name = ir->name;
ReaderBackend* backend = (*ir->factory)(frontend);
assert(backend);
frontend->ty_name = ir->name;
return backend;
}

View file

@ -191,10 +191,10 @@ WriterBackend* Manager::CreateBackend(WriterFrontend* frontend, bro_int_t type)
assert(ld->factory);
frontend->ty_name = ld->name;
WriterBackend* backend = (*ld->factory)(frontend);
assert(backend);
frontend->ty_name = ld->name;
return backend;
}

View file

@ -80,18 +80,23 @@ const char* BasicThread::Fmt(const char* format, ...)
void BasicThread::Start()
{
int err;
if ( started )
return;
if ( pthread_mutex_init(&terminate, 0) != 0 )
reporter->FatalError("Cannot create terminate mutex for thread %s", name.c_str());
err = pthread_mutex_init(&terminate, 0);
if ( err != 0 )
reporter->FatalError("Cannot create terminate mutex for thread %s:%s", name.c_str(), strerror(err));
// We use this like a binary semaphore and acquire it immediately.
if ( pthread_mutex_lock(&terminate) != 0 )
reporter->FatalError("Cannot aquire terminate mutex for thread %s", name.c_str());
if ( pthread_create(&pthread, 0, BasicThread::launcher, this) != 0 )
reporter->FatalError("Cannot create thread %s", name.c_str());
err = pthread_mutex_lock(&terminate);
if ( err != 0 )
reporter->FatalError("Cannot aquire terminate mutex for thread %s:%s", name.c_str(), strerror(err));
err = pthread_create(&pthread, 0, BasicThread::launcher, this);
if ( err != 0 )
reporter->FatalError("Cannot create thread %s:%s", name.c_str(), strerror(err));
DBG_LOG(DBG_THREADING, "Started thread %s", name.c_str());