summaryrefslogtreecommitdiffstats
path: root/jrt/src/com/yahoo/jrt/TieBreaker.java
diff options
context:
space:
mode:
Diffstat (limited to 'jrt/src/com/yahoo/jrt/TieBreaker.java')
-rw-r--r--jrt/src/com/yahoo/jrt/TieBreaker.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/jrt/src/com/yahoo/jrt/TieBreaker.java b/jrt/src/com/yahoo/jrt/TieBreaker.java
new file mode 100644
index 00000000000..b327328fae6
--- /dev/null
+++ b/jrt/src/com/yahoo/jrt/TieBreaker.java
@@ -0,0 +1,25 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.jrt;
+
+
+/**
+ * When multiple actors race to come to a certain point and only one
+ * should be allowed to continue, an object of this class may be used
+ * to settle who should be allowed to continue. Note that external
+ * synchronization is needed if this class is used with multiple
+ * threads.
+ **/
+class TieBreaker {
+ private boolean first = true;
+
+ /**
+ * Are we the first to come here?
+ *
+ * @return true if you are first, false otherwise.
+ **/
+ public boolean first() {
+ boolean ret = first;
+ first = false;
+ return ret;
+ }
+}