mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
introduce thread naming
This commit is contained in:
parent
cbef01451c
commit
b3fece25da
@ -30,7 +30,7 @@ RsControlModule::RsControlModule(int argc, char **argv, StateTokenServer* sts, A
|
|||||||
this->argv = argv;
|
this->argv = argv;
|
||||||
// start worker thread
|
// start worker thread
|
||||||
if(full_control)
|
if(full_control)
|
||||||
start();
|
start("RS ctrl module");
|
||||||
else
|
else
|
||||||
mRunState = RUNNING_OK_NO_FULL_CONTROL;
|
mRunState = RUNNING_OK_NO_FULL_CONTROL;
|
||||||
|
|
||||||
|
@ -188,19 +188,18 @@ void ftServer::StartupThreads()
|
|||||||
|
|
||||||
/* self contained threads */
|
/* self contained threads */
|
||||||
/* startup ExtraList Thread */
|
/* startup ExtraList Thread */
|
||||||
mFtExtra->start();
|
mFtExtra->start("RS ft extra lst");
|
||||||
|
|
||||||
/* startup Monitor Thread */
|
/* startup Monitor Thread */
|
||||||
/* startup the FileMonitor (after cache load) */
|
/* startup the FileMonitor (after cache load) */
|
||||||
/* start it up */
|
/* start it up */
|
||||||
|
mFiMon->start("RS ft monitor");
|
||||||
mFiMon->start();
|
|
||||||
|
|
||||||
/* Controller thread */
|
/* Controller thread */
|
||||||
mFtController->start();
|
mFtController->start("RS ft ctrl");
|
||||||
|
|
||||||
/* Dataplex */
|
/* Dataplex */
|
||||||
mFtDataplex->start();
|
mFtDataplex->start("RS ft dataplex");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ftServer::StopThreads()
|
void ftServer::StopThreads()
|
||||||
|
@ -83,6 +83,7 @@ RsThread::RsThread()
|
|||||||
mHasStoppedSemaphore.set(1) ;
|
mHasStoppedSemaphore.set(1) ;
|
||||||
mShouldStopSemaphore.set(0) ;
|
mShouldStopSemaphore.set(0) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsThread::isRunning()
|
bool RsThread::isRunning()
|
||||||
{
|
{
|
||||||
// do we need a mutex for this ?
|
// do we need a mutex for this ?
|
||||||
@ -142,7 +143,8 @@ void RsTickingThread::fullstop()
|
|||||||
THREAD_DEBUG << " finished!" << std::endl;
|
THREAD_DEBUG << " finished!" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
void RsThread::start()
|
|
||||||
|
void RsThread::start(const std::string &threadName)
|
||||||
{
|
{
|
||||||
pthread_t tid;
|
pthread_t tid;
|
||||||
void *data = (void *)this ;
|
void *data = (void *)this ;
|
||||||
@ -158,11 +160,27 @@ void RsThread::start()
|
|||||||
// -> the new thread will see mIsRunning() = true
|
// -> the new thread will see mIsRunning() = true
|
||||||
|
|
||||||
if( 0 == (err=pthread_create(&tid, 0, &rsthread_init, data)))
|
if( 0 == (err=pthread_create(&tid, 0, &rsthread_init, data)))
|
||||||
|
{
|
||||||
mTid = tid;
|
mTid = tid;
|
||||||
|
|
||||||
|
// set name
|
||||||
|
if(!threadName.empty()) {
|
||||||
|
// thread names are restricted to 16 characters including the terminating null byte
|
||||||
|
if(threadName.length() > 15)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_THREADS
|
||||||
|
THREAD_DEBUG << "RsThread::start called with to long name '" << name << "' truncating..." << std::endl;
|
||||||
|
#endif
|
||||||
|
pthread_setname_np(mTid, threadName.substr(0, 15).c_str());
|
||||||
|
} else {
|
||||||
|
pthread_setname_np(mTid, threadName.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
THREAD_DEBUG << "Fatal error: pthread_create could not create a thread. Error returned: " << err << " !!!!!!!" << std::endl;
|
THREAD_DEBUG << "Fatal error: pthread_create could not create a thread. Error returned: " << err << " !!!!!!!" << std::endl;
|
||||||
mHasStoppedSemaphore.set(1) ;
|
mHasStoppedSemaphore.set(1) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ class RsThread
|
|||||||
RsThread();
|
RsThread();
|
||||||
virtual ~RsThread() {}
|
virtual ~RsThread() {}
|
||||||
|
|
||||||
void start() ;
|
void start(const std::string &threadName = "");
|
||||||
|
|
||||||
// Returns true of the thread is still running.
|
// Returns true of the thread is still running.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user