1 module hunt.security.util.ReferenceQueue;
2 /**
3  * Reference queues, to which registered reference objects are appended by the
4  * garbage collector after the appropriate reachability changes are detected.
5  *
6  * @author   Mark Reinhold
7  */
8 
9 class ReferenceQueue(T) {
10     // TODO: Tasks pending completion -@zxp at 8/10/2018, 4:15:28 PM
11     // 
12     /**
13      * Constructs a new reference-object queue.
14      */
15     this() {
16     }
17 
18     // private static class Null<S> extends ReferenceQueue<S> {
19     //     bool enqueue(Reference<S> r) {
20     //         return false;
21     //     }
22     // }
23 
24     // static ReferenceQueue<Object> NULL = new Null<>();
25     // static ReferenceQueue<Object> ENQUEUED = new Null<>();
26 
27     // static private class Lock { };
28     // private Lock lock = new Lock();
29     // private Reference<T> head = null;
30     // private long queueLength = 0;
31 
32     // bool enqueue(Reference<T> r) { /* Called only by Reference class */
33     //     synchronized (lock) {
34     //         // Check that since getting the lock this reference hasn't already been
35     //         // enqueued (and even then removed)
36     //         ReferenceQueue<?> queue = r.queue;
37     //         if ((queue == NULL) || (queue == ENQUEUED)) {
38     //             return false;
39     //         }
40     //         assert queue == this;
41     //         r.queue = ENQUEUED;
42     //         r.next = (head is null) ? r : head;
43     //         head = r;
44     //         queueLength++;
45     //         if (r instanceof FinalReference) {
46     //             sun.misc.VM.addFinalRefCount(1);
47     //         }
48     //         lock.notifyAll();
49     //         return true;
50     //     }
51     // }
52 
53     // @SuppressWarnings("unchecked")
54     // private Reference<T> reallyPoll() {       /* Must hold lock */
55     //     Reference<T> r = head;
56     //     if (r !is null) {
57     //         head = (r.next == r) ?
58     //             null :
59     //             r.next; // Unchecked due to the next field having a raw type in Reference
60     //         r.queue = NULL;
61     //         r.next = r;
62     //         queueLength--;
63     //         if (r instanceof FinalReference) {
64     //             sun.misc.VM.addFinalRefCount(-1);
65     //         }
66     //         return r;
67     //     }
68     //     return null;
69     // }
70 
71     // /**
72     //  * Polls this queue to see if a reference object is available.  If one is
73     //  * available without further delay then it is removed from the queue and
74     //  * returned.  Otherwise this method immediately returns <tt>null</tt>.
75     //  *
76     //  * @return  A reference object, if one was immediately available,
77     //  *          otherwise <code>null</code>
78     //  */
79     // Reference<T> poll() {
80     //     if (head is null)
81     //         return null;
82     //     synchronized (lock) {
83     //         return reallyPoll();
84     //     }
85     // }
86 
87     // /**
88     //  * Removes the next reference object in this queue, blocking until either
89     //  * one becomes available or the given timeout period expires.
90     //  *
91     //  * <p> This method does not offer real-time guarantees: It schedules the
92     //  * timeout as if by invoking the {@link Object#wait(long)} method.
93     //  *
94     //  * @param  timeout  If positive, block for up to <code>timeout</code>
95     //  *                  milliseconds while waiting for a reference to be
96     //  *                  added to this queue.  If zero, block indefinitely.
97     //  *
98     //  * @return  A reference object, if one was available within the specified
99     //  *          timeout period, otherwise <code>null</code>
100     //  *
101     //  * @throws  IllegalArgumentException
102     //  *          If the value of the timeout argument is negative
103     //  *
104     //  * @throws  InterruptedException
105     //  *          If the timeout wait is interrupted
106     //  */
107     // Reference<T> remove(long timeout)
108     //     throws IllegalArgumentException, InterruptedException
109     // {
110     //     if (timeout < 0) {
111     //         throw new IllegalArgumentException("Negative timeout value");
112     //     }
113     //     synchronized (lock) {
114     //         Reference<T> r = reallyPoll();
115     //         if (r !is null) return r;
116     //         long start = (timeout == 0) ? 0 : System.nanoTime();
117     //         for (;;) {
118     //             lock.wait(timeout);
119     //             r = reallyPoll();
120     //             if (r !is null) return r;
121     //             if (timeout != 0) {
122     //                 long end = System.nanoTime();
123     //                 timeout -= (end - start) / 1000_000;
124     //                 if (timeout <= 0) return null;
125     //                 start = end;
126     //             }
127     //         }
128     //     }
129     // }
130 
131     // /**
132     //  * Removes the next reference object in this queue, blocking until one
133     //  * becomes available.
134     //  *
135     //  * @return A reference object, blocking until one becomes available
136     //  * @throws  InterruptedException  If the wait is interrupted
137     //  */
138     // Reference<T> remove() throws InterruptedException {
139     //     return remove(0);
140     // }
141 
142 }