You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/06/24 14:34:57 UTC

svn commit: r1139272 - /commons/sandbox/runtime/trunk/src/main/native/os/linux/epoll.c

Author: mturk
Date: Fri Jun 24 12:34:57 2011
New Revision: 1139272

URL: http://svn.apache.org/viewvc?rev=1139272&view=rev
Log:
Merge structs

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=1139272&r1=1139271&r2=1139272&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 12:34:57 2011
@@ -32,19 +32,15 @@
 #define PSS_WAIT        3
 #define PSS_WAKEUP      4
 
-typedef struct acr_pollfd_t {
+typedef struct pfd_elem_t pfd_elem_t;
+struct pfd_elem_t {
+    ACR_RING_ENTRY(pfd_elem_t) link;
     int            fd;
     short          ievents;
     short          revents;
     jobject        obj;
     acr_time_t     ttl;
     acr_time_t     exp;
-} acr_pollfd_t;
-
-typedef struct pfd_elem_t pfd_elem_t;
-struct pfd_elem_t {
-    ACR_RING_ENTRY(pfd_elem_t) link;
-    acr_pollfd_t pfd;
 };
 
 typedef struct acr_pollset_t {
@@ -157,17 +153,17 @@ ACR_NET_EXPORT(jlong, UnixSelector, crea
 
     /* Add the wakeup pipe to the pset
      */
-    pe->pfd.fd      = ps->wpipe[0];
-    pe->pfd.obj     = 0;
-    pe->pfd.ttl     = ACR_INFINITE;
-    pe->pfd.exp     = ACR_INFINITE;
-    pe->pfd.ievents = EPOLLIN;
-    pe->pfd.revents = 0;
+    pe->fd      = ps->wpipe[0];
+    pe->obj     = 0;
+    pe->ttl     = ACR_INFINITE;
+    pe->exp     = ACR_INFINITE;
+    pe->ievents = EPOLLIN;
+    pe->revents = 0;
 
     epipe.data.ptr = pe;
     epipe.events   = EPOLLIN;
     ACR_RING_INSERT_TAIL(&ps->eset_ring, pe, pfd_elem_t, link);
-    if (epoll_ctl(ps->epfd, EPOLL_CTL_ADD, pe->pfd.fd, &epipe) == -1) {
+    if (epoll_ctl(ps->epfd, EPOLL_CTL_ADD, pe->fd, &epipe) == -1) {
         /* Failed adding pipe to the pollset
          */
         ACR_THROW_NET_ERRNO();
@@ -225,11 +221,11 @@ ACR_NET_EXPORT(jint, UnixSelector, clr0)
         }
     }
     ACR_RING_FOREACH_SAFE(pe, np, &ps->eset_ring, pfd_elem_t, link) {
-        if (ps->wpipe[0] != pe->pfd.fd) {
-            epoll_ctl(ps->epfd, EPOLL_CTL_DEL, pe->pfd.fd, &eevent);
-            (*env)->SetObjectArrayElement(env, rs, cnt++, pe->pfd.obj);
+        if (ps->wpipe[0] != pe->fd) {
+            epoll_ctl(ps->epfd, EPOLL_CTL_DEL, pe->fd, &eevent);
+            (*env)->SetObjectArrayElement(env, rs, cnt++, pe->obj);
             /* Unref the container. */
-            (*env)->DeleteGlobalRef(env, pe->pfd.obj);
+            (*env)->DeleteGlobalRef(env, pe->obj);
             ACR_RING_REMOVE(pe, link);
             ACR_RING_INSERT_TAIL(&ps->free_ring, pe, pfd_elem_t, link);
         }
@@ -285,7 +281,7 @@ ACR_NET_EXPORT(jint, UnixSelector, add0)
         goto cleanup;
     }
     ACR_RING_FOREACH(pe, &ps->eset_ring, pfd_elem_t, link) {
-        if (fd->u.s == pe->pfd.fd) {
+        if (fd->u.s == pe->fd) {
             /* Duplicate descriptor
              */
             rc = ACR_EALREADY;
@@ -306,11 +302,11 @@ ACR_NET_EXPORT(jint, UnixSelector, add0)
         ACR_RING_ELEM_INIT(pe, link);
     }
     
-    pe->pfd.fd      = fd->u.s;
-    pe->pfd.ievents = ieventt(events);
-    pe->pfd.revents = 0;
-    pe->pfd.obj     = (*env)->NewGlobalRef(env, fo);
-    if (pe->pfd.obj == 0) {
+    pe->fd      = fd->u.s;
+    pe->ievents = ieventt(events);
+    pe->revents = 0;
+    pe->obj     = (*env)->NewGlobalRef(env, fo);
+    if (pe->obj == 0) {
         /* In case the NewGlobalRef fails,
          * OutOfMemoryError should be thrown already by the JVM.
          */
@@ -319,16 +315,16 @@ ACR_NET_EXPORT(jint, UnixSelector, add0)
         goto cleanup;
     }
     if (ttlms > 0) {
-        pe->pfd.ttl = AcrTimeFromMsec(ttlms);
-        pe->pfd.exp = AcrTimeNow() + pe->pfd.ttl;
+        pe->ttl = AcrTimeFromMsec(ttlms);
+        pe->exp = AcrTimeNow() + pe->ttl;
     }
     else {
-        pe->pfd.ttl = ACR_INFINITE;
-        pe->pfd.exp = ACR_INFINITE;
+        pe->ttl = ACR_INFINITE;
+        pe->exp = ACR_INFINITE;
     }
     eevent.data.ptr = pe;
-    eevent.events   = pe->pfd.ievents;
-    if (epoll_ctl(ps->epfd, EPOLL_CTL_ADD, pe->pfd.fd, &eevent) == 0) {
+    eevent.events   = pe->ievents;
+    if (epoll_ctl(ps->epfd, EPOLL_CTL_ADD, pe->fd, &eevent) == 0) {
         ps->used++;
         ACR_RING_INSERT_TAIL(&ps->eset_ring, pe, pfd_elem_t, link);
     }
@@ -357,9 +353,9 @@ ACR_NET_EXPORT(jint, UnixSelector, del0)
     }
     if (epoll_ctl(ps->epfd, EPOLL_CTL_DEL, fd->u.s, &eevent) == 0) {
         ACR_RING_FOREACH(pe, &ps->eset_ring, pfd_elem_t, link) {
-            if (fd->u.s == pe->pfd.fd) {
+            if (fd->u.s == pe->fd) {
                 /* Unref descriptor */
-                (*env)->DeleteGlobalRef(env, pe->pfd.obj);
+                (*env)->DeleteGlobalRef(env, pe->obj);
                 ACR_RING_REMOVE(pe, link);
                 ACR_RING_INSERT_TAIL(&ps->dead_ring, pe, pfd_elem_t, link);
                 ps->used--;
@@ -410,10 +406,10 @@ ACR_NET_EXPORT(int, UnixSelector, destro
         AcrFree(pe);
     }
     ACR_RING_FOREACH_SAFE(pe, np, &ps->free_ring, pfd_elem_t, link) {
-        if (pe->pfd.obj != 0) {
-            AcrSelectionKeyReset(env, pe->pfd.obj);
+        if (pe->obj != 0) {
+            AcrSelectionKeyReset(env, pe->obj);
             /* Unref descriptor */
-            (*env)->DeleteGlobalRef(env, pe->pfd.obj);
+            (*env)->DeleteGlobalRef(env, pe->obj);
         }
         ACR_RING_REMOVE(pe, link);
         AcrFree(pe);
@@ -516,7 +512,7 @@ ACR_NET_EXPORT(jint, UnixSelector, wait0
     for (i = 0; i < ns; i++) {
         pe = (pfd_elem_t *)ps->epset[i].data.ptr;
         if (ps->epset[i].events != 0) {
-            if (pe->pfd.fd == ps->wpipe[0]) {
+            if (pe->fd == ps->wpipe[0]) {
                 /* Drain the wakeup pipe.
                  * Wakeup pipe is always at index zero.
                  */
@@ -525,21 +521,21 @@ ACR_NET_EXPORT(jint, UnixSelector, wait0
             }
             else {
                 pevents[rv] = reventt(ps->epset[i].events);
-                (*env)->SetObjectArrayElement(env, rs, rv++, pe->pfd.obj);
+                (*env)->SetObjectArrayElement(env, rs, rv++, pe->obj);
                 if (autocancel == JNI_TRUE) {
-                    epoll_ctl(ps->epfd, EPOLL_CTL_DEL, pe->pfd.fd, &eevent);
+                    epoll_ctl(ps->epfd, EPOLL_CTL_DEL, pe->fd, &eevent);
                     ps->used--;
                     /* Unref descriptor */
-                    (*env)->DeleteGlobalRef(env, pe->pfd.obj);
+                    (*env)->DeleteGlobalRef(env, pe->obj);
                     ACR_RING_REMOVE(pe, link);
                     ACR_RING_INSERT_TAIL(&ps->free_ring, pe, pfd_elem_t, link);
                 }
-                else if (pe->pfd.ttl > 0) {
+                else if (pe->ttl > 0) {
                     /* Reset TTL
                      */
                     if (now == 0)
                         now = AcrTimeNow();
-                    pe->pfd.exp = now + pe->pfd.ttl;
+                    pe->exp = now + pe->ttl;
                 }
             }
         }
@@ -547,17 +543,17 @@ ACR_NET_EXPORT(jint, UnixSelector, wait0
 cleanup:
     /* Remove expired descriptors */
     ACR_RING_FOREACH_SAFE(pe, np, &ps->eset_ring, pfd_elem_t, link) {
-        if (pe->pfd.ttl > 0) {
+        if (pe->ttl > 0) {
             if (now == 0)
                 now = AcrTimeNow();
-            if (now > pe->pfd.exp) {
+            if (now > pe->exp) {
                 /* Expired descriptor */
                 pevents[rv] = ACR_OP_TIMEOUT;
-                (*env)->SetObjectArrayElement(env, rs, rv++, pe->pfd.obj);
+                (*env)->SetObjectArrayElement(env, rs, rv++, pe->obj);
                 if (autocancel == JNI_TRUE) {
                     /* Unref descriptor */
-                    epoll_ctl(ps->epfd, EPOLL_CTL_DEL, pe->pfd.fd, &eevent);
-                    (*env)->DeleteGlobalRef(env, pe->pfd.obj);
+                    epoll_ctl(ps->epfd, EPOLL_CTL_DEL, pe->fd, &eevent);
+                    (*env)->DeleteGlobalRef(env, pe->obj);
                     ACR_RING_REMOVE(pe, link);
                     ACR_RING_INSERT_TAIL(&ps->free_ring, pe, pfd_elem_t, link);
                     ps->used--;