4 * Copyright (c) 2007, The University of Manchester (UK)
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * - Neither the name of the University of Manchester nor the names
19 * of its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 /********************************************************************
37 * Ported for our STM implementation
38 * This version copyright(c) University of California, Irvine 2009
39 * @author: Alokika Dash, adash@uci.edu
41 ********************************************************************/
42 public class LeeThread extends Thread {
45 public boolean sampleNow;
46 public boolean doneSample;
47 public long totalLaidTracks;
48 public long myLaidTracks;
55 protected static ThreadLocal<ThreadState> _threadState = new ThreadLocal<ThreadState>() {
56 protected synchronized ThreadState initialValue() {
57 return new ThreadState();
60 static ThreadLocal<Thread> _thread = new ThreadLocal<Thread>() {
61 protected synchronized Thread initialValue() {
67 LeeThread(LeeRouter lt) {
79 int [][][] tempg = scratch new int[lt.GRID_SIZE][lt.GRID_SIZE][2]; // Lee 2D Grid copy
80 while (!finished && !stop) {
82 //collectMyStatistics();
88 t = lt.getNextTrack();
94 System.out.println("Finished");
95 //collectMyStatistics();
96 //collectStatistics(_threadState.get());
100 //System.out.println("Laying track "+t.nn);
101 lt.layNextTrack(t, tempg);
104 //updateStatistics();
111 protected static void collectStatistics(ThreadState threadState) {
112 // collect statistics
113 //synchronized (lock){
114 totalLaidTracks+=threadState.myLaidTracks;
115 threadState.reset(); // set up for next iteration
119 public void updateStatistics(){
120 _threadState.get().myLaidTracks++;
123 public void collectMyStatistics() {
124 myLaidTracks=_threadState.get().myLaidTracks-myLaidTracks;
128 public void resetMyStatistics() {
135 * Class that holds thread's actual state
137 public class ThreadState {
138 private long myLaidTracks; // number of laid tracks
141 * Creates new ThreadState
143 public ThreadState() {
148 * Resets any metering information (commits/aborts, etc).
150 public void reset() {
151 myLaidTracks = 0; // total number of transactions
156 * @return string representation of thread state
158 public String toString() {
160 "Thread" + hashCode() + "["+
161 "total: " + myLaidTracks + "," +