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
68XThread::~XThread( )68XThread::~XThread( )
69{69{
70#if defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__)70#if defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__)
71 // cant terminate self71 // can't self-terminate (much like the Terminator)
72 bool is_self_thread = (thread != pthread_self());72 bool is_self_thread = (thread == pthread_self());
73#elif defined(__PLATFORM_WIN32__)73#elif defined(__PLATFORM_WIN32__)
74 // ignore for now74 // ignore for now
75 bool is_self_thread = false;75 bool is_self_thread = false;
76#endif76#endif
77 77
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 )
79 {80 {
80 // TODO: find an alternative for Android?81 // TODO: find an alternative for Android?
81#if defined(__PLATFORM_MACOSX__) || ( defined(__PLATFORM_LINUX__) && !defined(__ANDROID__) ) || defined(__WINDOWS_PTHREAD__)82#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() );
82 pthread_cancel(thread);85 pthread_cancel(thread);
83 pthread_join(thread, NULL);86 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() );
84#elif defined(__PLATFORM_WIN32__)89#elif defined(__PLATFORM_WIN32__)
85 TerminateThread((HANDLE)thread, 0);90 TerminateThread((HANDLE)thread, 0);
86#endif91#endif
@@ -121,9 +126,11 @@ bool XThread::wait( long milliseconds, bool cancel ) · 34 unmodified lines
121 bool result = false;126 bool result = false;
122 127
123 // TODO: find an alternative for Android?128 // TODO: find an alternative for Android?
124#if ( defined(__PLATFORM_MACOSX__) || ( defined(__PLATFORM_LINUX__) && !defined(__ANDROID__) ) || defined(__WINDOWS_PTHREAD__) )129#if( defined(__PLATFORM_MACOSX__) || ( defined(__PLATFORM_LINUX__) && !defined(__ANDROID__) ) || defined(__WINDOWS_PTHREAD__) )
125 if(cancel) pthread_cancel(thread);130 // cancel the thread?
126 pthread_join(thread, NULL);131 if( cancel ) pthread_cancel( thread );
132 // wait for the thread to terminate
133 pthread_join( thread, NULL );
127#elif defined(__PLATFORM_WIN32__)134#elif defined(__PLATFORM_WIN32__)
128 DWORD timeout, retval;135 DWORD timeout, retval;
129 if( milliseconds < 0 ) timeout = INFINITE;136 if( milliseconds < 0 ) timeout = INFINITE;
@@ -279,11 +286,20 @@ XWriteThread::~XWriteThread() · 149 unmodified lines
279//-----------------------------------------------------------------------------286//-----------------------------------------------------------------------------
280void XWriteThread::shutdown()287void XWriteThread::shutdown()
281{288{
289 // put shutdown message into message buffer
282 Message msg;290 Message msg;
283 msg.operation = Message::SHUTDOWN;291 msg.operation = Message::SHUTDOWN;
284 m_msg_buffer->put( msg );292 m_msg_buffer->put( msg );
285 293
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
286 m_thread.wait( -1, false );300 m_thread.wait( -1, false );
301 // log
302 EM_log( CK_LOG_FINEST, "done waiting for thread: %d", (t_CKUINT)m_thread.getThread() );
287}303}
288 304
289 305

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