@@ -11,13 +11,15 @@ ACE_BEGIN_VERSIONED_NAMESPACE_DECL
1111
1212ACE_POSIX_CB_Proactor::Notification_State::Notification_State (ACE_SYNCH_SEMAPHORE &sema)
1313 : sema_ (&sema),
14- pending_callbacks_ (0 )
14+ pending_callbacks_ (0 ),
15+ ref_count_ (0 )
1516{
1617}
1718
1819void
1920ACE_POSIX_CB_Proactor::Notification_State::add_pending (void )
2021{
22+ this ->add_ref ();
2123 ++this ->pending_callbacks_ ;
2224}
2325
@@ -26,6 +28,7 @@ ACE_POSIX_CB_Proactor::Notification_State::complete_one (void)
2628{
2729 this ->sema_ ->release ();
2830 --this ->pending_callbacks_ ;
31+ this ->remove_ref ();
2932}
3033
3134long
@@ -34,13 +37,27 @@ ACE_POSIX_CB_Proactor::Notification_State::pending (void) const
3437 return this ->pending_callbacks_ .value ();
3538}
3639
40+ void
41+ ACE_POSIX_CB_Proactor::Notification_State::add_ref (void )
42+ {
43+ ++this ->ref_count_ ;
44+ }
45+
46+ void
47+ ACE_POSIX_CB_Proactor::Notification_State::remove_ref (void )
48+ {
49+ if (--this ->ref_count_ == 0 )
50+ delete this ;
51+ }
52+
3753ACE_POSIX_CB_Proactor::ACE_POSIX_CB_Proactor (size_t max_aio_operations)
3854 : ACE_POSIX_AIOCB_Proactor (max_aio_operations,
3955 ACE_POSIX_Proactor::PROACTOR_CB),
4056 sema_ ((unsigned int ) 0),
4157 notification_state_ (0 )
4258{
4359 ACE_NEW (this ->notification_state_ , Notification_State (this ->sema_ ));
60+ this ->notification_state_ ->add_ref ();
4461
4562 // we should start pseudo-asynchronous accept task
4663 // one per all future acceptors
@@ -79,24 +96,23 @@ ACE_POSIX_CB_Proactor_aio_completion (sigval cb_data)
7996int
8097ACE_POSIX_CB_Proactor::close (void )
8198{
82- const int result = ACE_POSIX_AIOCB_Proactor::close ();
99+ int const result = ACE_POSIX_AIOCB_Proactor::close ();
83100
84101 Notification_State *state = this ->notification_state_ ;
85102 if (state != 0 )
86103 {
87- const ACE_Time_Value settle_interval (0 , 10000 );
88- const size_t max_settle_attempts = 50 ;
104+ this ->notification_state_ = 0 ;
105+
106+ ACE_Time_Value const settle_interval (0 , 10000 );
107+ size_t const max_settle_attempts = 50 ;
89108
90109 for (size_t attempt = 0 ;
91110 state->pending () > 0 && attempt < max_settle_attempts;
92111 ++attempt)
93112 ACE_OS::sleep (settle_interval);
94113
95- if (state->pending () == 0 )
96- {
97- delete state;
98- this ->notification_state_ = 0 ;
99- }
114+ state->detach ();
115+ state->remove_ref ();
100116 }
101117
102118 return result;
@@ -117,10 +133,8 @@ ACE_POSIX_CB_Proactor::handle_events (void)
117133}
118134
119135int
120- ACE_POSIX_CB_Proactor::notify_completion (int sig_num)
136+ ACE_POSIX_CB_Proactor::notify_completion (int /* sig_num */ )
121137{
122- ACE_UNUSED_ARG (sig_num);
123-
124138 return this ->sema_ .release ();
125139}
126140
@@ -262,28 +276,31 @@ ACE_POSIX_CB_Proactor::start_aio (ACE_POSIX_Asynch_Result *result,
262276 return -1 ;
263277 }
264278
265- const ssize_t slot = this ->allocate_aio_slot (result);
279+ ssize_t const slot = this ->allocate_aio_slot (result);
266280 if (slot < 0 )
267281 return -1 ;
268282
269- const size_t index = static_cast <size_t > (slot);
283+ size_t const index = static_cast <size_t > (slot);
270284 this ->result_list_ [index] = result;
271285 ++this ->aiocb_list_cur_size_ ;
272286
287+ if (this ->notification_state_ != 0 )
288+ this ->notification_state_ ->add_pending ();
289+
273290 ret_val = this ->start_aio_i (result);
274291 switch (ret_val)
275292 {
276293 case 0 :
277294 this ->aiocb_list_ [index] = result;
278- if (this ->notification_state_ != 0 )
279- this ->notification_state_ ->add_pending ();
280295 return 0 ;
281296
282297 case 1 :
283298 ++this ->num_deferred_aiocb_ ;
284299 return 0 ;
285300
286301 default :
302+ if (this ->notification_state_ != 0 )
303+ this ->notification_state_ ->complete_one ();
287304 break ;
288305 }
289306
0 commit comments