diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1996-10-31 09:07:58 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1996-10-31 09:07:58 +0000 |
commit | 87720d1fb9c6ff5b56ed79a43fe13c077199a822 (patch) | |
tree | 55361d379e07ed44f46ef7ad0772b5d3d5209166 /ace | |
parent | 267685af03949eb809efb6f6b240c92e1aa086b1 (diff) | |
download | ATCD-87720d1fb9c6ff5b56ed79a43fe13c077199a822.tar.gz |
Jammer
Diffstat (limited to 'ace')
-rw-r--r-- | ace/ACE.cpp | 150 | ||||
-rw-r--r-- | ace/ACE.h | 31 | ||||
-rw-r--r-- | ace/Acceptor.cpp | 6 | ||||
-rw-r--r-- | ace/Connector.cpp | 2 | ||||
-rw-r--r-- | ace/OS.h | 11 | ||||
-rw-r--r-- | ace/README | 1 | ||||
-rw-r--r-- | ace/Reactor.cpp | 1 | ||||
-rw-r--r-- | ace/SOCK_Stream.h | 15 | ||||
-rw-r--r-- | ace/SOCK_Stream.i | 22 | ||||
-rw-r--r-- | ace/Service_Manager.cpp | 2 | ||||
-rw-r--r-- | ace/Stream.cpp | 22 | ||||
-rw-r--r-- | ace/Svc_Handler.cpp | 13 | ||||
-rw-r--r-- | ace/Svc_Handler.h | 2 | ||||
-rw-r--r-- | ace/Synch.h | 4 | ||||
-rw-r--r-- | ace/Synch_T.cpp | 2 | ||||
-rw-r--r-- | ace/Task.cpp | 254 | ||||
-rw-r--r-- | ace/Task.h | 177 | ||||
-rw-r--r-- | ace/Task.i | 121 | ||||
-rw-r--r-- | ace/Thread_Manager.cpp | 35 | ||||
-rw-r--r-- | ace/Thread_Manager.h | 38 | ||||
-rw-r--r-- | ace/XtReactor.cpp | 44 | ||||
-rw-r--r-- | ace/config-win32-msvc4.0.h | 14 |
22 files changed, 533 insertions, 434 deletions
diff --git a/ace/ACE.cpp b/ace/ACE.cpp index c67ac81981e..5ca941f54ee 100644 --- a/ace/ACE.cpp +++ b/ace/ACE.cpp @@ -753,81 +753,75 @@ ACE::send (ACE_HANDLE handle, return ACE::send (handle, buf, n, flags); else { - // We need to record whether we are already *in* nonblocking mode, - // so that we can correctly reset the state when we're done. + // On timed writes we always go into select(); only if the + // descriptor is available for writing within the specified + // amount of time do we put it in non-blocking mode - int val = ACE::get_flags (handle); - - if (ACE_BIT_ENABLED (val, ACE_NONBLOCK) == 0) - // Set the descriptor into non-blocking mode if it's not already - // in it. - ACE::set_flags (handle, ACE_NONBLOCK); - - ACE_Time_Value timeout (*tv); - ACE_Time_Value start_time = ACE_OS::gettimeofday(); - - ssize_t bytes_written; - - // Use the non-timeout version to do the actual send. - bytes_written = ACE::send (handle, buf, n, flags); + ACE_Handle_Set handle_set; + handle_set.set_bit (handle); - if (bytes_written == -1 && errno == EWOULDBLOCK) + switch (ACE_OS::select (int (handle) + 1, 0, handle_set, 0, tv)) { - // We couldn't send due to flow control. - - // Compute time that has elapsed thus far. - ACE_Time_Value elapsed_time = ACE_OS::gettimeofday () - start_time; + case 1: // Ok to write now + // We need to record whether we are already *in* nonblocking + // mode, so that we can correctly reset the state when we're + // done. + { + int val = ACE::get_flags (handle); + + if (ACE_BIT_ENABLED (val, ACE_NONBLOCK) == 0) + // Set the descriptor into non-blocking mode if it's not + // already in it. + ACE::set_flags (handle, ACE_NONBLOCK); + + ssize_t bytes_written = ACE_OS::send (handle, (const char *) buf, n, flags); + + if (ACE_BIT_ENABLED (val, ACE_NONBLOCK) == 0) + { + // We need to stash errno here because ACE::clr_flags() may + // reset it. + int error = errno; + + // Only disable ACE_NONBLOCK if we weren't in non-blocking mode + // originally. + ACE::clr_flags (handle, ACE_NONBLOCK); + errno = error; + } + return bytes_written; + } + case 0: // Timer expired. + errno = ETIME; + /* FALLTHRU */ + default: // if we got here directly select() must have returned -1 + return -1; + } + } +} - if (elapsed_time > timeout) - // We've timed out, so break; - errno = ETIME; - else - { - // Update the timeout. - timeout -= elapsed_time; - - ACE_Handle_Set handle_set; +ssize_t +ACE::send_n (ACE_HANDLE handle, + const void *buf, + size_t n, + int flags, + const ACE_Time_Value *tv) +{ + size_t bytes_written; - handle_set.set_bit (handle); + // Actual number of bytes written in each attempt. + ssize_t i = 0; - switch (ACE_OS::select (int (handle) + 1, - 0, // read_fds. - handle_set, // write_fds. - 0, // exception_fds. - timeout)) - { - case 0: - errno = ETIME; - /* FALLTHRU */ - default: - /* FALLTHRU */ - case -1: - break; - case 1: - // We should be able to send something now. - bytes_written = ACE::send (handle, buf, n, flags); - break; - } - } - } - - if (ACE_BIT_ENABLED (val, ACE_NONBLOCK) == 0) - { - // We need to stash errno here because ACE::clr_flags() may - // reset it. - int error = errno; - - // Only disable ACE_NONBLOCK if we weren't in non-blocking mode - // originally. - ACE::clr_flags (handle, ACE_NONBLOCK); - errno = error; - } + for (bytes_written = 0; bytes_written < n; bytes_written += i) + { + i = ACE::send (handle, (char *) buf + bytes_written, + n - bytes_written, flags, tv); + if (i == -1) + break; + } - return bytes_written; - } + return bytes_written; } -int +ssize_t ACE::recv (ACE_HANDLE handle, void *buf, size_t n, @@ -858,3 +852,27 @@ ACE::recv (ACE_HANDLE handle, } } } + +ssize_t +ACE::recv_n (ACE_HANDLE handle, + void *buf, + size_t n, + int flags, + const ACE_Time_Value *tv) +{ + size_t bytes_received; + + // Actual number of bytes read in each attempt. + ssize_t i = 0; + + for (bytes_received = 0; bytes_received < n; bytes_received += i) + { + i = ACE::recv (handle, (char *) buf + bytes_received, + n - bytes_received, flags, tv); + + if (i == -1 || i == 0) + break; + } + + return bytes_received; +} diff --git a/ace/ACE.h b/ace/ACE.h index c6d97fa7e40..f7f26351315 100644 --- a/ace/ACE.h +++ b/ace/ACE.h @@ -38,8 +38,7 @@ class ACE_Export ACE // methods are put here rather than in ACE_OS in order to // separate concerns. public: - // = Network I/O functions that factor out differences between Win32 - // and UNIX. + // = Network I/O functions that factor out differences between Win32 and UNIX. static ssize_t recv (ACE_HANDLE handle, void *buf, size_t len, @@ -63,6 +62,17 @@ public: // out a -1 is returned with <errno == ETIME>. If it succeeds the // number of bytes received is returned. + static ssize_t recv_n (ACE_HANDLE handle, + void *buf, + size_t len, + int flags, + const ACE_Time_Value *timeout); + // Try to recv exactly <len> bytes into <buf> from <handle> (uses + // the <recv> call). If <recv> blocks for longer than <timeout> the + // number of bytes actually read is returned with <errno == ETIME>. + // If a timeout does not occur, <recv_n> return <len> (i.e., the + // number of bytes requested to be read). + static ssize_t send (ACE_HANDLE handle, const void *buf, size_t len, @@ -80,6 +90,17 @@ public: // out a -1 is returned with <errno == ETIME>. If it succeeds the // number of bytes sent is returned. + static ssize_t send_n (ACE_HANDLE handle, + const void *buf, + size_t len, + int flags, + const ACE_Time_Value *timeout); + // Try to send exactly <len> bytes into <buf> from <handle> (uses + // the <send> call). If <send> blocks for longer than <timeout> the + // number of bytes actually sent is returned with <errno == ETIME>. + // If a timeout does not occur, <send_n> return <len> (i.e., the + // number of bytes requested to be sent). + static ssize_t send (ACE_HANDLE handle, const void *buf, size_t len); @@ -113,8 +134,7 @@ public: // Send <len> bytes from <buf> to <handle> (uses the <write> system // call on UNIX and the <recv> call on Win32). - // = File system I/O functions that encapsulate differences between - // UNIX and Win32 and also send and recv exactly n bytes. + // = File system I/O functions that encapsulate differences between UNIX and Win32 and also send and recv exactly n bytes. static ssize_t read_n (ACE_HANDLE handle, void *buf, size_t len); @@ -212,8 +232,7 @@ public: static int daemonize (void); // Become a daemon process. - // = Methods for searching and opening shared libraries using - // relative naming. + // = Methods for searching and opening shared libraries using relative naming. static int ldfind (const char *filename, char *pathname, size_t maxlen); diff --git a/ace/Acceptor.cpp b/ace/Acceptor.cpp index baef2c27ce2..f67c77115fe 100644 --- a/ace/Acceptor.cpp +++ b/ace/Acceptor.cpp @@ -214,7 +214,7 @@ ACE_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::accept_svc_handler (SVC_HANDLER *svc_handler) { ACE_TRACE ("ACE_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::accept_svc_handler"); - if (this->peer_acceptor_.accept (*svc_handler) == -1) + if (this->peer_acceptor_.accept (svc_handler->peer ()) == -1) { // Close down handler to avoid memory leaks. svc_handler->close (0); @@ -808,7 +808,7 @@ ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::shared_accept return -1; // Accept connection into the Svc_Handler. - else if (this->peer_acceptor_.accept (*svc_handler, remote_addr, + else if (this->peer_acceptor_.accept (svc_handler->peer (), remote_addr, timeout, restart) == -1) { // Check whether we just timed out or whether we failed... @@ -866,7 +866,7 @@ ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::accept // "oneshot" Acceptor). template <class SVC_HANDLER, ACE_PEER_ACCEPTOR_1> int -ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::handle_input (ACE_HANDLE listener) +ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::handle_input (ACE_HANDLE) { ACE_TRACE ("ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::handle_input"); int result = 0; diff --git a/ace/Connector.cpp b/ace/Connector.cpp index 917c6ce9ada..0cace4e72c3 100644 --- a/ace/Connector.cpp +++ b/ace/Connector.cpp @@ -81,7 +81,7 @@ ACE_Connector<SH, PR_CO_2>::connect_svc_handler (SVC_HANDLER *svc_handler, else timeout = (ACE_Time_Value *) synch_options.time_value (); - if (this->connector_.connect (*svc_handler, + if (this->connector_.connect (svc_handler->peer (), remote_addr, timeout, local_addr, @@ -937,6 +937,15 @@ typedef void (*ACE_SignalHandlerV)(...); #define ACE_PLATFORM "Win32" #define ACE_PLATFORM_EXE_SUFFIX ".exe" +// STRICT type checking in WINDOWS.H enhances type safety for Windows +// programs by using distinct types to represent all the different +// HANDLES in Windows. So for example, STRICT prevents you from +// mistakenly passing an HPEN to a routine expecting an HBITMAP. +// Note that we only use this if we +#if defined (ACE_HAS_STRICT) +#define STRICT +#endif /* ACE_HAS_STRICT */ + #include <sys/timeb.h> // The following 3 defines are used by the ACE Name Server... @@ -1029,7 +1038,7 @@ PAGE_NOCACHE */ #include <winsock.h> -#define MAXHOSTNAMELEN (MAX_COMPUTERNAME_LENGTH+1) // This should be around 16 or so... +#define MAXHOSTNAMELEN 256 // error code mapping #define ETIME ERROR_SEM_TIMEOUT diff --git a/ace/README b/ace/README index 83d029a3d9a..0fbc0ed35df 100644 --- a/ace/README +++ b/ace/README @@ -83,6 +83,7 @@ ACE_HAS_STRBUF_T Compiler/platform supports struct strbuf ACE_HAS_STREAMS Platform supports STREAMS ACE_HAS_STREAM_PIPES Platform supports STREAM pipes ACE_HAS_STRERROR Compiler/platform supports strerror () +ACE_HAS_STRICT Use the STRICT compilation mode on Win32. ACE_HAS_STRUCT_NETDB_DATA Compiler/platform has strange hostent API for socket *_r() calls ACE_HAS_STRUCT_PROTOENT_DATA Compiler/platform has strange protoent API for socket *_r() calls ACE_HAS_SUNOS4_GETTIMEOFDAY SunOS 4 style prototype. diff --git a/ace/Reactor.cpp b/ace/Reactor.cpp index 4e58ae76fd0..672caccc8f4 100644 --- a/ace/Reactor.cpp +++ b/ace/Reactor.cpp @@ -911,6 +911,7 @@ ACE_Reactor::ACE_Reactor (size_t size, int rs, ACE_Sig_Handler *sh) timer_skew_ (0, ACE_TIMER_SKEW) { ACE_TRACE ("ACE_Reactor::ACE_Reactor"); + if (this->open (size, rs, sh) == -1) ACE_ERROR ((LM_ERROR, "%p\n", "open failed")); } diff --git a/ace/SOCK_Stream.h b/ace/SOCK_Stream.h index cde111fc63a..826ede89c17 100644 --- a/ace/SOCK_Stream.h +++ b/ace/SOCK_Stream.h @@ -41,6 +41,21 @@ public: ssize_t recv_n (void *buf, int n, int flags) const; // Recv n bytes, keep trying until n are received. + ssize_t send_n (const void *buf, size_t len, int flags, + const ACE_Time_Value *timeout); + // Try to send exactly <len> bytes into <buf> from <handle> (uses + // the <send> call). If <send> blocks for longer than <timeout> the + // number of bytes actually sent is returned with <errno == ETIME>. + // If a timeout does not occur, <send_n> return <len> (i.e., the + // number of bytes requested to be sent). + + ssize_t recv_n (void *buf, size_t len, int flags, + const ACE_Time_Value *timeout); + // Wait up to <timeout> amount of time to receive up to <len> bytes + // into <buf> from <handle> (uses the <recv> call). If <recv> times + // out a -1 is returned with <errno == ETIME>. If it succeeds the + // number of bytes received is returned. + // = Send/receive an ``urgent'' character (see TCP specs...). ssize_t send_urg (void *ptr, int len = sizeof (char)); ssize_t recv_urg (void *ptr, int len = sizeof (char)); diff --git a/ace/SOCK_Stream.i b/ace/SOCK_Stream.i index cd703bb834c..6bf38fbaf26 100644 --- a/ace/SOCK_Stream.i +++ b/ace/SOCK_Stream.i @@ -11,8 +11,7 @@ inline int ACE_SOCK_Stream::close_reader (void) { ACE_TRACE ("ACE_SOCK_Stream::close_reader"); - int result = ACE_OS::shutdown (this->get_handle (), 0); - return result; + return ACE_OS::shutdown (this->get_handle (), 0); } // Shut down just the writing end of a ACE_SOCK. @@ -21,8 +20,23 @@ inline int ACE_SOCK_Stream::close_writer (void) { ACE_TRACE ("ACE_SOCK_Stream::close_writer"); - int result = ACE_OS::shutdown (this->get_handle (), 1); - return result; + return ACE_OS::shutdown (this->get_handle (), 1); +} + +inline ssize_t +ACE_SOCK_Stream::send_n (const void *buf, size_t len, int flags, + const ACE_Time_Value *timeout) +{ + ACE_TRACE ("ACE_SOCK_Stream::send_n"); + return ACE::send_n (this->get_handle (), buf, len, flags, timeout); +} + +inline ssize_t +ACE_SOCK_Stream::recv_n (void *buf, size_t len, int flags, + const ACE_Time_Value *timeout) +{ + ACE_TRACE ("ACE_SOCK_Stream::send_n"); + return ACE::recv_n (this->get_handle (), buf, len, flags, timeout); } // Receive exactly BUF_SIZE bytes from file descriptor this->handle diff --git a/ace/Service_Manager.cpp b/ace/Service_Manager.cpp index 2658895e4c6..ceac86b7fc7 100644 --- a/ace/Service_Manager.cpp +++ b/ace/Service_Manager.cpp @@ -21,7 +21,7 @@ ACE_Service_Manager::dump (void) const ACE_TRACE ("ACE_Service_Manager::dump"); } -/* Static variables. */ +// Static variables. u_short ACE_Service_Manager::DEFAULT_PORT_ = 10000; diff --git a/ace/Stream.cpp b/ace/Stream.cpp index 3b985d1cc95..7b120ef43f3 100644 --- a/ace/Stream.cpp +++ b/ace/Stream.cpp @@ -32,26 +32,26 @@ ACE_Stream<ACE_SYNCH_2>::dump (void) const ACE_DEBUG ((LM_DEBUG, "-------- writer links --------\n")); - ACE_Task<ACE_SYNCH_2> *qp; + ACE_Task<ACE_SYNCH_2> *tp; - for (qp = this->stream_head_->writer (); ; qp = qp->next ()) + for (tp = this->stream_head_->writer (); ; tp = tp->next ()) { - ACE_DEBUG ((LM_DEBUG, "writer queue name = %s\n", qp->name ())); - qp->dump (); + ACE_DEBUG ((LM_DEBUG, "writer queue name = %s\n", tp->name ())); + tp->dump (); ACE_DEBUG ((LM_DEBUG, "-------\n")); - if (qp == this->stream_tail_->writer () - || (this->linked_us_ && qp == this->linked_us_->stream_head_->reader ())) + if (tp == this->stream_tail_->writer () + || (this->linked_us_ && tp == this->linked_us_->stream_head_->reader ())) break; } ACE_DEBUG ((LM_DEBUG, "-------- reader links --------\n")); - for (qp = this->stream_tail_->reader (); ; qp = qp->next ()) + for (tp = this->stream_tail_->reader (); ; tp = tp->next ()) { - ACE_DEBUG ((LM_DEBUG, "reader queue name = %s\n", qp->name ())); - qp->dump (); + ACE_DEBUG ((LM_DEBUG, "reader queue name = %s\n", tp->name ())); + tp->dump (); ACE_DEBUG ((LM_DEBUG, "-------\n")); - if (qp == this->stream_head_->reader () - || (this->linked_us_ && qp == this->linked_us_->stream_head_->writer ())) + if (tp == this->stream_head_->reader () + || (this->linked_us_ && tp == this->linked_us_->stream_head_->writer ())) break; } } diff --git a/ace/Svc_Handler.cpp b/ace/Svc_Handler.cpp index 4c797a7e8e9..4c7261fcb70 100644 --- a/ace/Svc_Handler.cpp +++ b/ace/Svc_Handler.cpp @@ -184,16 +184,7 @@ ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_2>::peer (void) const return (ACE_PEER_STREAM &) this->peer_; } -// Extract the underlying PEER_STREAM (e.g., used by ACE_Connector and -// ACE_Acceptor). - -template <PR_ST_1, ACE_SYNCH_1> -ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_2>::operator ACE_PEER_STREAM &() -{ - return this->peer_; -} - -/* Extract the underlying I/O descriptor. */ +// Extract the underlying I/O descriptor. template <PR_ST_1, ACE_SYNCH_1> ACE_HANDLE ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_2>::get_handle (void) const @@ -202,7 +193,7 @@ ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_2>::get_handle (void) const return this->peer_.get_handle (); } -/* Set the underlying I/O descriptor. */ +// Set the underlying I/O descriptor. template <PR_ST_1, ACE_SYNCH_1> void ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_2>::set_handle (ACE_HANDLE h) diff --git a/ace/Svc_Handler.h b/ace/Svc_Handler.h index bd02389d0e2..bf10408b5ce 100644 --- a/ace/Svc_Handler.h +++ b/ace/Svc_Handler.h @@ -94,7 +94,7 @@ public: ACE_PEER_STREAM &peer (void) const; // Returns the underlying PEER_STREAM - operator ACE_PEER_STREAM &(); + // operator ACE_PEER_STREAM &(); // Returns the underlying PEER_STREAM (used by // ACE_Acceptor::accept() and ACE_Connector::connect() factories). diff --git a/ace/Synch.h b/ace/Synch.h index 01f33cd8748..cd93af0fe77 100644 --- a/ace/Synch.h +++ b/ace/Synch.h @@ -465,7 +465,9 @@ class ACE_Export ACE_Recursive_Thread_Mutex // = DESCRIPTION // This class should be a specialization of the // ACE_Recursive_Lock template class, but problems with some C++ - // compilers preclude this... + // compilers preclude this. This implementation is based + // on an algorithm sketched by Dave Butenhof <butenhof@zko.dec.com>. + // Naturally, I take the credit for any mistakes ;-) { // friend class ACE_Condition<class ACE_COND_MUTEX>; public: diff --git a/ace/Synch_T.cpp b/ace/Synch_T.cpp index a24ab8e46b9..c5c552a3204 100644 --- a/ace/Synch_T.cpp +++ b/ace/Synch_T.cpp @@ -178,7 +178,7 @@ template <class MUTEX> int ACE_Condition<MUTEX>::wait (void) { // ACE_TRACE ("ACE_Condition<MUTEX>::wait"); - return ACE_OS::cond_wait (&this->cond_, this->mutex_.lock_); + return ACE_OS::cond_wait (&this->cond_, &this->mutex_.lock_); } template <class MUTEX> int diff --git a/ace/Task.cpp b/ace/Task.cpp index 037c734be14..52fea1db94e 100644 --- a/ace/Task.cpp +++ b/ace/Task.cpp @@ -15,14 +15,13 @@ #if defined (ACE_MT_SAFE) && !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) // Lock the creation of the Singleton. -template <ACE_SYNCH_1> -ACE_Thread_Mutex ACE_Task_Exit<ACE_SYNCH_2>::ace_task_lock_; +ACE_Thread_Mutex ACE_Task_Exit::ace_task_lock_; #endif /* defined (ACE_MT_SAFE) && !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) */ -template<ACE_SYNCH_1> ACE_Task_Exit<ACE_SYNCH_2> * -ACE_Task_Exit<ACE_SYNCH_2>::instance (void) +ACE_Task_Exit * +ACE_Task_Exit::instance (void) { - ACE_TRACE ("ACE_Task_Exit<ACE_SYNCH_2>::instance"); + ACE_TRACE ("ACE_Task_Exit::instance"); #if defined (ACE_MT_SAFE) && defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) // Lock the creation of the Singleton. This should be inside of @@ -31,7 +30,7 @@ ACE_Task_Exit<ACE_SYNCH_2>::instance (void) #endif /* defined (ACE_MT_SAFE) && defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) */ // Determines if we were dynamically allocated. - static ACE_TSS_TYPE (ACE_Task_Exit<ACE_SYNCH_2>) *instance_; + static ACE_TSS_TYPE (ACE_Task_Exit) *instance_; // Implement the Double Check pattern. @@ -40,28 +39,27 @@ ACE_Task_Exit<ACE_SYNCH_2>::instance (void) ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, ace_task_lock_, 0)); if (instance_ == 0) - ACE_NEW_RETURN (instance_, ACE_TSS_TYPE (ACE_Task_Exit<ACE_SYNCH_2>), 0); + ACE_NEW_RETURN (instance_, ACE_TSS_TYPE (ACE_Task_Exit), 0); } - return ACE_TSS_GET (instance_, ACE_Task_Exit<ACE_SYNCH_2>); + return ACE_TSS_GET (instance_, ACE_Task_Exit); } // Grab hold of the Task * so that we can close() it in the // destructor. -template<ACE_SYNCH_1> -ACE_Task_Exit<ACE_SYNCH_2>::ACE_Task_Exit (void) +ACE_Task_Exit::ACE_Task_Exit (void) : t_ (0), status_ ((void *) -1) { - ACE_TRACE ("ACE_Task_Exit<ACE_SYNCH_2>::ACE_Task_Exit"); + ACE_TRACE ("ACE_Task_Exit::ACE_Task_Exit"); } // Returns the pointer to the ACE_Task. -template<ACE_SYNCH_1> ACE_Task<ACE_SYNCH_2>* -ACE_Task_Exit<ACE_SYNCH_2>::get_task (void) +ACE_Task_Base * +ACE_Task_Exit::get_task (void) { ACE_TRACE ("ACE_Task_Exit<ACE_SYNCH_2>::get_task"); @@ -70,10 +68,10 @@ ACE_Task_Exit<ACE_SYNCH_2>::get_task (void) // Set the this pointer... -template<ACE_SYNCH_1> void -ACE_Task_Exit<ACE_SYNCH_2>::set_task (ACE_Task<ACE_SYNCH_2> *t) +void +ACE_Task_Exit::set_task (ACE_Task_Base *t) { - ACE_TRACE ("ACE_Task_Exit<ACE_SYNCH_2>::set_task"); + ACE_TRACE ("ACE_Task_Exit::set_task"); this->t_ = t; if (t != 0) @@ -82,27 +80,26 @@ ACE_Task_Exit<ACE_SYNCH_2>::set_task (ACE_Task<ACE_SYNCH_2> *t) // Set the thread exit status value. -template<ACE_SYNCH_1> void * -ACE_Task_Exit<ACE_SYNCH_2>::status (void *s) +void * +ACE_Task_Exit::status (void *s) { - ACE_TRACE ("ACE_Task_Exit<ACE_SYNCH_2>::status"); + ACE_TRACE ("ACE_Task_Exit::status"); return this->status_ = s; } -template<ACE_SYNCH_1> void * -ACE_Task_Exit<ACE_SYNCH_2>::status (void) +void * +ACE_Task_Exit::status (void) { - ACE_TRACE ("ACE_Task_Exit<ACE_SYNCH_2>::status"); + ACE_TRACE ("ACE_Task_Exit::status"); return this->status_; } // When this object is destroyed the Task is automatically closed // down! -template<ACE_SYNCH_1> -ACE_Task_Exit<ACE_SYNCH_2>::~ACE_Task_Exit (void) +ACE_Task_Exit::~ACE_Task_Exit (void) { - ACE_TRACE ("ACE_Task_Exit<ACE_SYNCH_2>::~ACE_Task_Exit"); + ACE_TRACE ("ACE_Task_Exit::~ACE_Task_Exit"); if (this->t_ != 0) { @@ -115,6 +112,103 @@ ACE_Task_Exit<ACE_SYNCH_2>::~ACE_Task_Exit (void) ACE_ALLOC_HOOK_DEFINE(ACE_Task) +ACE_Task_Base::ACE_Task_Base (ACE_Thread_Manager *thr_man) + : thr_count_ (0), + thr_mgr_ (thr_man), + flags_ (0), + grp_id_ (0) +{ +} + +// Get the current group id. +ACE_INLINE int +ACE_Task_Base::grp_id (void) +{ + ACE_TRACE ("ACE_Task_Base::grp_id"); + ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); + return this->grp_id_; +} + +// Set the current group id. +ACE_INLINE void +ACE_Task_Base::grp_id (int id) +{ + ACE_TRACE ("ACE_Task_Base::grp_id"); + ACE_MT (ACE_GUARD (ACE_Thread_Mutex, ace_mon, this->lock_)); + this->grp_id_ = id; +} + +// Suspend a task. +int +ACE_Task_Base::suspend (void) +{ + ACE_TRACE ("ACE_Task_Base::suspend"); + ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); + if (this->thr_count_ > 0) + return this->thr_mgr_->suspend_task (this); + else + return 0; +} + +// Resume a suspended task. +int +ACE_Task_Base::resume (void) +{ + ACE_TRACE ("ACE_Task_Base::resume"); + ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); + if (this->thr_count_ > 0) + return this->thr_mgr_->resume_task (this); + else + return 0; +} + +int +ACE_Task_Base::activate (long flags, + int n_threads, + int force_active, + u_int priority, + int grp_id, + ACE_Task_Base *task) +{ + ACE_TRACE ("ACE_Task_Base::activate"); + +#if defined (ACE_MT_SAFE) + ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1); + + if (this->thr_count_ > 0 && force_active == 0) + return 1; // Already active. + else + this->thr_count_ = n_threads; + + // Use the ACE_Thread_Manager singleton if we're running as an + // active object and the caller didn't supply us with a + // Thread_Manager. + if (this->thr_mgr_ == 0) + this->thr_mgr_ = ACE_Service_Config::thr_mgr (); + + this->grp_id_ = this->thr_mgr_->spawn_n (n_threads, + ACE_THR_FUNC (&ACE_Task_Base::svc_run), + (void *) this, + flags, + priority, + grp_id, + task); + if (this->grp_id_ == -1) + return -1; + else + return 0; +#else + { + // Keep the compiler from complaining. + n_threads = n_threads; + force_active = force_active; + flags = flags; + errno = EINVAL; + return -1; + } +#endif /* ACE_MT_SAFE */ +} + template <ACE_SYNCH_1> ACE_INLINE void ACE_Task<ACE_SYNCH_2>::dump (void) const { @@ -141,14 +235,11 @@ ACE_Task<ACE_SYNCH_2>::dump (void) const template<ACE_SYNCH_1> ACE_Task<ACE_SYNCH_2>::ACE_Task (ACE_Thread_Manager *thr_man, ACE_Message_Queue<ACE_SYNCH_2> *mq) - : thr_count_ (0), - thr_mgr_ (thr_man), + : ACE_Task_Base (thr_man), msg_queue_ (0), delete_msg_queue_ (0), - flags_ (0), - mod_ (0), - next_ (0), - grp_id_ (0) + mod_ (0), + next_ (0) { ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::ACE_Task"); @@ -171,23 +262,19 @@ ACE_Task<ACE_SYNCH_2>::~ACE_Task (void) // These assignments aren't strickly necessary but they help guard // against odd race conditions... this->delete_msg_queue_ = 0; - this->msg_queue_ = 0; - this->thr_mgr_ = 0; - this->mod_ = 0; } // Note that this routine often does not return since the thread that // is executing it will do an ACE_Thread::exit() first! -template<ACE_SYNCH_1> void * -ACE_Task<ACE_SYNCH_2>::svc_run (ACE_Task<ACE_SYNCH_2> *t) +void * +ACE_Task_Base::svc_run (ACE_Task_Base *t) { - ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::svc_run"); + ACE_TRACE ("ACE_Task_Base::svc_run"); // Obtain our thread-specific exit hook and make sure that it knows // how to clean us up! - ACE_Task_Exit<ACE_SYNCH_2> *exit_hook = - ACE_Task_Exit<ACE_SYNCH_2>::instance (); + ACE_Task_Exit *exit_hook = ACE_Task_Exit::instance (); exit_hook->set_task (t); @@ -225,93 +312,4 @@ ACE_Task<ACE_SYNCH_2>::module (void) const return this->mod_; } -// Get the current group id. -template <ACE_SYNCH_1> ACE_INLINE int -ACE_Task<ACE_SYNCH_2>::grp_id (void) -{ - ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::grp_id"); - ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); - return this->grp_id_; -} - -// Set the current group id. -template <ACE_SYNCH_1> ACE_INLINE void -ACE_Task<ACE_SYNCH_2>::grp_id (int id) -{ - ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::grp_id"); - ACE_MT (ACE_GUARD (ACE_Thread_Mutex, ace_mon, this->lock_)); - this->grp_id_ = id; -} - -// Suspend a task. -template<ACE_SYNCH_1> int -ACE_Task<ACE_SYNCH_2>::suspend (void) -{ - ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::suspend"); - ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); - if (this->thr_count_ > 0) - return this->thr_mgr_->suspend_task (this); - else - return 0; -} - -// Resume a suspended task. -template<ACE_SYNCH_1> int -ACE_Task<ACE_SYNCH_2>::resume (void) -{ - ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::resume"); - ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); - if (this->thr_count_ > 0) - return this->thr_mgr_->resume_task (this); - else - return 0; -} - -template<ACE_SYNCH_1> int -ACE_Task<ACE_SYNCH_2>::activate (long flags, - int n_threads, - int force_active, - u_int priority, - int grp_id, - ACE_Task<ACE_SYNCH_2> *task) -{ - ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::activate"); - -#if defined (ACE_MT_SAFE) - ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1); - - if (this->thr_count_ > 0 && force_active == 0) - return 1; // Already active. - else - this->thr_count_ = n_threads; - - // Use the ACE_Thread_Manager singleton if we're running as an - // active object and the caller didn't supply us with a - // Thread_Manager. - if (this->thr_mgr_ == 0) - this->thr_mgr_ = ACE_Service_Config::thr_mgr (); - - this->grp_id_ = this->thr_mgr_->spawn_n (n_threads, - ACE_THR_FUNC (&ACE_Task<ACE_SYNCH_2>::svc_run), - (void *) this, - flags, - priority, - grp_id, - task); - if (this->grp_id_ == -1) - return -1; - else - return 0; -#else - { - // Keep the compiler from complaining. - n_threads = n_threads; - force_active = force_active; - flags = flags; - errno = EINVAL; - return -1; - } -#endif /* ACE_MT_SAFE */ -} - #endif /* ACE_TASK_C */ diff --git a/ace/Task.h b/ace/Task.h index dcd3d1f7a88..e608ee4471b 100644 --- a/ace/Task.h +++ b/ace/Task.h @@ -25,7 +25,6 @@ // Forward decls... template <ACE_SYNCH_1> class ACE_Module; -template <ACE_SYNCH_1> class ACE_Task_Exit; class ACE_Task_Flags // = TITLE @@ -49,30 +48,21 @@ public: }; }; -template <ACE_SYNCH_1> -class ACE_Task : public ACE_Service_Object +class ACE_Task_Base : public ACE_Service_Object // = TITLE - // Primary interface for application message processing, as well - // as input and output message queueing. + // Direct base class for the ACE_Task template. // // = DESCRIPTION - // This class serves as the basis for passive and active objects - // in ACE. + // This class factors out the non-template code in order to + // reduce template bloat, as well as to make it possible for the + // <ACE_Thread_Manager> to store <ACE_Task_Base> *'s + // polymorphically. { -friend class ACE_Module<ACE_SYNCH_2>; -friend class ACE_Module_Type; -friend class ACE_Task_Exit<ACE_SYNCH_2>; public: - // = Initialization/termination methods. - ACE_Task (ACE_Thread_Manager *thr_mgr = 0, - ACE_Message_Queue<ACE_SYNCH_2> *mq = 0); - // Initialize a Task, supplying a thread manager and a message - // queue. If the user doesn't supply a ACE_Message_Queue pointer - // then we'll allocate one dynamically. Otherwise, we'll use the - // one they give. + // = Initialization method. + ACE_Task_Base (ACE_Thread_Manager *); - // = Initialization and termination hooks (note that these *must* be - // defined by subclasses). + // = Initialization and termination hooks (note that these *must* be defined by subclasses). virtual int open (void *args = 0) = 0; // Hook called to open a Task. <args> can be used to pass arbitrary // information into <open>. @@ -80,11 +70,8 @@ public: virtual int close (u_long flags = 0) = 0; // Hook called to close a Task. - virtual ~ACE_Task (void); - // Destructor. - // = Immediate and deferred processing methods, respectively. - virtual int put (ACE_Message_Block *, ACE_Time_Value *tv = 0) = 0; + virtual int put (ACE_Message_Block *, ACE_Time_Value * = 0) = 0; // Transfer msg into the queue to handle immediate processing. virtual int svc (void); @@ -96,7 +83,7 @@ public: int force_active = 0, u_int priority = 0, int grp_id = -1, - ACE_Task<ACE_SYNCH_2> *task = NULL); + ACE_Task_Base *task = NULL); // Turn the task into an active object, i.e., having <n_threads> of // control, all running at the <priority> level with the same // <grp_id>, all of which invoke <Task::svc>. Returns -1 if failure @@ -105,7 +92,7 @@ public: // this case), and returns 0 if Task was not already an active // object and a thread is created successfully or thread is an // active object and <force_active> is true. - + // = Suspend/resume a Task virtual int suspend (void); // Suspend a task. @@ -124,24 +111,80 @@ public: void thr_mgr (ACE_Thread_Manager *); // Set the thread manager associated with this Task. - ACE_Message_Queue<ACE_SYNCH_2> *msg_queue (void); - // Gets the message queue associated with this task. - - void msg_queue (ACE_Message_Queue<ACE_SYNCH_2> *); - // Sets the message queue associated with this task. - size_t thr_count (void); // Returns the number of threads currently running within a task. // If we're a passive object this value is 0, else it's > 0. -public: /* Should be protected: */ - static void *svc_run (ACE_Task<ACE_SYNCH_2> *); + static void *svc_run (ACE_Task_Base *); // Routine that runs the service routine as a daemon thread. - // = Message queue manipulation methods. + int is_reader (void); + // True if queue is a reader, else false. - int can_put (ACE_Message_Block *); - // Tests whether we can enqueue a message without blocking. + int is_writer (void); + // True if queue is a writer, else false. + + void thr_count_dec (void); + // Atomically decrement the thread count by 1. This should only be + // called by the <ACE_Task_Exit> class destructor. + + // = Internal data (should be private...). +// private: + + size_t thr_count_; + // Count of the number of threads running within the task. If this + // value is > 0 then we're an active object and the value of + // <thr_count_> is the number of active threads at this instant. If + // the value == 0, then we're a passive object. + + ACE_Thread_Manager *thr_mgr_; + // Multi-threading manager. + + u_long flags_; + // ACE_Task flags. + + int grp_id_; + // This maintains the group id of the + +#if defined (ACE_MT_SAFE) + ACE_Thread_Mutex lock_; + // Protect the state of a Task during concurrent operations, but + // only if we're configured as MT safe... +#endif /* ACE_MT_SAFE */ +}; + +template <ACE_SYNCH_1> +class ACE_Task : public ACE_Task_Base + // = TITLE + // Primary interface for application message processing, as well + // as input and output message queueing. + // + // = DESCRIPTION + // This class serves as the basis for passive and active objects + // in ACE. +{ +friend class ACE_Module<ACE_SYNCH_2>; +friend class ACE_Module_Type; +public: + // = Initialization/termination methods. + ACE_Task (ACE_Thread_Manager *thr_mgr = 0, + ACE_Message_Queue<ACE_SYNCH_2> *mq = 0); + // Initialize a Task, supplying a thread manager and a message + // queue. If the user doesn't supply a ACE_Message_Queue pointer + // then we'll allocate one dynamically. Otherwise, we'll use the + // one they give. + + virtual ~ACE_Task (void); + // Destructor. + + ACE_Message_Queue<ACE_SYNCH_2> *msg_queue (void); + // Gets the message queue associated with this task. + + void msg_queue (ACE_Message_Queue<ACE_SYNCH_2> *); + // Sets the message queue associated with this task. + +public: // Should be protected: + // = Message queue manipulation methods. int putq (ACE_Message_Block *, ACE_Time_Value *tv = 0); // Insert message into the message list. @@ -152,17 +195,26 @@ public: /* Should be protected: */ int ungetq (ACE_Message_Block *, ACE_Time_Value *tv = 0); // Return a message to the queue. - int put_next (ACE_Message_Block *msg, ACE_Time_Value *tv = 0); - // Transfer message to the adjacent ACE_Task in a ACE_Stream. + int can_put (ACE_Message_Block *); + // Tests whether we can enqueue a message without blocking. int reply (ACE_Message_Block *, ACE_Time_Value *tv = 0); // Turn the message back around. + int put_next (ACE_Message_Block *msg, ACE_Time_Value *tv = 0); + // Transfer message to the adjacent ACE_Task in a ACE_Stream. + // = ACE_Task utility routines to identify names et al. const char *name (void) const; // Return the name of the enclosing Module if there's one associated // with the Task, else returns 0. + // = Pointers to next ACE_Task_Base (if ACE is part of an ACE_Stream). + ACE_Task<ACE_SYNCH_2> *next (void); + // Get next Task pointer. + void next (ACE_Task<ACE_SYNCH_2> *); + // Set next Task pointer. + ACE_Task<ACE_SYNCH_2> *sibling (void); // Return the Task's sibling if there's one associated with the // Task's Module, else returns 0. @@ -170,64 +222,24 @@ public: /* Should be protected: */ ACE_Module<ACE_SYNCH_2> *module (void) const; // Return the Task's Module if there is one, else returns 0. - int is_reader (void); - // True if queue is a reader, else false. - - int is_writer (void); - // True if queue is a writer, else false. - - // = Pointers to next ACE_Queue (if ACE is part of an ACE_Stream). - ACE_Task<ACE_SYNCH_2> *next (void); - // Get next Task pointer. - void next (ACE_Task<ACE_SYNCH_2> *); - // Set next Task pointer. - int flush (u_long flag = ACE_Task_Flags::ACE_FLUSHALL); /* Flush the queue */ // Special routines corresponding to certain message types. void water_marks (ACE_IO_Cntl_Msg::ACE_IO_Cntl_Cmds, size_t); // Manipulate watermarks. - void thr_count_dec (void); - // Atomically decrement the thread count by 1. This should only be - // called by the <ACE_Task_Exit> class destructor. - - // = Internal data (should be private...). -// private: - - size_t thr_count_; - // Count of the number of threads running within the task. If this - // value is > 0 then we're an active object and the value of - // <thr_count_> is the number of active threads at this instant. If - // the value == 0, then we're a passive object. - - ACE_Thread_Manager *thr_mgr_; - // Multi-threading manager. - ACE_Message_Queue<ACE_SYNCH_2> *msg_queue_; // List of messages on the ACE_Task.. int delete_msg_queue_; // 1 if should delete Message_Queue, 0 otherwise. - u_long flags_; - // ACE_Task flags. - ACE_Module<ACE_SYNCH_2> *mod_; // Back-pointer to the enclosing module. ACE_Task<ACE_SYNCH_2> *next_; // Pointer to adjacent ACE_Task. - int grp_id_; - // This maintains the group id of the - -#if defined (ACE_MT_SAFE) - ACE_Thread_Mutex lock_; - // Protect the state of a Task during concurrent operations, but - // only if we're configured as MT safe... -#endif /* ACE_MT_SAFE */ - void dump (void) const; // Dump the state of an object. @@ -235,7 +247,6 @@ public: /* Should be protected: */ // Declare the dynamic allocation hooks. }; -template<ACE_SYNCH_1> class ACE_Task_Exit // = TITLE // Keep exit information for a Task in thread specific storage so @@ -253,10 +264,10 @@ public: ACE_Task_Exit (void); // Capture the Task object that will be cleaned up automatically. - void set_task (ACE_Task<ACE_SYNCH_2> *t); + void set_task (ACE_Task_Base *t); // Set the this pointer... - ACE_Task<ACE_SYNCH_2>* get_task (void); + ACE_Task_Base *get_task (void); // Get the pointer to the ACE_Task. void *status (void *s); @@ -268,11 +279,11 @@ public: ~ACE_Task_Exit (void); // Destructor calls the <close> method of the captured Task on exit. - static ACE_Task_Exit<ACE_SYNCH_2> *instance (void); + static ACE_Task_Exit *instance (void); // Singleton access point. private: - ACE_Task<ACE_SYNCH_2> *t_; + ACE_Task_Base *t_; // Pointer to the captured Task. void *status_; diff --git a/ace/Task.i b/ace/Task.i index 22d2c6cfb09..51d223d85be 100644 --- a/ace/Task.i +++ b/ace/Task.i @@ -5,11 +5,25 @@ #include "ace/Log_Msg.h" +ACE_INLINE ACE_Thread_Manager * +ACE_Task_Base::thr_mgr (void) +{ + ACE_TRACE ("ACE_Task_Base::thr_mgr"); + return this->thr_mgr_; +} + +ACE_INLINE void +ACE_Task_Base::thr_mgr (ACE_Thread_Manager *thr_mgr) +{ + ACE_TRACE ("ACE_Task_Base::thr_mgr"); + this->thr_mgr_ = thr_mgr; +} + // Return the count of the current number of threads. -template <ACE_SYNCH_1> ACE_INLINE size_t -ACE_Task<ACE_SYNCH_2>::thr_count (void) +ACE_INLINE size_t +ACE_Task_Base::thr_count (void) { - ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::thr_count"); + ACE_TRACE ("ACE_Task_Base::thr_count"); ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0)); return this->thr_count_; @@ -17,15 +31,38 @@ ACE_Task<ACE_SYNCH_2>::thr_count (void) // Decrement the count of the active threads by 1. -template <ACE_SYNCH_1> ACE_INLINE void -ACE_Task<ACE_SYNCH_2>::thr_count_dec (void) +ACE_INLINE void +ACE_Task_Base::thr_count_dec (void) { - ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::thr_count_dec"); + ACE_TRACE ("ACE_Task_Base::thr_count_dec"); ACE_MT (ACE_GUARD (ACE_Thread_Mutex, ace_mon, this->lock_)); this->thr_count_--; } +ACE_INLINE int +ACE_Task_Base::is_reader (void) +{ + ACE_TRACE ("ACE_Task_Base::is_reader"); + return (ACE_BIT_ENABLED (this->flags_, ACE_Task_Flags::ACE_READER)); +} + +ACE_INLINE int +ACE_Task_Base::is_writer (void) +{ + ACE_TRACE ("ACE_Task_Base::is_writer"); + return (ACE_BIT_DISABLED (this->flags_, ACE_Task_Flags::ACE_READER)); +} + +// Default ACE_Task service routine + +int +ACE_Task_Base::svc (void) +{ + ACE_TRACE ("ACE_Task_Base::svc"); + return 0; +} + template <ACE_SYNCH_1> ACE_INLINE void ACE_Task<ACE_SYNCH_2>::water_marks (ACE_IO_Cntl_Msg::ACE_IO_Cntl_Cmds cmd, size_t size) @@ -67,20 +104,6 @@ ACE_Task<ACE_SYNCH_2>::ungetq (ACE_Message_Block *mb, ACE_Time_Value *tv) } template <ACE_SYNCH_1> ACE_INLINE int -ACE_Task<ACE_SYNCH_2>::is_reader (void) -{ - ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::is_reader"); - return (ACE_BIT_ENABLED (this->flags_, ACE_Task_Flags::ACE_READER)); -} - -template <ACE_SYNCH_1> ACE_INLINE int -ACE_Task<ACE_SYNCH_2>::is_writer (void) -{ - ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::is_writer"); - return (ACE_BIT_DISABLED (this->flags_, ACE_Task_Flags::ACE_READER)); -} - -template <ACE_SYNCH_1> ACE_INLINE int ACE_Task<ACE_SYNCH_2>::flush (u_long flag) { ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::flush"); @@ -90,13 +113,25 @@ ACE_Task<ACE_SYNCH_2>::flush (u_long flag) return -1; // Note, need to be more careful about what we free... } -// Default ACE_Task service routine +template <ACE_SYNCH_1> ACE_INLINE void +ACE_Task<ACE_SYNCH_2>::msg_queue (ACE_Message_Queue<ACE_SYNCH_2> *mq) +{ + ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::msg_queue"); + this->msg_queue_ = mq; +} + +template <ACE_SYNCH_1> ACE_Message_Queue<ACE_SYNCH_2> * +ACE_Task<ACE_SYNCH_2>::msg_queue (void) +{ + ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::msg_queue"); + return this->msg_queue_; +} template <ACE_SYNCH_1> ACE_INLINE int -ACE_Task<ACE_SYNCH_2>::svc (void) +ACE_Task<ACE_SYNCH_2>::reply (ACE_Message_Block *mb, ACE_Time_Value *tv) { - ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::svc"); - return 0; + ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::reply"); + return this->sibling ()->put_next (mb, tv); } template <ACE_SYNCH_1> ACE_INLINE ACE_Task<ACE_SYNCH_2> * @@ -107,40 +142,12 @@ ACE_Task<ACE_SYNCH_2>::next (void) } template <ACE_SYNCH_1> ACE_INLINE void -ACE_Task<ACE_SYNCH_2>::next (ACE_Task<ACE_SYNCH_2> *q) +ACE_Task<ACE_SYNCH_2>::next (ACE_Task<ACE_SYNCH_2> *q) { ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::next"); this->next_ = q; } -template <ACE_SYNCH_1> ACE_INLINE ACE_Thread_Manager * -ACE_Task<ACE_SYNCH_2>::thr_mgr (void) -{ - ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::thr_mgr"); - return this->thr_mgr_; -} - -template <ACE_SYNCH_1> ACE_INLINE void -ACE_Task<ACE_SYNCH_2>::thr_mgr (ACE_Thread_Manager *thr_mgr) -{ - ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::thr_mgr"); - this->thr_mgr_ = thr_mgr; -} - -template <ACE_SYNCH_1> ACE_INLINE void -ACE_Task<ACE_SYNCH_2>::msg_queue (ACE_Message_Queue<ACE_SYNCH_2> *mq) -{ - ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::msg_queue"); - this->msg_queue_ = mq; -} - -template <ACE_SYNCH_1> ACE_Message_Queue<ACE_SYNCH_2> * -ACE_Task<ACE_SYNCH_2>::msg_queue (void) -{ - ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::msg_queue"); - return this->msg_queue_; -} - // Transfer msg to the next ACE_Task. template <ACE_SYNCH_1> ACE_INLINE int @@ -150,11 +157,3 @@ ACE_Task<ACE_SYNCH_2>::put_next (ACE_Message_Block *msg, ACE_Time_Value *tv) return this->next_ == 0 ? -1 : this->next_->put (msg, tv); } -template <ACE_SYNCH_1> ACE_INLINE int -ACE_Task<ACE_SYNCH_2>::reply (ACE_Message_Block *mb, ACE_Time_Value *tv) -{ - ACE_TRACE ("ACE_Task<ACE_SYNCH_2>::reply"); - return this->sibling ()->put_next (mb, tv); -} - - diff --git a/ace/Thread_Manager.cpp b/ace/Thread_Manager.cpp index c318081b424..c69df42ed22 100644 --- a/ace/Thread_Manager.cpp +++ b/ace/Thread_Manager.cpp @@ -194,7 +194,7 @@ ACE_Thread_Manager::spawn_i (ACE_THR_FUNC func, int grp_id, void *stack, size_t stack_size, - ACE_Task<ACE_SYNCH> *task) + ACE_Task_Base *task) { ACE_TRACE ("ACE_Thread_Manager::spawn_i"); ACE_thread_t thr_id; @@ -256,7 +256,7 @@ ACE_Thread_Manager::spawn_n (int n, long flags, u_int priority, int grp_id, - ACE_Task<ACE_SYNCH> *task) + ACE_Task_Base *task) { ACE_TRACE ("ACE_Thread_Manager::spawn_n"); ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1); @@ -284,7 +284,7 @@ ACE_Thread_Manager::append_thr (ACE_thread_t t_id, ACE_hthread_t t_handle, ACE_Thread_State thr_state, int grp_id, - ACE_Task<ACE_SYNCH> *task) + ACE_Task_Base *task) { ACE_TRACE ("ACE_Thread_Manager::append_thr"); // Try to resize the array to twice its existing size if we run out @@ -714,7 +714,7 @@ ACE_Thread_Manager::wait (const ACE_Time_Value *timeout) // Wait for task int -ACE_Thread_Manager::wait_task (ACE_Task<ACE_SYNCH> *task, +ACE_Thread_Manager::wait_task (ACE_Task_Base *task, const ACE_Time_Value *timeout) { // This method will be implemented in the future. The way we @@ -744,7 +744,7 @@ ACE_Thread_Manager::wait_group (int grp_id, } int -ACE_Thread_Manager::apply_task (ACE_Task<ACE_SYNCH> *task, +ACE_Thread_Manager::apply_task (ACE_Task_Base *task, THR_FUNC func, int arg) { @@ -763,7 +763,7 @@ ACE_Thread_Manager::apply_task (ACE_Task<ACE_SYNCH> *task, // Suspend a task int -ACE_Thread_Manager::suspend_task (ACE_Task<ACE_SYNCH> *task) +ACE_Thread_Manager::suspend_task (ACE_Task_Base *task) { ACE_TRACE ("ACE_Thread_Manager::suspend_task"); return this->apply_task (task, @@ -772,7 +772,7 @@ ACE_Thread_Manager::suspend_task (ACE_Task<ACE_SYNCH> *task) // Resume a task. int -ACE_Thread_Manager::resume_task (ACE_Task<ACE_SYNCH> *task) +ACE_Thread_Manager::resume_task (ACE_Task_Base *task) { ACE_TRACE ("ACE_Thread_Manager::resume_task"); return this->apply_task (task, @@ -781,7 +781,7 @@ ACE_Thread_Manager::resume_task (ACE_Task<ACE_SYNCH> *task) // Kill a task. int -ACE_Thread_Manager::kill_task (ACE_Task<ACE_SYNCH> *task, int /* signum */) +ACE_Thread_Manager::kill_task (ACE_Task_Base *task, int /* signum */) { ACE_TRACE ("ACE_Thread_Manager::kill_task"); return this->apply_task (task, @@ -790,7 +790,7 @@ ACE_Thread_Manager::kill_task (ACE_Task<ACE_SYNCH> *task, int /* signum */) // Cancel a task. int -ACE_Thread_Manager::cancel_task (ACE_Task<ACE_SYNCH> *task) +ACE_Thread_Manager::cancel_task (ACE_Task_Base *task) { ACE_TRACE ("ACE_Thread_Manager::cancel_task"); return this->apply_task (task, @@ -802,7 +802,7 @@ ACE_Thread_Manager::cancel_task (ACE_Task<ACE_SYNCH> *task) // lock held. int -ACE_Thread_Manager::find_task (ACE_Task<ACE_SYNCH> *task, +ACE_Thread_Manager::find_task (ACE_Task_Base *task, int index) { ACE_TRACE ("ACE_Thread_Manager::find_task"); @@ -838,7 +838,7 @@ ACE_Thread_Manager::num_tasks_in_group (int grp_id) // Returns the number of threads in an ACE_Task. int -ACE_Thread_Manager::num_threads_in_task (ACE_Task<ACE_SYNCH> *task) +ACE_Thread_Manager::num_threads_in_task (ACE_Task_Base *task) { ACE_TRACE ("ACE_Thread_Manager::num_threads_in_task"); ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1); @@ -856,13 +856,13 @@ ACE_Thread_Manager::num_threads_in_task (ACE_Task<ACE_SYNCH> *task) int ACE_Thread_Manager::task_list (int grp_id, - ACE_Task<ACE_SYNCH> *task_list[], + ACE_Task_Base *task_list[], size_t n) { ACE_TRACE ("ACE_Thread_Manager::task_list"); ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1); - ACE_Task<ACE_SYNCH> **task_list_iterator = task_list; + ACE_Task_Base **task_list_iterator = task_list; size_t task_list_count = 0; for (size_t i = 0; i < this->current_count_; i++) @@ -878,8 +878,9 @@ ACE_Thread_Manager::task_list (int grp_id, } // Returns in thread_list a list of thread ids in an ACE_Task. + int -ACE_Thread_Manager::thread_list (ACE_Task<ACE_SYNCH> *task, +ACE_Thread_Manager::thread_list (ACE_Task_Base *task, ACE_thread_t thread_list[], size_t n) { @@ -902,7 +903,7 @@ ACE_Thread_Manager::thread_list (ACE_Task<ACE_SYNCH> *task, // Returns in thread_list a list of thread handles in an ACE_Task. int -ACE_Thread_Manager::hthread_list (ACE_Task<ACE_SYNCH> *task, +ACE_Thread_Manager::hthread_list (ACE_Task_Base *task, ACE_hthread_t hthread_list[], size_t n) { @@ -925,7 +926,7 @@ ACE_Thread_Manager::hthread_list (ACE_Task<ACE_SYNCH> *task, } int -ACE_Thread_Manager::set_grp (ACE_Task<ACE_SYNCH> *task, int grp_id) +ACE_Thread_Manager::set_grp (ACE_Task_Base *task, int grp_id) { ACE_TRACE ("ACE_Thread_Manager::set_grp"); @@ -938,7 +939,7 @@ ACE_Thread_Manager::set_grp (ACE_Task<ACE_SYNCH> *task, int grp_id) } int -ACE_Thread_Manager::get_grp (ACE_Task<ACE_SYNCH> *task, int &grp_id) +ACE_Thread_Manager::get_grp (ACE_Task_Base *task, int &grp_id) { ACE_TRACE ("ACE_Thread_Manager::get_grp"); diff --git a/ace/Thread_Manager.h b/ace/Thread_Manager.h index 894925797c2..a4f9a623c71 100644 --- a/ace/Thread_Manager.h +++ b/ace/Thread_Manager.h @@ -23,7 +23,7 @@ #include "ace/Synch.h" // Forward declarations. -template <ACE_SYNCH_1> class ACE_Task; +class ACE_Task_Base; class ACE_Thread_Manager; class ACE_Export ACE_Thread_Descriptor @@ -49,7 +49,7 @@ public: ACE_Thread_State state (void); // Current state of the thread. - ACE_Task<ACE_SYNCH> *task_; + ACE_Task_Base *task_; // Pointer to an ACE_Task; private: @@ -97,7 +97,7 @@ public: long = 0, u_int = 0, int = -1 - ACE_Task<ACE_SYNCH> * = 0) { return -1;} + ACE_Task_Base * = 0) { return -1;} void *exit (void *) { return 0; } void wait (const ACE_Time_Value * = 0) {} int thread_descriptor (ACE_thread_t, ACE_Thread_Descriptor &) { return -1;} @@ -178,7 +178,7 @@ public: long flags = THR_NEW_LWP, u_int priority = 0, int grp_id = -1, - ACE_Task<ACE_SYNCH> *task = NULL); + ACE_Task_Base *task = NULL); // Create N new threads, all of which execute <func>. // Returns: on success a unique group id that can be used to control // all of the threads in the same group. On failure, returns -1. @@ -250,7 +250,7 @@ public: // = The following methods are new methods which resemble current methods in ACE_Thread Manager. For example, the new apply_task() method resembles the old apply_thr() method, and suspend_task() resembles suspend_thr(). - int wait_task (ACE_Task<ACE_SYNCH> *task, + int wait_task (ACE_Task_Base *task, const ACE_Time_Value *timeout = 0); // Block until there are no more threads running or <timeout> // expires in an ACE_Task. Returns 0 on success and -1 on failure. @@ -261,13 +261,13 @@ public: // expires in a group. Returns 0 on success and -1 on failure. // = Operations on ACE_Tasks. - int suspend_task (ACE_Task<ACE_SYNCH> *task); + int suspend_task (ACE_Task_Base *task); // Suspend all threads in an ACE_Task. - int resume_task (ACE_Task<ACE_SYNCH> *task); + int resume_task (ACE_Task_Base *task); // Resume all threads in an ACE_Task. - int kill_task (ACE_Task<ACE_SYNCH> *task, int signum); + int kill_task (ACE_Task_Base *task, int signum); // Kill all threads in an ACE_Task. - int cancel_task (ACE_Task<ACE_SYNCH> *task); + int cancel_task (ACE_Task_Base *task); // Cancel all threads in an ACE_Task. // = The following method provide new functionality. They do not follow the same design as current methods. They provide new functionality. @@ -275,23 +275,23 @@ public: int num_tasks_in_group (int grp_id); // Returns the number of ACE_Task in a group. - int num_threads_in_task (ACE_Task<ACE_SYNCH> *task); + int num_threads_in_task (ACE_Task_Base *task); // Returns the number of threads in an ACE_Task. int task_list (int grp_id, - ACE_Task<ACE_SYNCH> *task_list[], + ACE_Task_Base *task_list[], size_t n); // Returns in <task_list> a list of up to <n> <ACE_Tasks> in a // group. The caller must allocate the memory for <task_list> - int thread_list (ACE_Task<ACE_SYNCH> *task, + int thread_list (ACE_Task_Base *task, ACE_thread_t thread_list[], size_t n); // Returns in <thread_list> a list of up to <h> thread ids in an // <ACE_Task>. The caller must allocate the memory for // <thread_list>. - int hthread_list (ACE_Task<ACE_SYNCH> *task, + int hthread_list (ACE_Task_Base *task, ACE_hthread_t hthread_list[], size_t n); // Returns in <hthread_list> a list of up to <n> thread handles in @@ -299,8 +299,8 @@ public: // <hthread_list>. // = Set/get group ids for a particular task. - int set_grp (ACE_Task<ACE_SYNCH> *task, int grp_id); - int get_grp (ACE_Task<ACE_SYNCH> *task, int &grp_id); + int set_grp (ACE_Task_Base *task, int grp_id); + int get_grp (ACE_Task_Base *task, int &grp_id); void dump (void) const; // Dump the state of an object. @@ -321,14 +321,14 @@ private: int grp_id = -1, void *stack = 0, size_t stack_size = 0, - ACE_Task<ACE_SYNCH> *task = 0); + ACE_Task_Base *task = 0); // Create a new thread (must be called with locks held). int find (ACE_thread_t t_id); // Locate the index of the table slot occupied by <t_id>. Returns // -1 if <t_id> is not in the table doesn't contain <t_id>. - int find_task (ACE_Task<ACE_SYNCH> *task, int index = -1); + int find_task (ACE_Task_Base *task, int index = -1); // Locate the index of the table slot occupied by <task>. Returns // -1 if <task> is not in the table doesn't contain <task>. @@ -338,7 +338,7 @@ private: int append_thr (ACE_thread_t t_id, ACE_hthread_t, ACE_Thread_State, int grp_id, - ACE_Task<ACE_SYNCH> *task = 0); + ACE_Task_Base *task = 0); // Append a thread in the table (adds at the end, growing the table // if necessary). @@ -365,7 +365,7 @@ private: // This call updates the TSS cache if possible to speed up // subsequent searches. - int apply_task (ACE_Task<ACE_MT_SYNCH> *task, THR_FUNC, int = 0); + int apply_task (ACE_Task_Base *task, THR_FUNC, int = 0); // Apply <func> to all members of the table that match the <task> int apply_grp (int grp_id, THR_FUNC, int = 0); diff --git a/ace/XtReactor.cpp b/ace/XtReactor.cpp index ac497c64e40..b3ce9a152f5 100644 --- a/ace/XtReactor.cpp +++ b/ace/XtReactor.cpp @@ -28,6 +28,18 @@ ACE_XtReactor::ACE_XtReactor (XtAppContext context, id_len_ (0), ids_ (0) { + // When the ACE_Reactor is constructed it creates the notify pipe + // and registers it with the attach() method. The XtReactor + // overloads this method BUT because the attach occurs when + // constructing the base class ACE_Reactor, the ACE_Reactor attach() + // is called not the XtReactor attach(). This means that the notify + // pipe is registered with the ACE_Reactor event handling code not + // the XtReactor and so notfications don't work. To get around this + // we simply close and re-opened the notification handler in the + // constructor of the XtReactor. + + this->notification_handler_.close (); + this->notification_handler_.open (this); } ACE_XtReactor::~ACE_XtReactor (void) @@ -103,15 +115,15 @@ ACE_XtReactor::TimerCallbackProc (XtPointer closure, XtIntervalId *id) self->reset_timeout (); } -// This could be made shorter if we know which *kind* of event we -// were about to get. Here we use select () to find out which one -// might be available. +// This could be made shorter if we know which *kind* of event we were +// about to get. Here we use select () to find out which one might be +// available. void ACE_XtReactor::InputCallbackProc (XtPointer closure, - int * source, - XtInputId *id) + int * source, + XtInputId *id) { - ACE_XtReactor * self = (ACE_XtReactor*)closure; + ACE_XtReactor *self = (ACE_XtReactor *) closure; ACE_DEBUG ((LM_DEBUG, "ACE_XtReactor::Input on fd %d\n", *source)); @@ -179,8 +191,8 @@ XtAppContext ACE_XtReactor::context (void) int ACE_XtReactor::attach (ACE_HANDLE handle, - ACE_Event_Handler *handler, - ACE_Reactor_Mask mask) + ACE_Event_Handler *handler, + ACE_Reactor_Mask mask) { ACE_TRACE ("ACE_XtReactor::attach"); @@ -192,27 +204,33 @@ ACE_XtReactor::attach (ACE_HANDLE handle, return -1; // Ensure the list of InputId's is big enough - if (ids_ == 0 || id_len_ < handle + 1) + if (this->ids_ == 0 || this->id_len_ < handle + 1) { ACE_XtReactorID *more; ACE_NEW_RETURN (more, ACE_XtReactorID[handle + 1], -1); + int i; + for (i = 0; i < this->id_len_; i++) more[i] = ids_[i]; + for (i = this->id_len_; i < handle + 1; i++) more[i].good_id = 0; + id_len_ = handle + 1; delete this->ids_; ids_ = more; } int condition = 0; + if (mask & ACE_Event_Handler::READ_MASK) - condition |= XtInputReadMask; + ACE_SET_BITS (condition, XtInputReadMask); if (mask & ACE_Event_Handler::WRITE_MASK) - condition |= XtInputWriteMask; + ACE_SET_BITS (condition, XtInputWriteMask); if (mask & ACE_Event_Handler::EXCEPT_MASK) - condition |= XtInputExceptMask; + ACE_SET_BITS (condition, XtInputExceptMask); + if (condition != 0) { if (ids_[handle].good_id) @@ -293,7 +311,7 @@ ACE_XtReactor::schedule_timer (ACE_Event_Handler *handler, return result; this->reset_timeout (); - return 0; + return result; } int diff --git a/ace/config-win32-msvc4.0.h b/ace/config-win32-msvc4.0.h index 56a0deaaf96..af03633ea15 100644 --- a/ace/config-win32-msvc4.0.h +++ b/ace/config-win32-msvc4.0.h @@ -35,15 +35,20 @@ #ifdef _AFXDLL // May be defined by MSVC++ IDE #include <afxwin.h> // He is doing MFC +#define _INC_WINDOWS // Prevent winsock.h from including windows.h #endif #ifdef _WINDLL // May be defined by MSVC++ IDE #include <afxwin.h> // He is doing MFC +#define _INC_WINDOWS // Prevent winsock.h from including windows.h #endif #ifndef __AFX_H__ // set in afxwin.h #include <windows.h> // if he's not doing MFC, snag this #endif +// Needed for timeval. +#include <winsock.h> + #define ACE_HAS_UNICODE // Uncomment these if you want to integrate ACE and Orbix in Win32. @@ -166,10 +171,7 @@ #define ACE_NEEDS_WRITEV #define ACE_NEEDS_READV -// STRICT type checking in WINDOWS.H enhances type safety for Windows -// programs by using distinct types to represent all the different -// HANDLES in Windows. So for example, STRICT prevents you from -// mistakenly passing an HPEN to a routine expecting an HBITMAP. -#define STRICT - +// Comment this out for now since it will break existing application +// code. +#define ACE_HAS_STRICT #endif /* ACE_CONFIG_H */ |