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 
TaskDescTaskDesc66 			TaskDesc()
67 				: taskFunc(nullptr)
68 				, poolDestroyFunc(nullptr)
69 				, userData(nullptr)
70 				, stackRequirements(MT::StackRequirements::INVALID)
71 				, priority(MT::TaskPriority::INVALID)
72 			{
73 #ifdef MT_INSTRUMENTED_BUILD
74 				debugID = nullptr;
75 				debugColor = MT::Color::Blue;
76 #endif
77 			}
78 
TaskDescTaskDesc79 			TaskDesc(TTaskEntryPoint _taskFunc, const void* _userData, MT::StackRequirements::Type _stackRequirements, MT::TaskPriority::Type _priority)
80 				: taskFunc(_taskFunc)
81 				, poolDestroyFunc(nullptr)
82 				, userData(_userData)
83 				, stackRequirements(_stackRequirements)
84 				, priority(_priority)
85 			{
86 #ifdef MT_INSTRUMENTED_BUILD
87 				debugID = nullptr;
88 				debugColor = MT::Color::Blue;
89 #endif
90 			}
91 
TaskDescTaskDesc92 			TaskDesc(TTaskEntryPoint _taskFunc, TPoolTaskDestroy _poolDestroyFunc, const void* _userData, MT::StackRequirements::Type _stackRequirements)
93 				: taskFunc(_taskFunc)
94 				, poolDestroyFunc(_poolDestroyFunc)
95 				, userData(_userData)
96 				, stackRequirements(_stackRequirements)
97 				, priority(MT::TaskPriority::INVALID)
98 			{
99 #ifdef MT_INSTRUMENTED_BUILD
100 				debugID = nullptr;
101 				debugColor = MT::Color::Blue;
102 #endif
103 			}
104 
IsValidTaskDesc105 			bool IsValid()
106 			{
107 				return (taskFunc != nullptr);
108 			}
109 		};
110 	}
111 
112 }
113