1 /*
2  * Project: VizKit
3  * Version: 2.3
4 
5  * Date: 20090823
6  * File: VisualThreading.h
7  *
8  */
9 
10 /***************************************************************************
11 
12 Copyright (c) 2004-2009 Heiko Wichmann (http://www.imagomat.de/vizkit)
13 
14 
15 This software is provided 'as-is', without any expressed or implied warranty.
16 In no event will the authors be held liable for any damages
17 arising from the use of this software.
18 
19 Permission is granted to anyone to use this software for any purpose,
20 including commercial applications, and to alter it and redistribute it
21 freely, subject to the following restrictions:
22 
23 1. The origin of this software must not be misrepresented;
24    you must not claim that you wrote the original software.
25    If you use this software in a product, an acknowledgment
26    in the product documentation would be appreciated
27    but is not required.
28 
29 2. Altered source versions must be plainly marked as such,
30    and must not be misrepresented as being the original software.
31 
32 3. This notice may not be removed or altered from any source distribution.
33 
34  ***************************************************************************/
35 
36 #ifndef VisualThreading_h
37 #define VisualThreading_h
38 
39 
40 #include "VisualTypes.h"
41 
42 #if TARGET_OS_MAC
43 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h> // signature typedef OSStatus (*ThreadingFuncPtr)(void* parameter);
44 #endif
45 
46 #if TARGET_OS_WIN
47 #include <windows.h>
48 #endif
49 
50 
51 namespace VizKit {
52 
53 
54 #ifndef ThreadingFuncPtr_def
55 #define ThreadingFuncPtr_def
56 #if TARGET_OS_MAC
57 typedef OSStatus (*ThreadingFuncPtr)(void* parameter);
58 #endif
59 #if TARGET_OS_WIN
60 typedef DWORD (*ThreadingFuncPtr)(LPVOID lpParam);
61 #endif
62 #endif
63 
64 
65 	/**
66 	 * Providing multi-threading functionality.
67 	 */
68 	class VisualThreading {
69 
70 	public:
71 
72 		/**
73 		 * Callback that is called after a thread died.
74 		 */
75 		typedef void (*ThreadDidDieCallback)();
76 
77 		/**
78 		 * Creates a new thread by calling task function.
79 		 * @param aThreadingFuncPtr Pointer to function that should be started in new thread.
80 		 * @param param Optional name for function-thread. Useful for debugging purposes.
81 		 * @param callbackAfterThreadDidDie Callback that is called after the created thread did finished execution.
82 		 * @return True on success, false on failure.
83 		 */
84 		static bool createThread(ThreadingFuncPtr aThreadingFuncPtr, void* param = NULL, ThreadDidDieCallback callbackAfterThreadDidDie = NULL);
85 
86 	private:
87 
88 		/** The constructor. VisualThreading is a collection of static methods. Class does not need any instances. Constructor is private and not implemented. */
89 		VisualThreading();
90 
91 		/** The destructor. VisualThreading is a collection of static methods. Class does not need any instances. Destructor is private and not implemented. */
92 		~VisualThreading();
93 
94 	};
95 
96 }
97 
98 #endif /* VisualThreading_h */
99