From 1889b55dcbb3f5c5cccc3bcd986b13d0d108ed6c Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 27 Apr 2010 17:07:55 +0000 Subject: The Bu::Ito thread class has changed the rules on the run function. It no longer returns anything, that's fine, it's in a class, but it also is protected now. That doesn't really effect child classes much, they can make run public, but I reccomend protected to avoid confusion. --- src/ito.cpp | 6 +++--- src/ito.h | 20 ++++++++++---------- src/itoserver.cpp | 10 +++------- src/itoserver.h | 8 +++++--- src/tests/itoheap.cpp | 4 +--- src/tests/itoqueue1.cpp | 8 ++------ src/tests/itoqueue2.cpp | 8 ++------ src/tests/socketblock.cpp | 4 +--- 8 files changed, 27 insertions(+), 41 deletions(-) diff --git a/src/ito.cpp b/src/ito.cpp index dba1a87..0218ecc 100644 --- a/src/ito.cpp +++ b/src/ito.cpp @@ -32,9 +32,9 @@ bool Bu::Ito::stop() void *Bu::Ito::threadRunner( void *pThread ) { - void *pRet = ((Ito *)pThread)->run(); - pthread_exit( pRet ); - return pRet; + ((Ito *)pThread)->run(); + pthread_exit( NULL ); + return NULL; } bool Bu::Ito::join() diff --git a/src/ito.h b/src/ito.h index 895ff47..a60a23d 100644 --- a/src/ito.h +++ b/src/ito.h @@ -60,16 +60,6 @@ namespace Bu */ bool stop(); - /** - * The workhorse of the Ito class. This is the function that will run - * in the thread, when this function exits the thread dies and is - * cleaned up by the system. Make sure to read up on ItoMutex, - * ItoCondition, and cancel to see how to control and protect - * everything you do in a safe way within this function. - *@returns I'm not sure right now, but this is the posix standard form. - */ - virtual void *run()=0; - /** * Join the thread in action. This function performs what is commonly * called a thread join. That is that it effectively makes the calling @@ -88,6 +78,16 @@ namespace Bu int nHandle; /**< Numeric handle to the posix thread. */ protected: + /** + * The workhorse of the Ito class. This is the function that will run + * in the thread, when this function exits the thread dies and is + * cleaned up by the system. Make sure to read up on ItoMutex, + * ItoCondition, and cancel to see how to control and protect + * everything you do in a safe way within this function. + *@returns I'm not sure right now, but this is the posix standard form. + */ + virtual void run()=0; + /** * This is the hidden-heard of the thread system. While run is what the * user gets to override, and everything said about it is true, this is diff --git a/src/itoserver.cpp b/src/itoserver.cpp index 0640aad..279310d 100644 --- a/src/itoserver.cpp +++ b/src/itoserver.cpp @@ -74,7 +74,7 @@ void Bu::ItoServer::addClient( int nSocket, int nPort ) pC->start(); } -void *Bu::ItoServer::run() +void Bu::ItoServer::run() { for(;;) { @@ -105,8 +105,6 @@ void *Bu::ItoServer::run() delete pCli; } } - - return NULL; } void Bu::ItoServer::clientCleanup( int iSocket ) @@ -138,7 +136,7 @@ Bu::ItoServer::ItoClient::~ItoClient() { } -void *Bu::ItoServer::ItoClient::run() +void Bu::ItoServer::ItoClient::run() { imProto.lock(); rSrv.onNewConnection( pClient, iPort ); @@ -186,7 +184,7 @@ void *Bu::ItoServer::ItoClient::run() rSrv.clientCleanup( iSocket ); - return NULL; + return; } } @@ -197,8 +195,6 @@ void *Bu::ItoServer::ItoClient::run() imProto.unlock(); } } - - return NULL; } Bu::ItoServer::SrvClientLink::SrvClientLink( ItoClient *pClient ) : diff --git a/src/itoserver.h b/src/itoserver.h index 1b45748..c08d453 100644 --- a/src/itoserver.h +++ b/src/itoserver.h @@ -69,7 +69,8 @@ namespace Bu virtual void onNewConnection( Client *pClient, int nPort )=0; virtual void onClosedConnection( Client *pClient )=0; - virtual void *run(); + protected: + virtual void run(); private: class SrvClientLink; @@ -81,11 +82,12 @@ namespace Bu int nTimeoutSec, int nTimeoutUSec ); virtual ~ItoClient(); - virtual void *run(); - typedef ItoQueue StringQueue; StringQueue qMsg; + protected: + virtual void run(); + private: ItoServer &rSrv; Client *pClient; diff --git a/src/tests/itoheap.cpp b/src/tests/itoheap.cpp index 92bf3cf..347f1e0 100644 --- a/src/tests/itoheap.cpp +++ b/src/tests/itoheap.cpp @@ -23,7 +23,7 @@ public: { } - void *run() + void run() { for( int j = 0; j < 10; j++ ) { @@ -39,8 +39,6 @@ public: printf("Nothing yet...\n"); } } - - return NULL; } Bu::ItoHeap hInt; diff --git a/src/tests/itoqueue1.cpp b/src/tests/itoqueue1.cpp index 815216d..a034c87 100644 --- a/src/tests/itoqueue1.cpp +++ b/src/tests/itoqueue1.cpp @@ -19,7 +19,7 @@ public: { } - void *run() + void run() { for( int i = 0; i < 10; i++ ) { @@ -35,8 +35,6 @@ public: } usleep( (int)(((double)rand())/((double)RAND_MAX)*2000000.0) ); } - - return NULL; } private: @@ -54,7 +52,7 @@ public: { } - void *run() + void run() { for( int i = 0; i < 11; i++ ) { @@ -62,8 +60,6 @@ public: q.enqueue( new std::string( strbase ) ); printf("[%d] write: %s\n", id, strbase ); } - - return NULL; } private: diff --git a/src/tests/itoqueue2.cpp b/src/tests/itoqueue2.cpp index d1f20a4..b11aa32 100644 --- a/src/tests/itoqueue2.cpp +++ b/src/tests/itoqueue2.cpp @@ -19,7 +19,7 @@ public: { } - void *run() + void run() { for( int i = 0; i < 10; i++ ) { @@ -35,8 +35,6 @@ public: delete pStr; } } - - return NULL; } private: @@ -54,7 +52,7 @@ public: { } - void *run() + void run() { for( int i = 0; i < 11; i++ ) { @@ -62,8 +60,6 @@ public: printf("[%d] write: %s\n", id, strbase ); q.enqueue( new std::string( strbase ) ); } - - return NULL; } private: diff --git a/src/tests/socketblock.cpp b/src/tests/socketblock.cpp index 3d50aa0..a1ea18d 100644 --- a/src/tests/socketblock.cpp +++ b/src/tests/socketblock.cpp @@ -19,7 +19,7 @@ public: { } - virtual void *run() + virtual void run() { Bu::Socket c = s.accept( 45, 0 ); printf("TstServer: Accetped connection.\n"); fflush( stdout ); @@ -33,8 +33,6 @@ public: printf("TstServer: Closing connection...\n"); fflush( stdout ); c.close(); - - return NULL; } Bu::ServerSocket s; -- cgit v1.2.3