<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>VTK: dox/Common/vtkMultiThreader.h Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.5.6 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="classes.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <h1>dox/Common/vtkMultiThreader.h</h1><a href="a02077.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*=========================================================================</span> <a name="l00002"></a>00002 <span class="comment"></span> <a name="l00003"></a>00003 <span class="comment"> Program: Visualization Toolkit</span> <a name="l00004"></a>00004 <span class="comment"> Module: $RCSfile: vtkMultiThreader.h,v $</span> <a name="l00005"></a>00005 <span class="comment"></span> <a name="l00006"></a>00006 <span class="comment"> Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen</span> <a name="l00007"></a>00007 <span class="comment"> All rights reserved.</span> <a name="l00008"></a>00008 <span class="comment"> See Copyright.txt or http://www.kitware.com/Copyright.htm for details.</span> <a name="l00009"></a>00009 <span class="comment"></span> <a name="l00010"></a>00010 <span class="comment"> This software is distributed WITHOUT ANY WARRANTY; without even</span> <a name="l00011"></a>00011 <span class="comment"> the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR</span> <a name="l00012"></a>00012 <span class="comment"> PURPOSE. See the above copyright notice for more information.</span> <a name="l00013"></a>00013 <span class="comment"></span> <a name="l00014"></a>00014 <span class="comment">=========================================================================*/</span> <a name="l00027"></a>00027 <span class="preprocessor">#ifndef __vtkMultiThreader_h</span> <a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define __vtkMultiThreader_h</span> <a name="l00029"></a>00029 <span class="preprocessor"></span> <a name="l00030"></a>00030 <span class="preprocessor">#include "<a class="code" href="a02079.html">vtkObject.h</a>"</span> <a name="l00031"></a>00031 <a name="l00032"></a>00032 <span class="preprocessor">#ifdef VTK_USE_SPROC</span> <a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#include <sys/types.h></span> <span class="comment">// Needed for unix implementation of sproc</span> <a name="l00034"></a>00034 <span class="preprocessor">#include <unistd.h></span> <span class="comment">// Needed for unix implementation of sproc</span> <a name="l00035"></a>00035 <span class="preprocessor">#endif</span> <a name="l00036"></a>00036 <span class="preprocessor"></span> <a name="l00037"></a>00037 <span class="preprocessor">#if defined(VTK_USE_PTHREADS) || defined(VTK_HP_PTHREADS)</span> <a name="l00038"></a>00038 <span class="preprocessor"></span><span class="preprocessor">#include <pthread.h></span> <span class="comment">// Needed for PTHREAD implementation of mutex</span> <a name="l00039"></a>00039 <span class="preprocessor">#include <sys/types.h></span> <span class="comment">// Needed for unix implementation of pthreads</span> <a name="l00040"></a>00040 <span class="preprocessor">#include <unistd.h></span> <span class="comment">// Needed for unix implementation of pthreads</span> <a name="l00041"></a>00041 <span class="preprocessor">#endif</span> <a name="l00042"></a>00042 <span class="preprocessor"></span> <a name="l00043"></a>00043 <span class="comment">// If VTK_USE_SPROC is defined, then sproc() will be used to create</span> <a name="l00044"></a>00044 <span class="comment">// multiple threads on an SGI. If VTK_USE_PTHREADS is defined, then</span> <a name="l00045"></a>00045 <span class="comment">// pthread_create() will be used to create multiple threads (on</span> <a name="l00046"></a>00046 <span class="comment">// a sun, for example)</span> <a name="l00047"></a>00047 <a name="l00048"></a>00048 <span class="comment">// Defined in vtkSystemIncludes.h:</span> <a name="l00049"></a>00049 <span class="comment">// VTK_MAX_THREADS</span> <a name="l00050"></a>00050 <a name="l00051"></a>00051 <span class="comment">// If VTK_USE_PTHREADS is defined, then the multithreaded</span> <a name="l00052"></a>00052 <span class="comment">// function is of type void *, and returns NULL</span> <a name="l00053"></a>00053 <span class="comment">// Otherwise the type is void which is correct for WIN32</span> <a name="l00054"></a>00054 <span class="comment">// and SPROC</span> <a name="l00055"></a>00055 <span class="comment">//BTX</span> <a name="l00056"></a>00056 <span class="preprocessor">#ifdef VTK_USE_SPROC</span> <a name="l00057"></a>00057 <span class="preprocessor"></span><span class="keyword">typedef</span> <span class="keywordtype">int</span> <a class="code" href="a02077.html#7eb266a71ebc6d86a0b1d57d021f0b21">vtkThreadProcessIDType</a>; <a name="l00058"></a>00058 <span class="keyword">typedef</span> <span class="keywordtype">int</span> <a class="code" href="a02077.html#0138e0597dfcd71eb7636901c96e27e4">vtkMultiThreaderIDType</a>; <a name="l00059"></a>00059 <span class="preprocessor">#endif</span> <a name="l00060"></a>00060 <span class="preprocessor"></span> <a name="l00061"></a>00061 <span class="comment">// Defined in vtkSystemIncludes.h:</span> <a name="l00062"></a>00062 <span class="comment">// VTK_THREAD_RETURN_VALUE</span> <a name="l00063"></a>00063 <span class="comment">// VTK_THREAD_RETURN_TYPE</span> <a name="l00064"></a>00064 <a name="l00065"></a>00065 <span class="preprocessor">#ifdef VTK_USE_PTHREADS</span> <a name="l00066"></a>00066 <span class="preprocessor"></span><span class="keyword">typedef</span> <span class="keywordtype">void</span> *(*vtkThreadFunctionType)(<span class="keywordtype">void</span> *); <a name="l00067"></a>00067 <span class="keyword">typedef</span> pthread_t <a class="code" href="a02077.html#7eb266a71ebc6d86a0b1d57d021f0b21">vtkThreadProcessIDType</a>; <a name="l00068"></a>00068 <span class="comment">// #define VTK_THREAD_RETURN_VALUE NULL</span> <a name="l00069"></a>00069 <span class="comment">// #define VTK_THREAD_RETURN_TYPE void *</span> <a name="l00070"></a>00070 <span class="keyword">typedef</span> pthread_t <a class="code" href="a02077.html#0138e0597dfcd71eb7636901c96e27e4">vtkMultiThreaderIDType</a>; <a name="l00071"></a>00071 <span class="preprocessor">#endif</span> <a name="l00072"></a>00072 <span class="preprocessor"></span> <a name="l00073"></a>00073 <span class="preprocessor">#ifdef VTK_USE_WIN32_THREADS</span> <a name="l00074"></a>00074 <span class="preprocessor"></span><span class="keyword">typedef</span> vtkWindowsLPTHREAD_START_ROUTINE <a class="code" href="a02077.html#1a4a360ecf4efc17d1e2ea057636ec48">vtkThreadFunctionType</a>; <a name="l00075"></a>00075 <span class="keyword">typedef</span> vtkWindowsHANDLE <a class="code" href="a02077.html#7eb266a71ebc6d86a0b1d57d021f0b21">vtkThreadProcessIDType</a>; <a name="l00076"></a>00076 <span class="comment">// #define VTK_THREAD_RETURN_VALUE 0</span> <a name="l00077"></a>00077 <span class="comment">// #define VTK_THREAD_RETURN_TYPE DWORD __stdcall</span> <a name="l00078"></a>00078 <span class="keyword">typedef</span> vtkWindowsDWORD <a class="code" href="a02077.html#0138e0597dfcd71eb7636901c96e27e4">vtkMultiThreaderIDType</a>; <a name="l00079"></a>00079 <span class="preprocessor">#endif</span> <a name="l00080"></a>00080 <span class="preprocessor"></span> <a name="l00081"></a>00081 <span class="preprocessor">#if !defined(VTK_USE_PTHREADS) && !defined(VTK_USE_WIN32_THREADS)</span> <a name="l00082"></a><a class="code" href="a02077.html#1a4a360ecf4efc17d1e2ea057636ec48">00082</a> <span class="preprocessor"></span><span class="keyword">typedef</span> void (*<a class="code" href="a02077.html#1a4a360ecf4efc17d1e2ea057636ec48">vtkThreadFunctionType</a>)(<span class="keywordtype">void</span> *); <a name="l00083"></a><a class="code" href="a02077.html#7eb266a71ebc6d86a0b1d57d021f0b21">00083</a> <span class="keyword">typedef</span> <span class="keywordtype">int</span> <a class="code" href="a02077.html#7eb266a71ebc6d86a0b1d57d021f0b21">vtkThreadProcessIDType</a>; <a name="l00084"></a>00084 <span class="comment">// #define VTK_THREAD_RETURN_VALUE</span> <a name="l00085"></a>00085 <span class="comment">// #define VTK_THREAD_RETURN_TYPE void</span> <a name="l00086"></a><a class="code" href="a02077.html#0138e0597dfcd71eb7636901c96e27e4">00086</a> <span class="keyword">typedef</span> <span class="keywordtype">int</span> <a class="code" href="a02077.html#0138e0597dfcd71eb7636901c96e27e4">vtkMultiThreaderIDType</a>; <a name="l00087"></a>00087 <span class="preprocessor">#endif</span> <a name="l00088"></a>00088 <span class="preprocessor"></span><span class="comment">//ETX</span> <a name="l00089"></a>00089 <a name="l00090"></a>00090 <span class="keyword">class </span><a class="code" href="a01074.html" title="mutual exclusion locking class">vtkMutexLock</a>; <a name="l00091"></a>00091 <a name="l00092"></a><a class="code" href="a01064.html">00092</a> <span class="keyword">class </span><a class="code" href="a02170.html#873ca0b83d0838a1df577536068a1730">VTK_COMMON_EXPORT</a> <a class="code" href="a01064.html" title="A class for performing multithreaded execution.">vtkMultiThreader</a> : <span class="keyword">public</span> <a class="code" href="a01084.html" title="abstract base class for most VTK objects">vtkObject</a> <a name="l00093"></a>00093 { <a name="l00094"></a>00094 <span class="keyword">public</span>: <a name="l00095"></a>00095 <span class="keyword">static</span> <a class="code" href="a01064.html" title="A class for performing multithreaded execution.">vtkMultiThreader</a> *<a class="code" href="a01084.html#4d5b227267c076d6f9e38483370b6612">New</a>(); <a name="l00096"></a>00096 <a name="l00097"></a><a class="code" href="a01064.html#e8f0f7305a9c9a2889650925e114e6ef">00097</a> vtkTypeRevisionMacro(<a class="code" href="a01064.html" title="A class for performing multithreaded execution.">vtkMultiThreader</a>,<a class="code" href="a01084.html" title="abstract base class for most VTK objects">vtkObject</a>); <a name="l00098"></a>00098 <span class="keywordtype">void</span> <a class="code" href="a01084.html#bf3dbb4154289b56a12483eee3866263">PrintSelf</a>(ostream& os, <a class="code" href="a00869.html" title="a simple class to control print indentation">vtkIndent</a> indent); <a name="l00099"></a>00099 <a name="l00111"></a>00111 <span class="comment">//BTX</span> <a name="l00112"></a><a class="code" href="a02077.html#975272f39ace1821fd3c61acdb0823ed">00112</a> <span class="preprocessor">#define ThreadInfoStruct vtkMultiThreader::ThreadInfo</span> <a name="l00113"></a><a class="code" href="a01065.html">00113</a> <span class="preprocessor"></span> <span class="keyword">class </span><a class="code" href="a01065.html">ThreadInfo</a> <a name="l00114"></a>00114 { <a name="l00115"></a>00115 <span class="keyword">public</span>: <a name="l00116"></a><a class="code" href="a01065.html#16dfffdcd339b90af11df0069a1436be">00116</a> <span class="keywordtype">int</span> ThreadID; <a name="l00117"></a><a class="code" href="a01065.html#ae744824cb562d2bb79a913bb9f756e1">00117</a> <span class="keywordtype">int</span> NumberOfThreads; <a name="l00118"></a><a class="code" href="a01065.html#0ea9e62bef591e81fa055a38ddeff808">00118</a> <span class="keywordtype">int</span> *ActiveFlag; <a name="l00119"></a><a class="code" href="a01065.html#add5e8b17547ddbdbac7e0acd4d9e762">00119</a> <a class="code" href="a01074.html" title="mutual exclusion locking class">vtkMutexLock</a> *ActiveFlagLock; <a name="l00120"></a><a class="code" href="a01065.html#3d080567042d762e9d3d2b6fa068de23">00120</a> <span class="keywordtype">void</span> *UserData; <a name="l00121"></a>00121 }; <a name="l00122"></a>00122 <span class="comment">//ETX</span> <a name="l00123"></a>00123 <a name="l00125"></a>00125 <a name="l00128"></a>00128 vtkSetClampMacro( NumberOfThreads, <span class="keywordtype">int</span>, 1, <a class="code" href="a02139.html#804fbb60e0f29e0e0a3d5706c85ef921">VTK_MAX_THREADS</a> ); <a name="l00129"></a>00129 <span class="keyword">virtual</span> <span class="keywordtype">int</span> GetNumberOfThreads(); <a name="l00131"></a>00131 <a name="l00133"></a>00133 <a name="l00136"></a>00136 <span class="keyword">static</span> <span class="keywordtype">void</span> SetGlobalMaximumNumberOfThreads(<span class="keywordtype">int</span> val); <a name="l00137"></a>00137 <span class="keyword">static</span> <span class="keywordtype">int</span> GetGlobalMaximumNumberOfThreads(); <a name="l00139"></a>00139 <a name="l00141"></a>00141 <a name="l00144"></a>00144 <span class="keyword">static</span> <span class="keywordtype">void</span> SetGlobalDefaultNumberOfThreads(<span class="keywordtype">int</span> val); <a name="l00145"></a>00145 <span class="keyword">static</span> <span class="keywordtype">int</span> GetGlobalDefaultNumberOfThreads(); <a name="l00147"></a>00147 <a name="l00148"></a>00148 <span class="comment">// These methods are excluded from Tcl wrapping 1) because the</span> <a name="l00149"></a>00149 <span class="comment">// wrapper gives up on them and 2) because they really shouldn't be</span> <a name="l00150"></a>00150 <span class="comment">// called from a script anyway.</span> <a name="l00151"></a>00151 <span class="comment">//BTX </span> <a name="l00152"></a>00152 <a name="l00155"></a>00155 <span class="keywordtype">void</span> SingleMethodExecute(); <a name="l00156"></a>00156 <a name="l00160"></a>00160 <span class="keywordtype">void</span> MultipleMethodExecute(); <a name="l00161"></a>00161 <a name="l00166"></a>00166 <span class="keywordtype">void</span> SetSingleMethod(<a class="code" href="a02077.html#1a4a360ecf4efc17d1e2ea057636ec48">vtkThreadFunctionType</a>, <span class="keywordtype">void</span> *<a class="code" href="a03761.html#c6551f7bf833e8254b2b3ecdaea0d210eb708a412c0730a6b5f3215b36474a1e">data</a> ); <a name="l00167"></a>00167 <a name="l00170"></a>00170 <span class="keywordtype">void</span> SetMultipleMethod( <span class="keywordtype">int</span> <a class="code" href="a03761.html#c6551f7bf833e8254b2b3ecdaea0d210e519c5019582479480124c44722a451f">index</a>, <a class="code" href="a02077.html#1a4a360ecf4efc17d1e2ea057636ec48">vtkThreadFunctionType</a>, <span class="keywordtype">void</span> *<a class="code" href="a03761.html#c6551f7bf833e8254b2b3ecdaea0d210eb708a412c0730a6b5f3215b36474a1e">data</a> ); <a name="l00171"></a>00171 <a name="l00175"></a>00175 <span class="keywordtype">int</span> SpawnThread( <a class="code" href="a02077.html#1a4a360ecf4efc17d1e2ea057636ec48">vtkThreadFunctionType</a>, <span class="keywordtype">void</span> *<a class="code" href="a03761.html#c6551f7bf833e8254b2b3ecdaea0d210eb708a412c0730a6b5f3215b36474a1e">data</a> ); <a name="l00176"></a>00176 <a name="l00178"></a>00178 <span class="keywordtype">void</span> TerminateThread( <span class="keywordtype">int</span> thread_id ); <a name="l00179"></a>00179 <a name="l00181"></a>00181 <span class="keywordtype">int</span> IsThreadActive( <span class="keywordtype">int</span> threadID ); <a name="l00182"></a>00182 <a name="l00184"></a>00184 <span class="keyword">static</span> <a class="code" href="a02077.html#0138e0597dfcd71eb7636901c96e27e4">vtkMultiThreaderIDType</a> GetCurrentThreadID(); <a name="l00185"></a>00185 <a name="l00187"></a>00187 <a name="l00188"></a>00188 <span class="keyword">static</span> <span class="keywordtype">int</span> ThreadsEqual(<a class="code" href="a02077.html#0138e0597dfcd71eb7636901c96e27e4">vtkMultiThreaderIDType</a> t1, <a name="l00189"></a>00189 <a class="code" href="a02077.html#0138e0597dfcd71eb7636901c96e27e4">vtkMultiThreaderIDType</a> t2); <a name="l00191"></a>00191 <a name="l00192"></a>00192 <span class="keyword">protected</span>: <a name="l00193"></a>00193 <a class="code" href="a01064.html" title="A class for performing multithreaded execution.">vtkMultiThreader</a>(); <a name="l00194"></a>00194 ~<a class="code" href="a01064.html" title="A class for performing multithreaded execution.">vtkMultiThreader</a>(); <a name="l00195"></a>00195 <a name="l00196"></a>00196 <span class="comment">// The number of threads to use</span> <a name="l00197"></a><a class="code" href="a01064.html#d937f844da5781fd31e8bd6bf8adc72a">00197</a> <span class="keywordtype">int</span> NumberOfThreads; <a name="l00198"></a>00198 <a name="l00199"></a>00199 <span class="comment">// An array of thread info containing a thread id</span> <a name="l00200"></a>00200 <span class="comment">// (0, 1, 2, .. VTK_MAX_THREADS-1), the thread count, and a pointer</span> <a name="l00201"></a>00201 <span class="comment">// to void so that user data can be passed to each thread</span> <a name="l00202"></a><a class="code" href="a01064.html#1494a3fe0502f5e5cb97a512cf2f55ac">00202</a> <a class="code" href="a01065.html">ThreadInfo</a> ThreadInfoArray[<a class="code" href="a02139.html#804fbb60e0f29e0e0a3d5706c85ef921">VTK_MAX_THREADS</a>]; <a name="l00203"></a>00203 <a name="l00204"></a>00204 <span class="comment">// The methods</span> <a name="l00205"></a><a class="code" href="a01064.html#485669763015dd87577a05aea89f26fb">00205</a> <a class="code" href="a02077.html#1a4a360ecf4efc17d1e2ea057636ec48">vtkThreadFunctionType</a> SingleMethod; <a name="l00206"></a><a class="code" href="a01064.html#c9f7d6eb0b4cca2cca5ffd5361c1a1f8">00206</a> <a class="code" href="a02077.html#1a4a360ecf4efc17d1e2ea057636ec48">vtkThreadFunctionType</a> MultipleMethod[<a class="code" href="a02139.html#804fbb60e0f29e0e0a3d5706c85ef921">VTK_MAX_THREADS</a>]; <a name="l00207"></a>00207 <a name="l00208"></a>00208 <span class="comment">// Storage of MutexFunctions and ints used to control spawned </span> <a name="l00209"></a>00209 <span class="comment">// threads and the spawned thread ids</span> <a name="l00210"></a><a class="code" href="a01064.html#d98bba7b07f6a58adaab356af8cc9ee6">00210</a> <span class="keywordtype">int</span> SpawnedThreadActiveFlag[<a class="code" href="a02139.html#804fbb60e0f29e0e0a3d5706c85ef921">VTK_MAX_THREADS</a>]; <a name="l00211"></a><a class="code" href="a01064.html#7f0fe59d3d88ba2b558b45754af7a61c">00211</a> <a class="code" href="a01074.html" title="mutual exclusion locking class">vtkMutexLock</a> *SpawnedThreadActiveFlagLock[<a class="code" href="a02139.html#804fbb60e0f29e0e0a3d5706c85ef921">VTK_MAX_THREADS</a>]; <a name="l00212"></a><a class="code" href="a01064.html#0b19e5f8dfbb066855854f4268537818">00212</a> <a class="code" href="a02077.html#7eb266a71ebc6d86a0b1d57d021f0b21">vtkThreadProcessIDType</a> SpawnedThreadProcessID[<a class="code" href="a02139.html#804fbb60e0f29e0e0a3d5706c85ef921">VTK_MAX_THREADS</a>]; <a name="l00213"></a><a class="code" href="a01064.html#e06117c3bf5a8aa81c72d288be6e211f">00213</a> <a class="code" href="a01065.html">ThreadInfo</a> SpawnedThreadInfoArray[<a class="code" href="a02139.html#804fbb60e0f29e0e0a3d5706c85ef921">VTK_MAX_THREADS</a>]; <a name="l00214"></a>00214 <a name="l00215"></a>00215 <span class="comment">//ETX</span> <a name="l00216"></a>00216 <a name="l00217"></a>00217 <span class="comment">// Internal storage of the data</span> <a name="l00218"></a><a class="code" href="a01064.html#89874000b4c1932e098a7291de1c4a20">00218</a> <span class="keywordtype">void</span> *SingleData; <a name="l00219"></a><a class="code" href="a01064.html#e116d6f211bd6e2356996f3f01a55829">00219</a> <span class="keywordtype">void</span> *MultipleData[<a class="code" href="a02139.html#804fbb60e0f29e0e0a3d5706c85ef921">VTK_MAX_THREADS</a>]; <a name="l00220"></a>00220 <a name="l00221"></a>00221 <span class="keyword">private</span>: <a name="l00222"></a>00222 <a class="code" href="a01064.html" title="A class for performing multithreaded execution.">vtkMultiThreader</a>(<span class="keyword">const</span> <a class="code" href="a01064.html" title="A class for performing multithreaded execution.">vtkMultiThreader</a>&); <span class="comment">// Not implemented.</span> <a name="l00223"></a>00223 <span class="keywordtype">void</span> operator=(<span class="keyword">const</span> <a class="code" href="a01064.html" title="A class for performing multithreaded execution.">vtkMultiThreader</a>&); <span class="comment">// Not implemented.</span> <a name="l00224"></a>00224 }; <a name="l00225"></a>00225 <a name="l00226"></a>00226 <span class="preprocessor">#endif</span> <a name="l00227"></a>00227 <span class="preprocessor"></span> <a name="l00228"></a>00228 <a name="l00229"></a>00229 <a name="l00230"></a>00230 <a name="l00231"></a>00231 </pre></div></div> <hr size="1"><address style="text-align: right;"><small>Generated on Wed Jun 3 18:35:11 2009 for VTK by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address> </body> </html>