From: Nick Holland Date: Tue, 7 Jul 2015 11:19:14 +0000 (+0100) Subject: Boost removal from performance server X-Git-Tag: dali_1.0.49~5^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;ds=sidebyside;h=1df589a4107d47e3eadca3e74534ebd374969785;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git Boost removal from performance server Change-Id: Ia02b511bfc33e101b2eccbed57cc71fe67d6a0b6 --- diff --git a/adaptors/base/performance-logging/networking/network-performance-client.cpp b/adaptors/base/performance-logging/networking/network-performance-client.cpp index f11d825..27fb07a 100644 --- a/adaptors/base/performance-logging/networking/network-performance-client.cpp +++ b/adaptors/base/performance-logging/networking/network-performance-client.cpp @@ -116,12 +116,14 @@ private: } // unnamed namespace -NetworkPerformanceClient::NetworkPerformanceClient( SocketInterface *socket, +NetworkPerformanceClient::NetworkPerformanceClient( pthread_t* thread, + SocketInterface *socket, unsigned int clientId, TriggerEventFactoryInterface& triggerEventFactory, ClientSendDataInterface& sendDataInterface, SocketFactoryInterface& socketFactory ) -: mSocket( socket ), +: mThread( thread ), + mSocket( socket ), mMarkerBitmask( PerformanceMarker::FILTERING_DISABLED ), mTriggerEventFactory( triggerEventFactory ), mSendDataInterface( sendDataInterface ), @@ -184,6 +186,10 @@ void NetworkPerformanceClient::ExitSelect() mSocket->ExitSelect(); } +pthread_t* NetworkPerformanceClient::GetThread() +{ + return mThread; +} void NetworkPerformanceClient::ProcessCommand( char* buffer, unsigned int bufferSizeInBytes ) { diff --git a/adaptors/base/performance-logging/networking/network-performance-client.h b/adaptors/base/performance-logging/networking/network-performance-client.h index 646b594..d9ea2c9 100644 --- a/adaptors/base/performance-logging/networking/network-performance-client.h +++ b/adaptors/base/performance-logging/networking/network-performance-client.h @@ -18,16 +18,15 @@ * */ +// EXTERNAL INCLUDES +#include + // INTERNAL INCLUDES #include #include #include #include -namespace boost -{ -class thread; -} namespace Dali { @@ -62,13 +61,15 @@ public: /** * @brief Constructor + * @param thread thread pointer * @param socket socket interface * @param clientId unique client id * @param triggerEventFactory used to create trigger events * @param sendDataInterface used to send data to the socket from main thread * @param SocketFactoryInterface used to delete the socket when the client is destroyed */ - NetworkPerformanceClient( SocketInterface *socket, + NetworkPerformanceClient( pthread_t* thread, + SocketInterface *socket, unsigned int clientId, TriggerEventFactoryInterface& triggerEventFactory, ClientSendDataInterface& sendDataInterface, @@ -114,8 +115,15 @@ public: */ void ExitSelect(); + /** + * @brief get the thread running the client + * @return thread pointer + */ + pthread_t* GetThread(); + private: + pthread_t* mThread; ///< thread for the client SocketInterface* mSocket; ///< socket interface PerformanceMarker::MarkerFilter mMarkerBitmask; ///< What markers are currently filtered TriggerEventFactoryInterface& mTriggerEventFactory; ///< Trigger event factory diff --git a/adaptors/base/performance-logging/networking/network-performance-server.cpp b/adaptors/base/performance-logging/networking/network-performance-server.cpp index dbbd3e6..4d86afb 100644 --- a/adaptors/base/performance-logging/networking/network-performance-server.cpp +++ b/adaptors/base/performance-logging/networking/network-performance-server.cpp @@ -18,8 +18,6 @@ // CLASS HEADER #include "network-performance-server.h" -// EXTERNAL INCLUDES -#include // INTERNAL INCLUDES #include @@ -40,6 +38,15 @@ const unsigned int MAXIMUM_PORTS_TO_TRY = 10; ///< if port in use, try up to SER const unsigned int CONNECTION_BACKLOG = 2; ///< maximum length of the queue of pending connections. const unsigned int SOCKET_READ_BUFFER_SIZE = 4096; typedef Vector< NetworkPerformanceClient*> ClientList; + +/** + * POD passed to client thread on startup + */ +struct ClientThreadInfo +{ + NetworkPerformanceServer* server; + NetworkPerformanceClient* client; +}; } NetworkPerformanceServer::NetworkPerformanceServer( AdaptorInternalServices& adaptorServices, @@ -47,7 +54,7 @@ NetworkPerformanceServer::NetworkPerformanceServer( AdaptorInternalServices& ada : mTriggerEventFactory( adaptorServices.GetTriggerEventFactoryInterface() ), mSocketFactory( adaptorServices.GetSocketFactoryInterface() ), mLogOptions( logOptions ), - mServerThread( NULL ), + mServerThread( 0 ), mListeningSocket( NULL ), mClientUniqueId( 0 ), mClientCount( 0 ), @@ -99,7 +106,8 @@ void NetworkPerformanceServer::Start() mListeningSocket->Listen( CONNECTION_BACKLOG ); // start a thread which will block waiting for new connections - mServerThread = new boost::thread(boost::bind(&NetworkPerformanceServer::ConnectionListener, this)); + int error = pthread_create( &mServerThread, NULL, ConnectionListenerFunc, this ); + DALI_ASSERT_ALWAYS( !error && "pthread create failed" ); Dali::Integration::Log::LogMessage(Integration::Log::DebugInfo, "~~~ NetworkPerformanceServer started on port %d ~~~ \n", SERVER_PORT + basePort); @@ -115,29 +123,19 @@ void NetworkPerformanceServer::Stop() mListeningSocket->ExitSelect(); // wait for the thread to exit. - mServerThread->join(); + void* exitValue; + pthread_join( mServerThread, &exitValue ); // close the socket mListeningSocket->CloseSocket(); - delete mServerThread; mSocketFactory.DestroySocket( mListeningSocket ); - mServerThread = NULL; mListeningSocket = NULL; // this will tell all client threads to quit StopClients(); - // wait for all threads to exit and the client count to hit zero - { - boost::mutex::scoped_lock lock(mClientListMutex); - - while (mClientCount != 0) - { - mClientCountUpdated.wait(lock); - } - } } bool NetworkPerformanceServer::IsRunning() const @@ -205,8 +203,17 @@ void NetworkPerformanceServer::ConnectionListener() SocketInterface* clientSocket = mListeningSocket->Accept(); // new connection made, spawn a thread to handle it - NetworkPerformanceClient* client = AddClient( clientSocket ); - new boost::thread(boost::bind(&NetworkPerformanceServer::ClientThread, this, client)); + pthread_t* clientThread = new pthread_t(); + + NetworkPerformanceClient* client = AddClient( clientSocket, clientThread ); + + ClientThreadInfo* info = new ClientThreadInfo; + info->client = client; + info->server = this; + + int error = pthread_create( clientThread, NULL, ClientThreadFunc, info ); + DALI_ASSERT_ALWAYS( !error && "pthread create failed" ); + } else // ret == SocketInterface::QUIT or SocketInterface::ERROR { @@ -215,17 +222,26 @@ void NetworkPerformanceServer::ConnectionListener() } } -NetworkPerformanceClient* NetworkPerformanceServer::AddClient( SocketInterface* clientSocket ) +void* NetworkPerformanceServer::ClientThreadFunc( void* data ) +{ + ClientThreadInfo* info = static_cast( data ); + info->server->ClientThread( info->client ); + delete info; + return NULL; +} + +NetworkPerformanceClient* NetworkPerformanceServer::AddClient( SocketInterface* clientSocket, pthread_t* clientThread ) { // This function is only called from the listening thread - NetworkPerformanceClient* client= new NetworkPerformanceClient(clientSocket, - mClientUniqueId++, - mTriggerEventFactory, - *this, - mSocketFactory); + NetworkPerformanceClient* client= new NetworkPerformanceClient( clientThread, + clientSocket, + mClientUniqueId++, + mTriggerEventFactory, + *this, + mSocketFactory); // protect the mClients list which can be accessed from multiple threads. - boost::mutex::scoped_lock sharedDatalock( mClientListMutex ); + Mutex::ScopedLock lock( mClientListMutex ); mClients.PushBack( client ); @@ -235,7 +251,7 @@ NetworkPerformanceClient* NetworkPerformanceServer::AddClient( SocketInterface* void NetworkPerformanceServer::DeleteClient( NetworkPerformanceClient* client ) { // protect the mClients list while modifying - boost::mutex::scoped_lock sharedDatalock( mClientListMutex ); + Mutex::ScopedLock lock( mClientListMutex ); // remove from the list, and delete it for( ClientList::Iterator iter = mClients.Begin(); iter != mClients.End() ; ++iter ) @@ -248,8 +264,6 @@ void NetworkPerformanceServer::DeleteClient( NetworkPerformanceClient* client ) // if there server is shutting down, it waits for client count to hit zero mClientCount--; - // lets the server know the client count has been modified - mClientCountUpdated.notify_one(); return; } } @@ -263,7 +277,7 @@ void NetworkPerformanceServer::SendData( const char* const data, unsigned int bu } // prevent clients been added / deleted while transmiting data - boost::mutex::scoped_lock sharedDatalock( mClientListMutex ); + Mutex::ScopedLock lock( mClientListMutex ); for( ClientList::Iterator iter = mClients.Begin(); iter != mClients.End() ; ++iter ) { @@ -283,7 +297,7 @@ void NetworkPerformanceServer::TransmitMarker( const PerformanceMarker& marker, return; } // prevent clients been added / deleted while transmiting data - boost::mutex::scoped_lock sharedDatalock( mClientListMutex ); + Mutex::ScopedLock lock( mClientListMutex ); for( ClientList::Iterator iter = mClients.Begin(); iter != mClients.End() ; ++iter ) { @@ -296,13 +310,19 @@ void NetworkPerformanceServer::TransmitMarker( const PerformanceMarker& marker, void NetworkPerformanceServer::StopClients() { // prevent clients been added / deleted while stopping all clients - boost::mutex::scoped_lock sharedDatalock( mClientListMutex ); + Mutex::ScopedLock lock( mClientListMutex ); for( ClientList::Iterator iter = mClients.Begin(); iter != mClients.End() ; ++iter ) { NetworkPerformanceClient* client = (*iter); // stop the client from waiting for new commands, and exit from it's thread client->ExitSelect(); + + void* exitValue; + pthread_t* thread = client->GetThread(); + pthread_join( *thread, &exitValue ); + delete thread; + } } diff --git a/adaptors/base/performance-logging/networking/network-performance-server.h b/adaptors/base/performance-logging/networking/network-performance-server.h index 95bdd8b..6cff347 100644 --- a/adaptors/base/performance-logging/networking/network-performance-server.h +++ b/adaptors/base/performance-logging/networking/network-performance-server.h @@ -19,8 +19,8 @@ */ // EXTERNAL INCLUDES -#include -#include +#include +#include #include // INTERNAL INCLUDES @@ -28,11 +28,6 @@ #include #include - -namespace boost -{ -class thread; -} namespace Dali { @@ -115,6 +110,23 @@ protected: // ClientSendDataInterface virtual void SendData( const char* const data, unsigned int bufferSizeInBytes, unsigned int clientId ); private: + + /** + * Helper for the thread calling the entry function. + * @param[in] This A pointer to the current RenderThread object + */ + static void* ConnectionListenerFunc( void* This ) + { + ( static_cast( This ) )->ConnectionListener(); + return NULL; + } + + /** + * Helper for the thread calling the entry function. + * @param[in] This A pointer to the current RenderThread object + */ + static void* ClientThreadFunc( void* data ); + /** * @brief Client thread function * @param client network client object @@ -134,9 +146,10 @@ private: /** * @brief Add a new client to the client list * @param clientSocket client socket + * @param clientThread client thread * @return client */ - NetworkPerformanceClient* AddClient( SocketInterface* clientSocket ); + NetworkPerformanceClient* AddClient( SocketInterface* clientSocket, pthread_t* clientThread ); /** * @brief Delete a client from the client list @@ -152,12 +165,11 @@ private: SocketFactoryInterface& mSocketFactory; ///< used to create sockets const EnvironmentOptions& mLogOptions; ///< log options Dali::Vector< NetworkPerformanceClient* > mClients; ///< list of connected clients - boost::thread* mServerThread; ///< thread that listens for new connections + pthread_t mServerThread; ///< thread that listens for new connections SocketInterface* mListeningSocket; ///< socket used to listen for new connections - boost::mutex mClientListMutex; ///< mutex - boost::condition_variable mClientCountUpdated; ///< used to say the client count has changed + Dali::Mutex mClientListMutex; ///< mutex unsigned int mClientUniqueId; ///< increments for every client connection - unsigned int mClientCount; ///< client count + volatile unsigned int mClientCount; ///< client count bool mLogFunctionInstalled; ///< whether the log function is installed }; diff --git a/adaptors/base/performance-logging/performance-server.cpp b/adaptors/base/performance-logging/performance-server.cpp index 1984304..5b6773f 100644 --- a/adaptors/base/performance-logging/performance-server.cpp +++ b/adaptors/base/performance-logging/performance-server.cpp @@ -119,10 +119,6 @@ void PerformanceServer::AddMarker( MarkerType markerType, ContextId contextId ) return; } - // This is only called from main event thread, but may overlap with internal AddMarker calls - // from other threads ( update, render etc). - boost::mutex::scoped_lock sharedDatalock( mDataMutex ); - // Get the time stamp unsigned int seconds = 0; unsigned int microseconds = 0; @@ -139,7 +135,6 @@ void PerformanceServer::AddMarker( MarkerType markerType, ContextId contextId ) // Add custom marker to statistics context manager mStatContextManager.AddCustomMarker( marker, contextId ); - } void PerformanceServer::AddMarker( MarkerType markerType ) @@ -151,10 +146,6 @@ void PerformanceServer::AddMarker( MarkerType markerType ) return; } - // AddMarker can be called from multiple threads, to avoid problems - // with updating contexts and the kernel trace, lock here. - boost::mutex::scoped_lock sharedDatalock( mDataMutex ); - if( markerType == VSYNC ) { // make sure log function is installed, note this will be called only from v-sync thread @@ -189,7 +180,7 @@ void PerformanceServer::LogContextStatistics( const char* const text ) void PerformanceServer::LogMarker( const PerformanceMarker& marker, const char* const description ) { - // log to the network ( this is thread safe) + // log to the network ( this is thread safe ) if( mNetworkControlEnabled ) { mNetworkServer.TransmitMarker( marker, description ); @@ -198,6 +189,8 @@ void PerformanceServer::LogMarker( const PerformanceMarker& marker, const char* // log to kernel trace if( mPerformanceOutputBitmask & OUTPUT_KERNEL_TRACE ) { + // Kernel tracing implementation may not be thread safe + Mutex::ScopedLock lock( mLogMutex ); // description will be something like UPDATE_START or UPDATE_END mKernelTrace.Trace( marker, description ); } @@ -205,10 +198,13 @@ void PerformanceServer::LogMarker( const PerformanceMarker& marker, const char* // log to system trace if( mPerformanceOutputBitmask & OUTPUT_SYSTEM_TRACE ) { + // System tracing implementation may not be thread safe + Mutex::ScopedLock lock( mLogMutex ); + mSystemTrace.Trace( marker, description ); } - // log to Dali log + // log to Dali log ( this is thread safe ) if ( mPerformanceOutputBitmask & OUTPUT_DALI_LOG ) { Integration::Log::LogMessage( Dali::Integration::Log::DebugInfo, diff --git a/adaptors/base/performance-logging/performance-server.h b/adaptors/base/performance-logging/performance-server.h index b3b5062..8c71900 100644 --- a/adaptors/base/performance-logging/performance-server.h +++ b/adaptors/base/performance-logging/performance-server.h @@ -20,6 +20,7 @@ // EXTERNAL INCLDUES #include +#include // INTERNAL INCLUDES #include @@ -120,7 +121,7 @@ private: const EnvironmentOptions& mEnvironmentOptions; ///< environment options TraceInterface& mKernelTrace; ///< kernel trace interface TraceInterface& mSystemTrace; ///< system trace interface - boost::mutex mDataMutex; ///< mutex + Dali::Mutex mLogMutex; ///< mutex NetworkPerformanceServer mNetworkServer; ///< network server StatContextManager mStatContextManager; ///< Stat context manager unsigned int mStatisticsLogBitmask; ///< statistics log level diff --git a/adaptors/base/performance-logging/statistics/stat-context-manager.cpp b/adaptors/base/performance-logging/statistics/stat-context-manager.cpp index 22a67d1..bdc86ec 100644 --- a/adaptors/base/performance-logging/statistics/stat-context-manager.cpp +++ b/adaptors/base/performance-logging/statistics/stat-context-manager.cpp @@ -88,6 +88,7 @@ void StatContextManager::AddInternalMarker( const PerformanceMarker& marker ) { // log to the stat contexts, can be called from multiple threads so we // protect the data + Mutex::ScopedLock lock( mDataMutex ); for( StatContexts::Iterator it = mStatContexts.Begin(), itEnd = mStatContexts.End(); it != itEnd; ++it ) { StatContext* context = *it; @@ -99,6 +100,7 @@ void StatContextManager::AddCustomMarker( const PerformanceMarker& marker, Perfo { // log to the stat contexts, can be called from multiple threads so we // protect the data + Mutex::ScopedLock lock( mDataMutex ); StatContext* context = GetContext( contextId ); if( context ) { diff --git a/adaptors/base/performance-logging/statistics/stat-context-manager.h b/adaptors/base/performance-logging/statistics/stat-context-manager.h index 49242a0..1252eee 100644 --- a/adaptors/base/performance-logging/statistics/stat-context-manager.h +++ b/adaptors/base/performance-logging/statistics/stat-context-manager.h @@ -18,6 +18,9 @@ * */ +// EXTERNAL INCLUDES +#include + // INTERNAL INCLUDES #include #include @@ -138,6 +141,7 @@ public: */ StatContext* GetContext( PerformanceInterface::ContextId contextId ) const; + Dali::Mutex mDataMutex; ///< mutex StatContexts mStatContexts; ///< The list of stat contexts StatContextLogInterface& mLogInterface; ///< Log interface