History

fixed self thread check in XThread destructor; fine grain logs

Ge Wang committed 5 years ago

Commit 81dbbf41 parent 57a94986 files · +53 −18Browse files

Showing the changes to src/core/util_thread.cpp (1 of 6 files). Show all

Unified · Split

src/core/util_thread.cpp+22−6
@@ -68,19 +68,24 @@ XThread::XThread( ) · 67 unmodified lines
6868 XThread::~XThread( )
6969 {
7070 #if defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__)
71− // cant terminate self
72− bool is_self_thread = (thread != pthread_self());
71+ // can't self-terminate (much like the Terminator)
72+ bool is_self_thread = (thread == pthread_self());
7373 #elif defined(__PLATFORM_WIN32__)
7474 // ignore for now
7575 bool is_self_thread = false;
7676 #endif
7777
78− if( thread != 0 && !is_self_thread)
78+ // if our thread not NULL and this destructor is NOT being called on it
79+ if( thread != 0 && !is_self_thread )
7980 {
8081 // TODO: find an alternative for Android?
8182 #if defined(__PLATFORM_MACOSX__) || ( defined(__PLATFORM_LINUX__) && !defined(__ANDROID__) ) || defined(__WINDOWS_PTHREAD__)
83+ // log
84+ EM_log( CK_LOG_FINEST, "cancelling XThread: %d on thread: %d", (t_CKUINT)thread, (t_CKUINT)pthread_self() );
8285 pthread_cancel(thread);
8386 pthread_join(thread, NULL);
87+ // log
88+ EM_log( CK_LOG_FINEST, "joined with XThread: %d on thread: %d", (t_CKUINT)thread, (t_CKUINT)pthread_self() );
8489 #elif defined(__PLATFORM_WIN32__)
8590 TerminateThread((HANDLE)thread, 0);
8691 #endif
@@ -121,9 +126,11 @@ bool XThread::wait( long milliseconds, bool cancel ) · 34 unmodified lines
121126 bool result = false;
122127
123128 // TODO: find an alternative for Android?
124−#if ( defined(__PLATFORM_MACOSX__) || ( defined(__PLATFORM_LINUX__) && !defined(__ANDROID__) ) || defined(__WINDOWS_PTHREAD__) )
125− if(cancel) pthread_cancel(thread);
126− pthread_join(thread, NULL);
129+#if( defined(__PLATFORM_MACOSX__) || ( defined(__PLATFORM_LINUX__) && !defined(__ANDROID__) ) || defined(__WINDOWS_PTHREAD__) )
130+ // cancel the thread?
131+ if( cancel ) pthread_cancel( thread );
132+ // wait for the thread to terminate
133+ pthread_join( thread, NULL );
127134 #elif defined(__PLATFORM_WIN32__)
128135 DWORD timeout, retval;
129136 if( milliseconds < 0 ) timeout = INFINITE;
@@ -279,11 +286,20 @@ XWriteThread::~XWriteThread() · 149 unmodified lines
279286 //-----------------------------------------------------------------------------
280287 void XWriteThread::shutdown()
281288 {
289+ // put shutdown message into message buffer
282290 Message msg;
283291 msg.operation = Message::SHUTDOWN;
284292 m_msg_buffer->put( msg );
285293
294+ // smart log push
295+ SmartPushLog logPush;
296+
297+ // log
298+ EM_log( CK_LOG_FINEST, "waiting on write thread: %d", (t_CKUINT)m_thread.getThread() );
299+ // wait on the thread
286300 m_thread.wait( -1, false );
301+ // log
302+ EM_log( CK_LOG_FINEST, "done waiting for thread: %d", (t_CKUINT)m_thread.getThread() );
287303 }
288304
289305

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t