Executes the given callback with the lock acquired.
Executes the given callback with the lock acquired.
Is implemented as macro to eliminate any method calls overhead.
the callback to be executed once the lock is acquired
the returned value of our callback
private[this] val gate = Extensions() private[this] var queue = mutable.Queue.empty[Int] def push(elem: Int): Unit = gate.enter { queue.enqueue(elem) } def pop(): Option[Int] = gate.enter { if (queue.nonEmpty) Some(queue.dequeue()) else None }
Executes the given callback with the lock acquired, unless the thread was interrupted.
Executes the given callback with the lock acquired, unless the thread was interrupted.
Is implemented as macro to eliminate any method calls overhead.
the callback to be executed once the lock is acquired
the returned value of our callback
private[this] val gate = Extensions() private[this] var queue = mutable.Queue.empty[Int] def push(elem: Int): Unit = gate.enterInterruptibly { queue.enqueue(elem) } def pop(): Option[Int] = gate.enterInterruptibly { if (queue.nonEmpty) Some(queue.dequeue()) else None }
java.lang.InterruptedException
exception is thrown if the thread was interrupted
Acquires the lock only if it is free within the given waiting time and in case the lock was acquired then executes the given callback.
Acquires the lock only if it is free within the given waiting time and in case the lock was acquired then executes the given callback.
the maximum time to wait for the lock
the time unit of the time
argument
the callback to execute
either true
in case the lock was acquired and the callback was executed, or false
otherwise.
Acquires the lock only if it is free at the time of invocation and in case the lock was acquired then executes the given callback.
Acquires the lock only if it is free at the time of invocation and in case the lock was acquired then executes the given callback.
the callback to execute
either true
in case the lock was acquired and the callback was executed, or false
otherwise.