ALBA
albaMultiThreader.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: ALBA (Agile Library for Biomedical Applications)
4 Module: albaMultiThreader
5 Authors: Based on vtkMultiThreader (www.vtk.org), adapted by Marco Petrone
6
7 Copyright (c) BIC
8 All rights reserved. See Copyright.txt or
9
10
11 This software is distributed WITHOUT ANY WARRANTY; without even
12 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the above copyright notice for more information.
14
15=========================================================================*/
16
17#ifndef __albaMultiThreader_h
18#define __albaMultiThreader_h
19
20#include "albaDefines.h"
21#include "albaBase.h"
22#include "albaIncludeWIN32.h"
23
24#define ALBA_MAX_THREADS 16
25
26#ifdef CMAKE_USE_SPROC_INIT
27#include <sys/types.h> Needed for unix implementation of sproc
28#include <unistd.h> Needed for unix implementation of sproc
29#endif
30
31#if defined(CMAKE_USE_PTHREADS_INIT) || defined(CMAKE_HP_PTHREADS_INIT)
32#include <pthread.h> //Needed for PTHREAD implementation of mutex
33#include <sys/types.h> //Needed for unix implementation of pthreads
34#include <unistd.h> //Needed for unix implementation of pthreads
35#endif
47#ifdef CMAKE_USE_SPROC_INIT
48typedef int mmuThreadProcessIDType;
49#endif
50
51
52#ifdef CMAKE_USE_PTHREADS_INIT
53typedef void *(*mmuInternalThreadFunctionType)(void *);
54typedef pthread_t mmuThreadProcessIDType;
55#endif
56
57#ifdef CMAKE_USE_WIN32_THREADS_INIT
58typedef LPTHREAD_START_ROUTINE mmuInternalThreadFunctionType;
59typedef HANDLE mmuThreadProcessIDType;
60#endif
61
62#if !defined(CMAKE_USE_PTHREADS_INIT) && !defined(CMAKE_USE_WIN32_THREADS_INIT)
63typedef void (*mmuInternalThreadFunctionType)(void *);
65#endif
66
67
68class albaMutexLock;
69
75class ALBA_EXPORT albaMultiThreader: public albaBase
76{
77public:
80
81 void Print(std::ostream& os, const int tabs);
82
94#define mmuThreadInfoStruct albaMultiThreader::mmuThreadInfo
96 {
97 public:
103 };
104
105 typedef void (*albaThreadFunctionType)(mmuThreadInfoStruct *);
106
111 int SpawnThread( albaThreadFunctionType, void *UserData );
112
114 void TerminateThread( int thread_id );
115
116protected:
117
122 mmuThreadInfo m_ThreadInfoArray[ALBA_MAX_THREADS];
123
127 int m_SpawnedThreadActiveFlag[ALBA_MAX_THREADS];
128 albaMutexLock* m_SpawnedThreadActiveFlagLock[ALBA_MAX_THREADS];
129 mmuThreadProcessIDType m_SpawnedThreadProcessID[ALBA_MAX_THREADS];
130 mmuThreadInfo m_SpawnedThreadInfoArray[ALBA_MAX_THREADS];
131};
132
133#endif
134
135
136
137
138
#define ALBA_MAX_THREADS
int mmuThreadProcessIDType
#define mmuThreadInfoStruct
This is the structure that is passed to the thread that is created from the SingleMethodExecute,...
void(* mmuInternalThreadFunctionType)(void *)
If CMAKE_USE_SPROC_INIT is defined, then sproc() will be used to create multiple threads on an SGI.
albaBase - the pourpose of this class is just to groups utilities classes
Definition: albaBase.h:27
albaMultiThreader - A class for performing multithreaded execution.
void Print(std::ostream &os, const int tabs)
void TerminateThread(int thread_id)
Terminate the thread that was created with a SpawnThreadExecute()
int SpawnThread(albaThreadFunctionType, void *UserData)
Create a new thread for the given function.
Critical section locking class that can be allocated on the stack.
Definition: albaMutexLock.h:33