Author: mturk
Date: Fri Jun 24 11:25:28 2011
New Revision: 1139247

URL: http://svn.apache.org/viewvc?rev=1139247&view=rev
Log:
Remove from epollset only if autocancel is true

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/linux/epoll.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/linux/epoll.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/linux/epoll.c?rev=1139247&r1=1139246&r2=1139247&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/linux/epoll.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/linux/epoll.c Fri Jun 24 
11:25:28 2011
@@ -436,7 +436,7 @@ ACR_NET_EXPORT(jint, LinuxSelector, wait
     int rv = 0;
     jshort *pevents;
     struct epoll_event eevent = { 0 };
-    pfd_elem_t *pe = 0;
+    pfd_elem_t *np, *pe = 0;
     acr_time_t now = 0;
     acr_time_t tmx = 0;
     acr_pollset_t *ps = J2P(pollset, acr_pollset_t *);
@@ -551,24 +551,28 @@ ACR_NET_EXPORT(jint, LinuxSelector, wait
         }
     }
     /* Remove expired descriptors */
-    ACR_RING_FOREACH(pe, &ps->eset_ring, pfd_elem_t, link) {
+    ACR_RING_FOREACH_SAFE(pe, np, &ps->eset_ring, pfd_elem_t, link) {
         if (pe->pfd.ttl > 0) {
             if (now == 0)
                 now = AcrTimeNow();
             if (pe->pfd.exp > now) {
                 /* Expired descriptor */
-                epoll_ctl(ps->epfd, EPOLL_CTL_DEL, pe->pfd.fd, &eevent);
                 pevents[rv] = ACR_OP_TIMEOUT;
-                (*env)->SetObjectArrayElement(env, rs, rv++, pe->pfd.obj);     
       
-                /* Unref descriptor */
-                (*env)->DeleteGlobalRef(env, pe->pfd.obj);
-                ACR_RING_REMOVE(pe, link);
-                ACR_RING_INSERT_TAIL(&ps->dead_ring, pe, pfd_elem_t, link);
-                ps->used--;
+                (*env)->SetObjectArrayElement(env, rs, rv++, pe->pfd.obj);
+                if (autocancel == JNI_TRUE) {
+                    /* Unref descriptor */
+                    epoll_ctl(ps->epfd, EPOLL_CTL_DEL, pe->pfd.fd, &eevent);
+                    (*env)->DeleteGlobalRef(env, pe->pfd.obj);
+                    ACR_RING_REMOVE(pe, link);
+                    ACR_RING_INSERT_TAIL(&ps->free_ring, pe, pfd_elem_t, link);
+                    ps->used--;
+                }
             }
         }
     }    
     RELEASE_CRITICAL(revents, pevents);
+    /* Shift all PFDs in the Dead Ring to the Free Ring */
+    ACR_RING_CONCAT(&ps->free_ring, &ps->dead_ring, pfd_elem_t, link);
     ps->state = 0;
     pthread_cond_broadcast(&ps->wakeup);
     pthread_mutex_unlock(&ps->mutex);


Reply via email to