|
From: Josh A. <axl...@us...> - 2009-04-17 11:21:43
|
Update of /cvsroot/hgengine/Mercury/src In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv3356 Modified Files: MercuryThreads.h MercuryThreads.cpp Log Message: update to mercury 2 threads Index: MercuryThreads.h =================================================================== RCS file: /cvsroot/hgengine/Mercury/src/MercuryThreads.h,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** MercuryThreads.h 1 Sep 2007 23:55:51 -0000 1.15 --- MercuryThreads.h 17 Apr 2009 11:21:38 -0000 1.16 *************** *** 2,6 **** #define _MERCURY_THREADS_H ! #include "MercuryString.h" #if !defined(WIN32) --- 2,7 ---- #define _MERCURY_THREADS_H ! #include <MercuryString.h> ! #if !defined(WIN32) *************** *** 23,27 **** ///Create a thread of function fn and pass it data *data. ! int Create( void * (*fn)(void *), void *data ); ///Wait for the thread to complete. --- 24,28 ---- ///Create a thread of function fn and pass it data *data. ! int Create( void * (*fn)(void *), void *data, bool detach = true ); ///Wait for the thread to complete. *************** *** 37,43 **** --- 38,47 ---- void Close( ); + // inline void Exit() { pthread_exit(NULL); } + inline void HaltOnDestroy(bool t) { m_haltOnDestroy = t; } private: MString m_name; + bool m_haltOnDestroy; #if defined(WIN32) StartThreadData *mkThreadData; Index: MercuryThreads.cpp =================================================================== RCS file: /cvsroot/hgengine/Mercury/src/MercuryThreads.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** MercuryThreads.cpp 2 Sep 2007 00:12:52 -0000 1.22 --- MercuryThreads.cpp 17 Apr 2009 11:21:38 -0000 1.23 *************** *** 1,4 **** ! #include "global.h" ! #include "MercuryThreads.h" #if defined( WIN32 ) --- 1,3 ---- ! #include <MercuryThreads.h> #if defined( WIN32 ) *************** *** 9,13 **** MercuryThread::MercuryThread() ! :m_name("(null)"), m_thread(0) { #if defined( WIN32 ) --- 8,12 ---- MercuryThread::MercuryThread() ! :m_name("(null)"), m_haltOnDestroy(true), m_thread(0) { #if defined( WIN32 ) *************** *** 17,21 **** MercuryThread::MercuryThread( const MString &name ) ! :m_name(name), m_thread(0) { #if defined( WIN32 ) --- 16,20 ---- MercuryThread::MercuryThread( const MString &name ) ! :m_name(name), m_haltOnDestroy(true), m_thread(0) { #if defined( WIN32 ) *************** *** 46,50 **** #endif ! int MercuryThread::Create( void * (*fn)(void *), void *data ) { #if defined( WIN32 ) --- 45,49 ---- #endif ! int MercuryThread::Create( void * (*fn)(void *), void *data, bool detach ) { #if defined( WIN32 ) *************** *** 60,64 **** --- 59,67 ---- return false; else + { + if (detach) + pthread_detach( m_thread ); //reclaim memory on thread destruction return true; + } #endif } *************** *** 74,79 **** return SuspendThread( m_thread ); #else ! pthread_detach( m_thread ); //reclaim memory on thread destruction ! pthread_cancel( m_thread ); #endif } --- 77,83 ---- return SuspendThread( m_thread ); #else ! // pthread_detach( m_thread ); //reclaim memory on thread destruction ! if (pthread_equal(pthread_self(), m_thread) != 0) { pthread_exit(NULL); } ! else { pthread_cancel( m_thread ); } #endif } *************** *** 102,110 **** void MercuryThread::Close( ) { ! if ( m_thread ) { Halt( true ); #if defined( WIN32 ) ! SAFE_DELETE( mkThreadData ); CloseHandle( m_thread ); m_thread = NULL; --- 106,116 ---- void MercuryThread::Close( ) { ! if ( m_thread && m_haltOnDestroy) { Halt( true ); #if defined( WIN32 ) ! delete mkThreadData; ! mkThreadData = NULL; ! // SAFE_DELETE( mkThreadData ); CloseHandle( m_thread ); m_thread = NULL; *************** *** 164,167 **** --- 170,174 ---- { // printf("Unlocked %s\n", m_name.c_str()); + --iLockCount; #if defined( WIN32 ) return ReleaseMutex( m_mutex ); *************** *** 180,184 **** p->bInheritHandle = true; p->lpSecurityDescriptor = NULL; ! m_mutex = CreateMutex( p, true, m_name.c_str() ); free( p ); return (int)m_mutex; --- 187,191 ---- p->bInheritHandle = true; p->lpSecurityDescriptor = NULL; ! m_mutex = CreateMutex( p, true, (LPCWSTR)m_name.c_str() ); free( p ); return (int)m_mutex; |