00001 // Copyright (c) 2000, Compaq Computer Corporation 00002 // Copyright (C) 2001, Compaq Computer Corporation 00003 // 00004 // This file is part of Vesta. 00005 // 00006 // Vesta is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU Lesser General Public 00008 // License as published by the Free Software Foundation; either 00009 // version 2.1 of the License, or (at your option) any later version. 00010 // 00011 // Vesta is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public 00017 // License along with Vesta; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 // File: ThreadData.H 00021 00022 #ifndef ThreadData_H 00023 #define ThreadData_H 00024 00025 #include "EvalBasics.H" 00026 #include <CacheC.H> 00027 #include <BufStream.H> 00028 00029 // 00030 // Thread-specific data for threads started by _par_map 00031 // 00032 struct ThreadData { 00033 // List of all extant ThreadData objects 00034 static Basics::mutex mu; 00035 static ThreadData* head; 00036 ThreadData* prev; 00037 ThreadData* next; 00038 00039 // Fields of individual ThreadData objects 00040 int id; // Dense, small integer ids. Main thread should be 0. 00041 int funcCallDepth; 00042 Basics::OBufStream *traceRes; 00043 Exprs *callStack; 00044 ThreadData *parent; 00045 int parentCallStackSize; 00046 CacheEntry::IndicesApp* orphanCIs; 00047 00048 // !! add more fields if needed 00049 }; 00050 00051 // Create thread-specific data for the current thread. Call this 00052 // routine once from each new thread after forking it. Caller assigns 00053 // ids. Also OK to call repeatedly from the same thread (e.g., the 00054 // main thread); each call frees the old ThreadData and creates a 00055 // fresh one. The ThreadData object is automatically freed when a 00056 // thread terminates. 00057 ThreadData* ThreadDataCreate(int id, CacheEntry::IndicesApp *threadCIs); 00058 00059 // Get thread-specific data for the current thread. 00060 ThreadData* ThreadDataGet(); 00061 00062 // Initialize module. Also calls ThreadDataCreate(0) for main thread. 00063 void ThreadDataInit(); 00064 00065 inline Text ThreadLabel() 00066 { 00067 return ((maxThreads > 1) 00068 ? IntToText(ThreadDataGet()->id) + "/" 00069 : Text("")); 00070 } 00071 00072 #endif // ThreadData_H