void portals_free(Portals *portals) { if (portals != NULL ) { portal_free(portals->bleu); portal_free(portals->orange); free(portals); } }
/** * private static native void getLinks0(Link[] linkarray); */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_links_LinkPortal_getLinks0(void) { int targetIsolate; jsize len; int i; KNI_StartHandles(2); KNI_DeclareHandle(linkArray); KNI_DeclareHandle(linkObj); targetIsolate = JVM_CurrentIsolateID(); KNI_GetParameterAsObject(1, linkArray); len = KNI_GetArrayLength(linkArray); if (portals != NULL) { if (portals[targetIsolate].count > 0) { rendezvous **rpp = portals[targetIsolate].rppa; for (i = 0; i < len; i++) { KNI_GetObjectArrayElement(linkArray, i, linkObj); setNativePointer(linkObj, rpp[i]); rp_incref(rpp[i]); } } portal_free(&portals[targetIsolate]); } KNI_EndHandles(); KNI_ReturnVoid(); }
/** * Shutdowns Links subsystem. */ void midp_links_shutdown() { if (portals != NULL) { int i; for (i = 0; i < JVM_MaxIsolates(); i++) { portal_free(&portals[i]); } pcsl_mem_free(portals); portals = NULL; } }
/** * private static native void setLinks0(int isolateid, Link[] linkarray); */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_links_LinkPortal_setLinks0(void) { int targetIsolate; int len; int i; int ok = 1; rendezvous *rp; rendezvous **newrppa = NULL; KNI_StartHandles(2); KNI_DeclareHandle(linkArray); KNI_DeclareHandle(linkObj); targetIsolate = KNI_GetParameterAsInt(1); KNI_GetParameterAsObject(2, linkArray); if (KNI_IsNullHandle(linkArray)) { len = 0; } else { len = KNI_GetArrayLength(linkArray); } for (i = 0; i < len; i++) { KNI_GetObjectArrayElement(linkArray, i, linkObj); rp = getNativePointer(linkObj); if (rp == NULL || rp->state == CLOSED) { ok = 0; KNI_ThrowNew(midpIllegalArgumentException, NULL); break; } } if (ok && portals == NULL) { portals = (portal *)pcsl_mem_malloc(JVM_MaxIsolates() * sizeof(portal)); if (portals == NULL) { ok = 0; KNI_ThrowNew(midpOutOfMemoryError, NULL); } else { int i; for (i = 0; i < JVM_MaxIsolates(); i++) { portals[i].count = -1; portals[i].rppa = NULL; } } } if (ok && len > 0) { newrppa = (rendezvous **)pcsl_mem_malloc(len * sizeof(rendezvous *)); if (newrppa == NULL) { KNI_ThrowNew(midpOutOfMemoryError, NULL); ok = 0; } } if (ok) { portal *pp = &portals[targetIsolate]; portal_free(pp); /* at this point the portal's count is zero and rppa is null */ if (len > 0) { for (i = 0; i < len; i++) { KNI_GetObjectArrayElement(linkArray, i, linkObj); rp = getNativePointer(linkObj); /* rp not null, checked above */ newrppa[i] = rp; rp_incref(rp); } pp->count = len; pp->rppa = newrppa; } else if (KNI_IsNullHandle(linkArray)) { pp->count = -1; pp->rppa = NULL; } else { /* len == 0 */ pp->count = 0; pp->rppa = NULL; } midp_thread_signal(LINK_PORTAL_SIGNAL, targetIsolate, 0); } KNI_EndHandles(); KNI_ReturnVoid(); }