GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java™ (public API).
Lock.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.common.util.locks;
30
31import jogamp.common.Debug;
32
33/**
34 * Specifying a thread blocking lock implementation
35 */
36public interface Lock {
37
38 /** Enable via the property <code>jogamp.debug.Lock</code> */
39 public static final boolean DEBUG = Debug.debug("Lock");
40
41 /** Enable via the property <code>jogamp.debug.Lock.TraceLock</code> */
42 public static final boolean TRACE_LOCK = Debug.isPropertyDefined("jogamp.debug.Lock.TraceLock", true);
43
44 /** The default {@link #TIMEOUT} value, of {@value} ms */
45 public static final long DEFAULT_TIMEOUT = 5000; // 5s default timeout
46
47 /**
48 * The <code>TIMEOUT</code> for {@link #lock()} in ms,
49 * defaults to {@link #DEFAULT_TIMEOUT}.
50 * <p>
51 * It can be overridden via the system property <code>jogamp.common.utils.locks.Lock.timeout</code>.
52 * </p>
53 */
54 public static final long TIMEOUT = Debug.getLongProperty("jogamp.common.utils.locks.Lock.timeout", true, DEFAULT_TIMEOUT);
55
56 /**
57 * Blocking until the lock is acquired by this Thread or {@link #TIMEOUT} is reached.
58 *
59 * @throws RuntimeException in case of {@link #TIMEOUT}
60 */
61 void lock() throws RuntimeException;
62
63 /**
64 * Blocking until the lock is acquired by this Thread or <code>maxwait</code> in ms is reached.
65 *
66 * @param timeout Maximum time in ms to wait to acquire the lock. If this value is zero,
67 * the call returns immediately either without being able
68 * to acquire the lock, or with acquiring the lock directly while ignoring any scheduling order.
69 * @return true if the lock has been acquired within <code>maxwait</code>, otherwise false
70 *
71 * @throws InterruptedException
72 */
73 boolean tryLock(long timeout) throws InterruptedException;
74
75 /**
76 * Release the lock.
77 *
78 * @throws RuntimeException in case the lock is not acquired by this thread.
79 */
80 void unlock() throws RuntimeException;
81
82 /** Query if locked */
83 boolean isLocked();
84}
Specifying a thread blocking lock implementation.
Definition: Lock.java:36
static final boolean TRACE_LOCK
Enable via the property jogamp.debug.Lock.TraceLock
Definition: Lock.java:42
boolean tryLock(long timeout)
Blocking until the lock is acquired by this Thread or maxwait in ms is reached.
static final long TIMEOUT
The TIMEOUT for lock() in ms, defaults to DEFAULT_TIMEOUT.
Definition: Lock.java:54
void unlock()
Release the lock.
static final long DEFAULT_TIMEOUT
The default TIMEOUT value, of {@value} ms.
Definition: Lock.java:45
void lock()
Blocking until the lock is acquired by this Thread or TIMEOUT is reached.
static final boolean DEBUG
Enable via the property jogamp.debug.Lock
Definition: Lock.java:39
boolean isLocked()
Query if locked.