Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
Lock.java
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2021 Gothel Software e.K.
4 * Copyright (c) 2010 Gothel Software e.K.
5 * Copyright (c) 2010 JogAmp Community.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27package jau.test.util.parallel.locks;
28
29import org.jau.sys.Debug;
30
31/**
32 * Specifying a thread blocking lock implementation
33 */
34public interface Lock {
35
36 /** Enable via the property <code>jogamp.debug.Lock</code> */
37 public static final boolean DEBUG = Debug.debug("Lock");
38
39 /** Enable via the property <code>jogamp.debug.Lock.TraceLock</code> */
40 public static final boolean TRACE_LOCK = Debug.isPropertyDefined("jogamp.debug.Lock.TraceLock", true);
41
42 /** The default {@link #TIMEOUT} value, of {@value} ms */
43 public static final long DEFAULT_TIMEOUT = 5000; // 5s default timeout
44
45 /**
46 * The <code>TIMEOUT</code> for {@link #lock()} in ms,
47 * defaults to {@link #DEFAULT_TIMEOUT}.
48 * <p>
49 * It can be overridden via the system property <code>jogamp.common.utils.locks.Lock.timeout</code>.
50 * </p>
51 */
52 public static final long TIMEOUT = Debug.getLongProperty("jogamp.common.utils.locks.Lock.timeout", true, DEFAULT_TIMEOUT);
53
54 /**
55 * Blocking until the lock is acquired by this Thread or {@link #TIMEOUT} is reached.
56 *
57 * @throws RuntimeException in case of {@link #TIMEOUT}
58 */
59 void lock() throws RuntimeException;
60
61 /**
62 * Blocking until the lock is acquired by this Thread or <code>maxwait</code> in ms is reached.
63 *
64 * @param timeout Maximum time in ms to wait to acquire the lock. If this value is zero,
65 * the call returns immediately either without being able
66 * to acquire the lock, or with acquiring the lock directly while ignoring any scheduling order.
67 * @return true if the lock has been acquired within <code>maxwait</code>, otherwise false
68 *
69 * @throws InterruptedException
70 */
71 boolean tryLock(long timeout) throws InterruptedException;
72
73 /**
74 * Release the lock.
75 *
76 * @throws RuntimeException in case the lock is not acquired by this thread.
77 */
78 void unlock() throws RuntimeException;
79
80 /** Query if locked */
81 boolean isLocked();
82}
Specifying a thread blocking lock implementation.
Definition: Lock.java:34
static final long TIMEOUT
The TIMEOUT for lock() in ms, defaults to DEFAULT_TIMEOUT.
Definition: Lock.java:52
static final boolean DEBUG
Enable via the property jogamp.debug.Lock
Definition: Lock.java:37
boolean tryLock(long timeout)
Blocking until the lock is acquired by this Thread or maxwait in ms is reached.
void lock()
Blocking until the lock is acquired by this Thread or TIMEOUT is reached.
void unlock()
Release the lock.
static final boolean TRACE_LOCK
Enable via the property jogamp.debug.Lock.TraceLock
Definition: Lock.java:40
static final long DEFAULT_TIMEOUT
The default TIMEOUT value, of {@value} ms.
Definition: Lock.java:43
boolean isLocked()
Query if locked.