1 // The MIT License (MIT)
2 //
3 // 	Copyright (c) 2015 Sergey Makeev, Vadim Slyusarev
4 //
5 // 	Permission is hereby granted, free of charge, to any person obtaining a copy
6 // 	of this software and associated documentation files (the "Software"), to deal
7 // 	in the Software without restriction, including without limitation the rights
8 // 	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // 	copies of the Software, and to permit persons to whom the Software is
10 // 	furnished to do so, subject to the following conditions:
11 //
12 //  The above copyright notice and this permission notice shall be included in
13 // 	all copies or substantial portions of the Software.
14 //
15 // 	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // 	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // 	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // 	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // 	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // 	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // 	THE SOFTWARE.
22 
23 #pragma once
24 
25 #include <MTTools.h>
26 #include <MTPlatform.h>
27 #include <MTArrayView.h>
28 #include <MTColorTable.h>
29 #include <MTStackRequirements.h>
30 
31 
32 namespace MT
33 {
34 	class FiberContext;
35 	typedef void (*TTaskEntryPoint)(FiberContext & context, const void* userData);
36 	typedef void (*TPoolTaskDestroy)(const void* userData);
37 
38 
39 	namespace internal
40 	{
41 		////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
42 		// Task description
43 		////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
44 		struct TaskDesc
45 		{
46 			//Task entry point
47 			TTaskEntryPoint taskFunc;
48 
49 			//Task destroy func from pool (dtor call)
50 			TPoolTaskDestroy poolDestroyFunc;
51 
52 			//Task user data (task data context)
53 			const void* userData;
54 
55 			//Stack requirements for task
56 			MT::StackRequirements::Type stackRequirements;
57 
58 			//Priority for task
59 			MT::TaskPriority::Type priority;
60 
61 #ifdef MT_INSTRUMENTED_BUILD
62 			const mt_char* debugID;
63 			MT::Color::Type debugColor;
64 #endif
65 
66 			TaskDesc()
67 				: taskFunc(nullptr)
68 				, poolDestroyFunc(nullptr)
69 				, userData(nullptr)
70 				, stackRequirements(MT::StackRequirements::INVALID)
71 			{
72 #ifdef MT_INSTRUMENTED_BUILD
73 				debugID = nullptr;
74 				debugColor = MT::Color::Blue;
75 #endif
76 			}
77 
78 			TaskDesc(TTaskEntryPoint _taskFunc, const void* _userData, MT::StackRequirements::Type _stackRequirements, MT::TaskPriority::Type _priority)
79 				: taskFunc(_taskFunc)
80 				, poolDestroyFunc(nullptr)
81 				, userData(_userData)
82 				, stackRequirements(_stackRequirements)
83 				, priority(_priority)
84 			{
85 #ifdef MT_INSTRUMENTED_BUILD
86 				debugID = nullptr;
87 				debugColor = MT::Color::Blue;
88 #endif
89 			}
90 
91 			TaskDesc(TTaskEntryPoint _taskFunc, TPoolTaskDestroy _poolDestroyFunc, const void* _userData, MT::StackRequirements::Type _stackRequirements)
92 				: taskFunc(_taskFunc)
93 				, poolDestroyFunc(_poolDestroyFunc)
94 				, userData(_userData)
95 				, stackRequirements(_stackRequirements)
96 			{
97 #ifdef MT_INSTRUMENTED_BUILD
98 				debugID = nullptr;
99 				debugColor = MT::Color::Blue;
100 #endif
101 			}
102 
103 			bool IsValid()
104 			{
105 				return (taskFunc != nullptr);
106 			}
107 		};
108 	}
109 
110 }
111