001/* ---------------------------------------------------------------------------- 002 * This file was automatically generated by SWIG (http://www.swig.org). 003 * Version 4.0.2 004 * 005 * Do not make changes to this file unless you know what you are doing--modify 006 * the SWIG interface file instead. 007 * ----------------------------------------------------------------------------- */ 008 009package com.avpkit.ferry; 010 011/** 012 * Internal Only.<br> 013 * <p><br> 014 * This object exists so that Native code can get access to <br> 015 * thread safe locking objects if they need it.<br> 016 * </p><p><br> 017 * Implements a blocking Mutually-Exclusive lock<br> 018 * by wrapping a Java lock.<br> 019 * </p><p><br> 020 * If not running inside Java, lock() and unlock()<br> 021 * are NO-OPs.<br> 022 * </p> 023 */ 024public class Mutex extends RefCounted { 025 // JNIHelper.swg: Start generated code 026 // >>>>>>>>>>>>>>>>>>>>>>>>>>> 027 /** 028 * This method is only here to use some references and remove 029 * a Eclipse compiler warning. 030 */ 031 @SuppressWarnings("unused") 032 private void noop() 033 { 034 IBuffer.make(null, 1); 035 } 036 037 private volatile long swigCPtr; 038 039 /** 040 * Internal Only. 041 */ 042 protected Mutex(long cPtr, boolean cMemoryOwn) { 043 super(FerryJNI.Mutex_SWIGUpcast(cPtr), cMemoryOwn); 044 swigCPtr = cPtr; 045 } 046 047 /** 048 * Internal Only. 049 */ 050 protected Mutex(long cPtr, boolean cMemoryOwn, 051 java.util.concurrent.atomic.AtomicLong ref) 052 { 053 super(FerryJNI.Mutex_SWIGUpcast(cPtr), 054 cMemoryOwn, ref); 055 swigCPtr = cPtr; 056 } 057 058 /** 059 * Internal Only. Not part of public API. 060 * 061 * Get the raw value of the native object that obj is proxying for. 062 * 063 * @param obj The java proxy object for a native object. 064 * @return The raw pointer obj is proxying for. 065 */ 066 public static long getCPtr(Mutex obj) { 067 if (obj == null) return 0; 068 return obj.getMyCPtr(); 069 } 070 071 /** 072 * Internal Only. Not part of public API. 073 * 074 * Get the raw value of the native object that we're proxying for. 075 * 076 * @return The raw pointer we're proxying for. 077 */ 078 public long getMyCPtr() { 079 if (swigCPtr == 0) throw new IllegalStateException("underlying native object already deleted"); 080 return swigCPtr; 081 } 082 083 /** 084 * Create a new Mutex object that is actually referring to the 085 * exact same underlying native object. 086 * 087 * @return the new Java object. 088 */ 089 @Override 090 public Mutex copyReference() { 091 if (swigCPtr == 0) 092 return null; 093 else 094 return new Mutex(swigCPtr, swigCMemOwn, getJavaRefCount()); 095 } 096 097 /** 098 * Compares two values, returning true if the underlying objects in native code are the same object. 099 * 100 * That means you can have two different Java objects, but when you do a comparison, you'll find out 101 * they are the EXACT same object. 102 * 103 * @return True if the underlying native object is the same. False otherwise. 104 */ 105 public boolean equals(Object obj) { 106 boolean equal = false; 107 if (obj instanceof Mutex) 108 equal = (((Mutex)obj).swigCPtr == this.swigCPtr); 109 return equal; 110 } 111 112 /** 113 * Get a hashable value for this object. 114 * 115 * @return the hashable value. 116 */ 117 public int hashCode() { 118 return (int)swigCPtr; 119 } 120 121 // <<<<<<<<<<<<<<<<<<<<<<<<<<< 122 // JNIHelper.swg: End generated code 123 124 public static Mutex make() { 125 long cPtr = FerryJNI.Mutex_make(); 126 return (cPtr == 0) ? null : new Mutex(cPtr, false); 127 } 128 129 public void lock() { 130 FerryJNI.Mutex_lock(swigCPtr, this); 131 } 132 133 public void unlock() { 134 FerryJNI.Mutex_unlock(swigCPtr, this); 135 } 136 137}