Commit cde08c27 authored by Ken Martin's avatar Ken Martin
Browse files

add mac thread limit

parent 6c4f703f
......@@ -52,6 +52,20 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#include <pthread.h>
#endif
// Initialize static member that controls global maximum number of threads
static int vtkMultiThreaderGlobalMaximumNumberOfThreads = 0;
void vtkMultiThreader::SetGlobalMaximumNumberOfThreads(int val)
{
if (val == vtkMultiThreaderGlobalMaximumNumberOfThreads) return;
vtkMultiThreaderGlobalMaximumNumberOfThreads = val;
}
int vtkMultiThreader::GetGlobalMaximumNumberOfThreads()
{
return vtkMultiThreaderGlobalMaximumNumberOfThreads;
}
// Description:
// Constructor. Default all the methods to NULL. Since the
// ThreadInfoArray is static, the ThreadIDs can be initialized here
......@@ -170,6 +184,14 @@ void vtkMultiThreader::SingleMethodExecute()
return;
}
// obey the global maximum number of threads limit
if (vtkMultiThreaderGlobalMaximumNumberOfThreads &&
this->NumberOfThreads > vtkMultiThreaderGlobalMaximumNumberOfThreads)
{
this->NumberOfThreads = vtkMultiThreaderGlobalMaximumNumberOfThreads;
}
// We are using sproc (on SGIs), pthreads(on Suns), or a single thread
// (the default)
......@@ -327,6 +349,13 @@ void vtkMultiThreader::MultipleMethodExecute()
#endif
// obey the global maximum number of threads limit
if (vtkMultiThreaderGlobalMaximumNumberOfThreads &&
this->NumberOfThreads > vtkMultiThreaderGlobalMaximumNumberOfThreads)
{
this->NumberOfThreads = vtkMultiThreaderGlobalMaximumNumberOfThreads;
}
for ( thread_loop = 0; thread_loop < this->NumberOfThreads; thread_loop++ )
if ( this->MultipleMethod[thread_loop] == (vtkThreadFunctionType)NULL)
{
......@@ -620,5 +649,7 @@ void vtkMultiThreader::PrintSelf(ostream& os, vtkIndent indent)
{
os << indent << "Thread Count: " << this->NumberOfThreads << "\n";
os << indent << "Global Maximum Number Of Threads: " <<
vtkMultiThreaderGlobalMaximumNumberOfThreads << endl;
}
......@@ -196,6 +196,13 @@ public:
// Terminate the thread that was created with a SpawnThreadExecute()
void TerminateThread( int thread_id );
// 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();
protected:
// The number of threads to use
int NumberOfThreads;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment