@@ -11,7 +11,7 @@ struct SYNC_TIMER {
1111 ACL_FIBER * fb ;
1212 MBOX * box ;
1313 int stop ;
14- TIMER_CACHE * waiters ;
14+ // TIMER_CACHE *waiters;
1515 long tid ;
1616};
1717
@@ -23,7 +23,7 @@ static SYNC_TIMER *sync_timer_new(void)
2323
2424 pthread_mutex_init (& timer -> lock , NULL );
2525 timer -> box = mbox_create (MBOX_T_MPSC );
26- timer -> waiters = timer_cache_create ();
26+ // timer->waiters = timer_cache_create();
2727 timer -> tid = thread_self ();
2828
2929 out = mbox_out (timer -> box );
@@ -47,7 +47,7 @@ static void sync_timer_free(SYNC_TIMER *timer)
4747{
4848 pthread_mutex_destroy (& timer -> lock );
4949 mbox_free (timer -> box , NULL );
50- timer_cache_free (timer -> waiters );
50+ // timer_cache_free(timer->waiters);
5151 mem_free (timer );
5252}
5353
@@ -69,7 +69,7 @@ static void thread_init(void)
6969
7070static void wakeup_waiter (SYNC_TIMER * timer UNUSED , SYNC_OBJ * obj )
7171{
72- // The fiber must has been awakened by the other fiber or thread.
72+ // The fiber must have been awakened by the other fiber or thread.
7373
7474 if (obj -> delay < 0 ) {
7575 // No timer has been set if delay < 0,
@@ -117,9 +117,11 @@ static void fiber_waiting(ACL_FIBER *fiber fiber_unused, void *ctx)
117117 sync_obj_unrefer (obj );
118118 mem_free (msg );
119119
120+ /*
120121 if (timer_cache_size(timer->waiters) == 0) {
121122 delay = -1;
122123 }
124+ */
123125 }
124126}
125127
@@ -160,16 +162,35 @@ void sync_timer_wakeup(SYNC_TIMER *timer, SYNC_OBJ *obj)
160162 // message with the temporary FILE_EVENT.
161163
162164 SYNC_MSG * msg = (SYNC_MSG * ) mem_malloc (sizeof (SYNC_MSG ));
165+ socket_t out , out2 = INVALID_SOCKET ;
166+ FILE_EVENT * fe ;
167+
163168 msg -> obj = obj ;
164169 msg -> action = SYNC_ACTION_WAKEUP ;
165- socket_t out = mbox_out (timer -> box );
166- FILE_EVENT * fe = fiber_file_cache_get (out );
170+ sync_obj_refer (obj );
167171
168- fe -> mask |= EVENT_SYSIO ;
172+ out = mbox_out (timer -> box );
173+
174+ // Check if the out fd has been bound by the other fiber that
175+ // it was yield when calling acl_fiber_write in mbox_send2,
176+ // if so, we should duplicate another out fd to bind the new one.
177+ fe = fiber_file_get (out );
178+ if (fe ) {
179+ out2 = dup (out );
180+ msg_warn ("%s(%d): fe exists for out=%d, dup's out2=%d" ,
181+ __FUNCTION__ , __LINE__ , (int ) out , (int ) out2 );
182+ fe = fiber_file_cache_get (out2 );
183+ } else {
184+ fe = fiber_file_cache_get (out );
185+ }
169186
170- sync_obj_refer ( obj ) ;
171- mbox_send (timer -> box , msg );
187+ fe -> mask |= EVENT_SYSIO ;
188+ mbox_send2 (timer -> box , out2 != INVALID_SOCKET ? out2 : out , msg );
172189 fiber_file_cache_put (fe );
190+
191+ if (out2 != INVALID_SOCKET ) {
192+ acl_fiber_close (out2 );
193+ }
173194 } else {
174195 // If the current notifier is a fiber in the same thread with
175196 // the one to be awakened, just wakeup it directly.
0 commit comments