summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralex <alex@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-05-12 21:26:23 +0000
committeralex <alex@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-05-12 21:26:23 +0000
commit3cbd98dd2c3d67aa7a3be27160efd70a605db912 (patch)
tree64faa4a37de977099473389f270cbe71432803bd
parent82d0e1c4edd7590a357fbf13b1adfb529c01b503 (diff)
downloadATCD-3cbd98dd2c3d67aa7a3be27160efd70a605db912.tar.gz
Fixed the problem with terminating the Timer thread. Also, fixed the
places where conversion between void * and ACE_POSIX_Asynch_Result. Used ACE_reinterpret_cast at these places.
-rw-r--r--ace/POSIX_Asynch_IO.cpp23
-rw-r--r--ace/POSIX_Proactor.cpp43
-rw-r--r--ace/POSIX_Proactor.h5
-rw-r--r--ace/Proactor.cpp16
-rw-r--r--examples/Reactor/Proactor/test_proactor.cpp8
5 files changed, 65 insertions, 30 deletions
diff --git a/ace/POSIX_Asynch_IO.cpp b/ace/POSIX_Asynch_IO.cpp
index ba5fce80ba6..b3375aa5187 100644
--- a/ace/POSIX_Asynch_IO.cpp
+++ b/ace/POSIX_Asynch_IO.cpp
@@ -533,8 +533,9 @@ ACE_POSIX_SIG_Asynch_Read_Stream::shared_read (ACE_POSIX_Asynch_Read_Stream_Resu
// We want queuing of RT signal to notify completion.
result->aio_sigevent.sigev_notify = SIGEV_SIGNAL;
result->aio_sigevent.sigev_signo = result->signal_number ();
- result->aio_sigevent.sigev_value.sival_ptr = (void *) result;
-
+ result->aio_sigevent.sigev_value.sival_ptr = ACE_reinterpret_cast (void *,
+ (ACE_POSIX_Asynch_Result *) result);
+
// Fire off the aio read.
if (aio_read (result) == -1)
// Queueing failed.
@@ -861,7 +862,8 @@ ACE_POSIX_SIG_Asynch_Write_Stream::shared_write (ACE_POSIX_Asynch_Write_Stream_R
// We want queuing of RT signal to notify completion.
result->aio_sigevent.sigev_notify = SIGEV_SIGNAL;
result->aio_sigevent.sigev_signo = result->signal_number ();
- result->aio_sigevent.sigev_value.sival_ptr = (void *) result;
+ result->aio_sigevent.sigev_value.sival_ptr = ACE_reinterpret_cast (void *,
+ (ACE_POSIX_Asynch_Result *) result);
// Fire off the aio write.
if (aio_write (result) == -1)
@@ -2079,7 +2081,7 @@ ACE_POSIX_AIOCB_Asynch_Accept::open (ACE_Handler &handler,
// Spawn the thread. It is the only thread we are going to have. It
// will do the <handle_events> on the reactor.
return_val = ACE_Thread_Manager::instance ()->spawn (ACE_POSIX_AIOCB_Asynch_Accept::thread_function,
- (void *) &this->reactor_);
+ ACE_reinterpret_cast (void *, &this->reactor_));
if (return_val == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%N:%l:Thread_Manager::spawn failed\n"),
@@ -2098,7 +2100,8 @@ ACE_POSIX_AIOCB_Asynch_Accept::thread_function (void* arg_reactor)
ACE_DEBUG ((LM_DEBUG, "ACE_Asynch_Accept::thread_function called\n"));
// Retrieve the reactor pointer from the argument.
- ACE_Reactor* reactor = (ACE_Reactor *) arg_reactor;
+ ACE_Reactor* reactor = ACE_reinterpret_cast (ACE_Reactor *,
+ arg_reactor);
// It should be valid Reactor, since we have a reactor_ ,e,ner we
// are passing only that one here.
@@ -2247,7 +2250,8 @@ void*
ACE_POSIX_SIG_Asynch_Accept::thread_function (void* arg_reactor)
{
// Retrieve the reactor pointer from the argument.
- ACE_Reactor* reactor = (ACE_Reactor *) arg_reactor;
+ ACE_Reactor* reactor = ACE_reinterpret_cast (ACE_Reactor *,
+ arg_reactor);
if (reactor == 0)
reactor = ACE_Reactor::instance ();
@@ -2665,7 +2669,7 @@ ACE_POSIX_AIOCB_Asynch_Transmit_Handler::transmit (void)
// Transmit the header.
if (this->ws_.write (*this->result_->header_and_trailer ()->header (),
this->result_->header_and_trailer ()->header_bytes (),
- (void *) &this->header_act_,
+ ACE_reinterpret_cast (void *, &this->header_act_),
0) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"Asynch_Transmit_Handler:transmitting header:write_stream failed\n"),
@@ -2734,7 +2738,7 @@ ACE_POSIX_AIOCB_Asynch_Transmit_Handler::handle_write_stream (const ACE_Asynch_W
// Not a partial write. A full write.
// Check ACT to see what was sent.
- ACT act = *(ACT *) result.act ();
+ ACT act = * (ACT *) result.act ();
switch (act)
{
@@ -2900,7 +2904,8 @@ ACE_POSIX_SIG_Asynch_Transmit_Handler::transmit (void)
// Transmit the header.
if (this->ws_.write (*this->result_->header_and_trailer ()->header (),
this->result_->header_and_trailer ()->header_bytes (),
- (void *) &this->header_act_,
+ ACE_reinterpret_cast (void *,
+ &this->header_act_),
this->result_->priority (),
this->result_->signal_number ()) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
diff --git a/ace/POSIX_Proactor.cpp b/ace/POSIX_Proactor.cpp
index 38aac828254..edaabee4098 100644
--- a/ace/POSIX_Proactor.cpp
+++ b/ace/POSIX_Proactor.cpp
@@ -290,7 +290,7 @@ void
ACE_POSIX_Proactor::application_specific_code (ACE_POSIX_Asynch_Result *asynch_result,
u_long bytes_transferred,
int success,
- const void *completion_key,
+ const void */* completion_key*/,
u_long error)
{
ACE_SEH_TRY
@@ -298,7 +298,7 @@ ACE_POSIX_Proactor::application_specific_code (ACE_POSIX_Asynch_Result *asynch_r
// Call completion hook
asynch_result->complete (bytes_transferred,
success,
- (void *) completion_key,
+ 0, // No completion key.
error);
}
ACE_SEH_FINALLY
@@ -410,7 +410,8 @@ ACE_AIOCB_Notify_Pipe_Manager::notify (ACE_POSIX_Asynch_Result *result)
{
// Send the result pointer through the pipe.
int return_val = ACE::send (this->pipe_.write_handle (),
- (char *) &result,
+ ACE_reinterpret_cast (char *,
+ &result),
sizeof (result));
if (return_val != sizeof (result))
ACE_ERROR_RETURN ((LM_ERROR,
@@ -562,12 +563,22 @@ ACE_POSIX_AIOCB_Proactor::handle_events (unsigned long milli_seconds)
{
int result_suspend = 0;
if (milli_seconds == ACE_INFINITE)
- // Indefinite blocking.
- result_suspend = aio_suspend (this->aiocb_list_,
- this->aiocb_list_max_size_,
- 0);
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ "ACE_POSIX_AIOCB_Proactor::handle_events:"
+ "Indefinite blocking on aio_suspend\n"));
+
+ // Indefinite blocking.
+ result_suspend = aio_suspend (this->aiocb_list_,
+ this->aiocb_list_max_size_,
+ 0);
+ }
else
{
+ ACE_DEBUG ((LM_DEBUG,
+ "ACE_POSIX_AIOCB_Proactor::handle_events:"
+ "Finite blocking on aio_suspend\n"));
+
// Block on <aio_suspend> for <milli_seconds>
timespec timeout;
timeout.tv_sec = milli_seconds / 1000;
@@ -576,6 +587,10 @@ ACE_POSIX_AIOCB_Proactor::handle_events (unsigned long milli_seconds)
this->aiocb_list_max_size_,
&timeout);
}
+
+ ACE_DEBUG ((LM_DEBUG,
+ "ACE_POSIX_AIOCB_Proactor::handle_events: result_aiosuspend %d\n",
+ result_suspend));
// Check for errors
if (result_suspend == -1)
@@ -639,7 +654,8 @@ ACE_POSIX_AIOCB_Proactor::handle_events (unsigned long milli_seconds)
// Retrive the result pointer.
ACE_POSIX_Asynch_Result *asynch_result =
- (ACE_POSIX_Asynch_Result *) this->aiocb_list_[ai];
+ ACE_dynamic_cast (ACE_POSIX_Asynch_Result *,
+ this->aiocb_list_[ai]);
// Invalidate entry in the aiocb list.
@@ -827,7 +843,8 @@ ACE_POSIX_SIG_Proactor::post_completion (ACE_POSIX_Asynch_Result *result)
// Set the signal information.
sigval value;
- value.sival_ptr = (void *) result;
+ value.sival_ptr = ACE_reinterpret_cast (void *,
+ result);
// Queue the signal.
if (sigqueue (pid, result->signal_number (), value) == -1)
@@ -1051,14 +1068,14 @@ ACE_POSIX_SIG_Proactor::handle_events (unsigned long milli_seconds)
-1);
// Retrive the result pointer.
- ACE_POSIX_Asynch_Result *asynch_result =
- (ACE_POSIX_Asynch_Result *) sig_info.si_value.sival_ptr;
+ ACE_POSIX_Asynch_Result *asynch_result = ACE_reinterpret_cast (ACE_POSIX_Asynch_Result *,
+ sig_info.si_value.sival_ptr);
// Check the <signal code> and act according to that.
if (sig_info.si_code == SI_ASYNCIO)
{
// Analyze error and return values.
-
+
// Check the error status
int error_status = aio_error (asynch_result);
if (error_status == -1)
@@ -1090,7 +1107,7 @@ ACE_POSIX_SIG_Proactor::handle_events (unsigned long milli_seconds)
this->application_specific_code (asynch_result,
return_status,
1, // Result : True.
- 0, // No completion_signal.
+ 0, // No completion key.
error_status); // Error.
}
}
diff --git a/ace/POSIX_Proactor.h b/ace/POSIX_Proactor.h
index f868d354034..45305a241e1 100644
--- a/ace/POSIX_Proactor.h
+++ b/ace/POSIX_Proactor.h
@@ -170,7 +170,10 @@ protected:
const void *completion_key,
u_long error);
// Protect against structured exceptions caused by user code when
- // dispatching handles.
+ // dispatching handles. The <completion_key> is not very useful
+ // compared to <AST> that can be associated each asynchronous
+ // operation. <completion_key> is implemented right now for the
+ // POSIX Proators.
};
// Forward declarations.
diff --git a/ace/Proactor.cpp b/ace/Proactor.cpp
index 2d261e550bd..7d7a2c1ad3c 100644
--- a/ace/Proactor.cpp
+++ b/ace/Proactor.cpp
@@ -56,9 +56,14 @@ public:
ACE_Proactor_Timer_Handler (ACE_Proactor &proactor);
// Constructor.
- ~ACE_Proactor_Timer_Handler (void);
+ virtual ~ACE_Proactor_Timer_Handler (void);
// Destructor.
+ int destroy (void);
+ // Proactor calls this to shut down the timer handler
+ // gracefully. Just calling the destructor alone doesnt do what
+ // <destroy> does. <destroy> make sure the thread exits properly.
+
protected:
virtual int svc (void);
// Run by a daemon thread to handle deferred processing. In other
@@ -89,6 +94,9 @@ ACE_Proactor_Timer_Handler::~ACE_Proactor_Timer_Handler (void)
// Signal timer event.
this->timer_event_.signal ();
+
+ // Wait for the Timer Handler thread to exit.
+ this->thr_mgr ()->wait ();
}
int
@@ -402,15 +410,15 @@ ACE_Proactor::close (void)
delete this->implementation ();
this->implementation_ = 0;
}
-
- // Take care of the timer handler
+
+ // Delete the timer handler.
if (this->timer_handler_)
{
delete this->timer_handler_;
this->timer_handler_ = 0;
}
- // Take care of the timer queue
+ // Delete the timer queue.
if (this->delete_timer_queue_)
{
delete this->timer_queue_;
diff --git a/examples/Reactor/Proactor/test_proactor.cpp b/examples/Reactor/Proactor/test_proactor.cpp
index 37c93cd7f57..89fe5e67ef2 100644
--- a/examples/Reactor/Proactor/test_proactor.cpp
+++ b/examples/Reactor/Proactor/test_proactor.cpp
@@ -303,6 +303,9 @@ private:
ACE_Asynch_Read_File rf_;
// rf (read file): for writing from the file
+ ACE_Asynch_Transmit_File tf_;
+ // Transmit file.
+
ACE_HANDLE input_file_;
// File to read from
@@ -397,8 +400,7 @@ Sender::transmit_file (void)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "ACE_OS::open"), -1);
// Open ACE_Asynch_Transmit_File
- ACE_Asynch_Transmit_File tf;
- if (tf.open (*this) == -1)
+ if (this->tf_.open (*this) == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "ACE_Asynch_Transmit_File::open"), -1);
// Header and trailer data for the file.
@@ -409,7 +411,7 @@ Sender::transmit_file (void)
this->welcome_message_.length ());
// Send it
- if (tf.transmit_file (file_handle,
+ if (this->tf_.transmit_file (file_handle,
&this->header_and_trailer_) == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "ACE_Asynch_Transmit_File::transmit_file"), -1);