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/05/23 20:48:40 UTC
svn commit: r1126656 -
/commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c
Author: mturk
Date: Mon May 23 18:48:40 2011
New Revision: 1126656
URL: http://svn.apache.org/viewvc?rev=1126656&view=rev
Log:
No need to check if the object is NULL. It must not be added as NULL at the first place
Modified:
commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c?rev=1126656&r1=1126655&r2=1126656&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c Mon May 23 18:48:40 2011
@@ -35,6 +35,7 @@
typedef struct acr_pollfd_t {
jobject obj;
acr_time_t ttl;
+ acr_time_t exp;
} acr_pollfd_t;
typedef struct acr_pollset_t {
@@ -141,6 +142,7 @@ ACR_NET_EXPORT(jlong, Pollset, create0)(
ps->fdset[0].revents = 0;
ps->ooset[0].obj = 0;
ps->ooset[0].ttl = ACR_INFINITE;
+ ps->ooset[0].exp = ACR_INFINITE;
if (pthread_cond_init(&ps->wakeup, 0) != 0) {
ACR_THROW_NET_ERRNO();
@@ -184,13 +186,12 @@ ACR_NET_EXPORT(void, Pollset, destroy0)(
}
}
ps->state = PSS_DESTROY;
- pthread_mutex_unlock(&ps->mutex);
for (i = 1; i < ps->used; i++) {
- if (ps->ooset[i].obj != 0) {
- /* Invalidate the container. */
- (*env)->DeleteGlobalRef(env, ps->ooset[i].obj);
- }
+ /* Invalidate the container. */
+ (*env)->DeleteGlobalRef(env, ps->ooset[i].obj);
}
+ ps->used = 0;
+ pthread_mutex_unlock(&ps->mutex);
r_close(ps->wpipe[0]);
r_close(ps->wpipe[1]);
pthread_cond_destroy(&ps->wakeup);
@@ -230,10 +231,8 @@ ACR_NET_EXPORT(jint, Pollset, clear0)(JN
}
}
for (i = 1; i < ps->used; i++) {
- if (ps->ooset[i].obj != 0) {
- (*env)->SetObjectArrayElement(env, rs, cnt++, ps->ooset[i].obj);
- (*env)->DeleteGlobalRef(env, ps->ooset[i].obj);
- }
+ (*env)->SetObjectArrayElement(env, rs, cnt++, ps->ooset[i].obj);
+ (*env)->DeleteGlobalRef(env, ps->ooset[i].obj);
}
ps->used = 1;
pthread_mutex_unlock(&ps->mutex);
@@ -340,12 +339,20 @@ ACR_NET_EXPORT(jint, Pollset, wait0)(JNI
else {
pevents[rv] = reventt(ps->fdset[i].revents);
(*env)->SetObjectArrayElement(env, rs, rv++, ps->ooset[i].obj);
+ if (rmsignaled == JNI_FALSE && ps->ooset[i].ttl > 0) {
+ /* Reset TTL if we are not going to remove
+ * the descriptor from this pollset
+ */
+ if (now == 0)
+ now = AcrTimeNow();
+ ps->ooset[i].exp = now + ps->ooset[i].ttl;
+ }
}
}
else {
if (now == 0)
- now = AcrTimeNow();
- if (ps->ooset[i].ttl > 0 && ps->ooset[i].ttl > now) {
+ now = AcrTimeNow();
+ if (ps->ooset[i].ttl > 0 && ps->ooset[i].exp > now) {
/* Expired descriptor */
ps->fdset[i].revents = POLLHUP;
pevents[rv] = ACR_POLLTTL;
@@ -363,13 +370,12 @@ ACR_NET_EXPORT(jint, Pollset, wait0)(JNI
int dest = i;
int used = ps->used;
ps->used--;
- if (ps->ooset[i].obj != 0) {
- (*env)->DeleteGlobalRef(env, ps->ooset[i].obj);
- ps->ooset[i].obj = 0;
- }
+ /* Unref descriptor */
+ (*env)->DeleteGlobalRef(env, ps->ooset[i].obj);
for (++i; i < used; i++) {
if (ps->fdset[i].revents != 0) {
/* Skip signaled descriptor */
+ (*env)->DeleteGlobalRef(env, ps->ooset[i].obj);
ps->used--;
}
else {
@@ -417,10 +423,21 @@ ACR_NET_EXPORT(jint, Pollset, add0)(JNI_
ps->fdset[ps->used].events = ieventt(events);
ps->fdset[ps->used].revents = 0;
ps->ooset[ps->used].obj = (*env)->NewGlobalRef(env, fo);
- if (ttlms > 0)
- ps->ooset[ps->used].ttl = AcrTimeNow() + AcrTimeFromMsec(ttlms);
- else
+ if (ps->ooset[ps->used].obj == 0) {
+ /* In case the NewGlobalRef fails,
+ * OutOfMemoryError should be thrown already by the JVM.
+ */
+ rc = ACR_ENOMEM;
+ goto cleanup;
+ }
+ if (ttlms > 0) {
+ ps->ooset[ps->used].ttl = AcrTimeFromMsec(ttlms);
+ ps->ooset[ps->used].exp = AcrTimeNow() + ps->ooset[ps->used].ttl;
+ }
+ else {
ps->ooset[ps->used].ttl = ACR_INFINITE;
+ ps->ooset[ps->used].exp = ACR_INFINITE;
+ }
ps->used++;
cleanup:
pthread_mutex_unlock(&ps->mutex);