Пример #1
0
 /** Close the native library we're mapped to. */
 public void dispose() {
   synchronized (libraries) {
     for (Iterator i = libraries.values().iterator(); i.hasNext(); ) {
       Reference ref = (WeakReference) i.next();
       if (ref.get() == this) {
         i.remove();
       }
     }
   }
   synchronized (this) {
     if (handle != 0) {
       Native.close(handle);
       handle = 0;
     }
   }
 }
 void terminate() throws IOException {
   int state = this.state;
   if (anyAreClear(state, WRITE_SHUTDOWN | READ_SHUTDOWN)) {
     this.state = state | WRITE_SHUTDOWN | READ_SHUTDOWN;
   }
   if (Native.SAFE_GC)
     try {
       Native.testAndThrow(Native.dup2(Native.DEAD_FD, fd));
     } finally {
       new FdRef<>(this, fd);
     }
   else {
     // hope for the best
     Native.testAndThrow(Native.close(fd));
   }
   if (Native.EXTRA_TRACE) log.tracef("Close(%d)", fd);
 }