/usr/include/openigtlink/igtlMultiThreader.h is in libopenigtlink-dev 1.11.0-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | /*=========================================================================
Program: The OpenIGTLink Library
Language: C++
Web page: http://openigtlink.org/
Copyright (c) Insight Software Consortium. All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkMultiThreader.h,v $
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME igtlMultiThreader - A class for performing multithreaded execution
// .SECTION Description
// igtlMultithreader is a class that provides support for multithreaded
// execution using sproc() on an SGI, or pthread_create on any platform
// supporting POSIX threads. This class can be used to execute a single
// method on multiple threads, or to specify a method per thread.
#ifndef __igtlMultiThreader_h
#define __igtlMultiThreader_h
#include "igtlObject.h"
#include "igtlObjectFactory.h"
#include "igtlMacro.h"
#include "igtlMutexLock.h"
#ifdef OpenIGTLink_USE_SPROC
#include <sys/types.h> // Needed for unix implementation of sproc
#include <unistd.h> // Needed for unix implementation of sproc
#endif
#if defined(OpenIGTLink_USE_PTHREAD) || defined(OpenIGTLink_HP_PTHREAD)
#include <pthread.h> // Needed for PTHREAD implementation of mutex
#include <sys/types.h> // Needed for unix implementation of pthreads
#include <unistd.h> // Needed for unix implementation of pthreads
#endif
namespace igtl
{
// If OpenIGTLink_USE_SPROC is defined, then sproc() will be used to create
// multiple threads on an SGI. If OpenIGTLink_USE_PTHREAD is defined, then
// pthread_create() will be used to create multiple threads (on
// a sun, for example)
// Defined in igtlSystemIncludes.h:
// IGTL_MAX_THREADS
// If OpenIGTLink_USE_PTHREADS is defined, then the multithreaded
// function is of type void *, and returns NULL
// Otherwise the type is void which is correct for WIN32
// and SPROC
//BTX
// The maximum number of threads allowed
#ifdef OpenIGTLink_USE_SPROC
#define IGTL_MAX_THREADS 128
#endif
#ifdef OpenIGTLink_USE_PTHREADS
#define IGTL_MAX_THREADS 128
#endif
#ifdef OpenIGTLink_USE_WIN32_THREADS
#define IGTL_MAX_THREADS 128
#endif
// cygwin threads are unreliable
#ifdef __CYGWIN__
#undef IGTL_MAX_THREADS
#define IGTL_MAX_THREADS 128
#endif
// mingw threads cause crashes so limit to 1
#if defined(__MINGW32__)
#undef IGTL_MAX_THREADS
#define IGTL_MAX_THREADS 1
#endif
// On some sgi machines, threads and stl don't mix so limit to 1
#if defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730
#undef IGTL_MAX_THREADS
#define IGTL_MAX_THREADS 1
#endif
#ifndef IGTL_MAX_THREADS
#define IGTL_MAX_THREADS 1
#endif
#ifdef OpenIGTLink_USE_SPROC
typedef int ThreadProcessIDType;
typedef int MultiThreaderIDType;
#endif
#ifdef OpenIGTLink_USE_PTHREADS
typedef void *(*ThreadFunctionType)(void *);
typedef pthread_t ThreadProcessIDType;
typedef pthread_t MultiThreaderIDType;
#endif
#ifdef OpenIGTLink_USE_WIN32_THREADS
typedef igtlWindowsLPTHREAD_START_ROUTINE ThreadFunctionType;
typedef igtlWindowsHANDLE ThreadProcessIDType;
typedef igtlWindowsDWORD MultiThreaderIDType;
#endif
#if !defined(OpenIGTLink_USE_PTHREADS) && !defined(OpenIGTLink_USE_WIN32_THREADS)
typedef void (*ThreadFunctionType)(void *);
typedef int ThreadProcessIDType;
typedef int MultiThreaderIDType;
#endif
//ETX
class IGTLCommon_EXPORT MultiThreader : public Object
{
public:
/** Standard class typedefs. */
typedef MultiThreader Self;
typedef Object Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
igtlNewMacro(Self);
igtlTypeMacro(MultiThreader, Object);
// Description:
// This is the structure that is passed to the thread that is
// created from the SingleMethodExecute, MultipleMethodExecute or
// the SpawnThread method. It is passed in as a void *, and it is
// up to the method to cast correctly and extract the information.
// The ThreadID is a number between 0 and NumberOfThreads-1 that indicates
// the id of this thread. The NumberOfThreads is this->NumberOfThreads for
// threads created from SingleMethodExecute or MultipleMethodExecute,
// and it is 1 for threads created from SpawnThread.
// The UserData is the (void *)arg passed into the SetSingleMethod,
// SetMultipleMethod, or SpawnThread method.
//BTX
#define ThreadInfoStruct MultiThreader::ThreadInfo
class ThreadInfo
{
public:
int ThreadID;
int NumberOfThreads;
int *ActiveFlag;
MutexLock::Pointer ActiveFlagLock;
void *UserData;
};
//ETX
// Description:
// Get/Set the number of threads to create. It will be clamped to the range
// 1 - IGTL_MAX_THREADS, so the caller of this method should check that the
// requested number of threads was accepted.
igtlSetClampMacro( NumberOfThreads, int, 1, IGTL_MAX_THREADS );
virtual int GetNumberOfThreads();
// Description:
// Set/Get the maximum number of threads to use when multithreading.
// This limits and overrides any other settings for multithreading.
// A value of zero indicates no limit.
static void SetGlobalMaximumNumberOfThreads(int val);
static int GetGlobalMaximumNumberOfThreads();
// Description:
// Set/Get the value which is used to initialize the NumberOfThreads
// in the constructor. Initially this default is set to the number of
// processors or IGTL_MAX_THREADS (which ever is less).
static void SetGlobalDefaultNumberOfThreads(int val);
static int GetGlobalDefaultNumberOfThreads();
// These methods are excluded from Tcl wrapping 1) because the
// wrapper gives up on them and 2) because they really shouldn't be
// called from a script anyway.
//BTX
// Description:
// Execute the SingleMethod (as define by SetSingleMethod) using
// this->NumberOfThreads threads.
void SingleMethodExecute();
// Description:
// Execute the MultipleMethods (as define by calling SetMultipleMethod
// for each of the required this->NumberOfThreads methods) using
// this->NumberOfThreads threads.
void MultipleMethodExecute();
// Description:
// Set the SingleMethod to f() and the UserData field of the
// ThreadInfo that is passed to it will be data.
// This method (and all the methods passed to SetMultipleMethod)
// must be of type ThreadFunctionType and must take a single argument of
// type void *.
void SetSingleMethod(ThreadFunctionType, void *data );
// Description:
// Set the MultipleMethod at the given index to f() and the UserData
// field of the ThreadInfo that is passed to it will be data.
void SetMultipleMethod( int index, ThreadFunctionType, void *data );
// Description:
// Create a new thread for the given function. Return a thread id
// which is a number between 0 and IGTL_MAX_THREADS - 1. This id should
// be used to kill the thread at a later time.
int SpawnThread( ThreadFunctionType, void *data );
// Description:
// Terminate the thread that was created with a SpawnThreadExecute()
void TerminateThread( int thread_id );
// Description:
// Get the thread identifier of the calling thread.
static MultiThreaderIDType GetCurrentThreadID();
// Description:
// Check whether two thread identifiers refer to the same thread.
static int ThreadsEqual(MultiThreaderIDType t1,
MultiThreaderIDType t2);
protected:
MultiThreader();
~MultiThreader();
void PrintSelf(std::ostream& os) const;
// The number of threads to use
int m_NumberOfThreads;
// An array of thread info containing a thread id
// (0, 1, 2, .. IGTL_MAX_THREADS-1), the thread count, and a pointer
// to void so that user data can be passed to each thread
ThreadInfo m_ThreadInfoArray[IGTL_MAX_THREADS];
// The methods
ThreadFunctionType m_SingleMethod;
ThreadFunctionType m_MultipleMethod[IGTL_MAX_THREADS];
// Storage of MutexFunctions and ints used to control spawned
// threads and the spawned thread ids
int m_SpawnedThreadActiveFlag[IGTL_MAX_THREADS];
MutexLock::Pointer m_SpawnedThreadActiveFlagLock[IGTL_MAX_THREADS];
ThreadProcessIDType m_SpawnedThreadProcessID[IGTL_MAX_THREADS];
ThreadInfo m_SpawnedThreadInfoArray[IGTL_MAX_THREADS];
//ETX
// Internal storage of the data
void *m_SingleData;
void *m_MultipleData[IGTL_MAX_THREADS];
private:
MultiThreader(const MultiThreader&); // Not implemented.
void operator=(const MultiThreader&); // Not implemented.
};
} // namespace igtl
#endif
|