*** empty log message ***
[IRC.git] / Robust / Transactions / jcarderdstm2version / src / com / enea / jcarder / agent / ThreadLocalEnteredMonitors.java
1 /*
2  * JCarder -- cards Java programs to keep threads disentangled
3  *
4  * Copyright (C) 2006-2007 Enea AB
5  * Copyright (C) 2007 Ulrik Svensson
6  * Copyright (C) 2007 Joel Rosdahl
7  *
8  * This program is made available under the GNU GPL version 2, with a special
9  * exception for linking with JUnit. See the accompanying file LICENSE.txt for
10  * details.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.
15  */
16
17 package com.enea.jcarder.agent;
18
19 import java.util.ArrayList;
20 import java.util.Iterator;
21 //import net.jcip.annotations.ThreadSafe;
22
23 /**
24  * Each instance of this class keeps a list of entered monitors for a thread.
25  *
26  * Note that this class is a ThreadLocal and therefore each thread will have its
27  * own instance.
28  */
29
30 //@ThreadSafe
31 final class ThreadLocalEnteredMonitors
32 extends ThreadLocal<ArrayList<EnteredMonitor>> {
33
34     public ArrayList<EnteredMonitor> initialValue() {
35         return new ArrayList<EnteredMonitor>();
36     }
37
38     Iterator<EnteredMonitor> getIterator() {
39         return get().iterator();
40     }
41
42     EnteredMonitor getFirst() {
43         ArrayList<EnteredMonitor> list = get();
44         if (list.isEmpty()) {
45             return null;
46         } else {
47             return list.get(0);
48         }
49     }
50
51     void addFirst(EnteredMonitor enteredMonitor) {
52         get().add(0, enteredMonitor);
53     }
54 }