aboutsummaryrefslogtreecommitdiffstats
path: root/jrt/src/com/yahoo/jrt/TieBreaker.java
blob: 5cb068c37134d0e576871d30aaff531ab4b25e96 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Copyright Yahoo. 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;
    }
}