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 <MTConcurrentQueueLIFO.h> 28 #include <MTStackArray.h> 29 #include <MTArrayView.h> 30 #include <MTColorTable.h> 31 32 33 namespace MT 34 { 35 class FiberContext; 36 typedef void (*TTaskEntryPoint)(FiberContext & context, void* userData); 37 38 typedef void (*TPoolTaskDestroy)(void* userData); 39 40 41 namespace internal 42 { 43 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 44 // Task description 45 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 46 struct TaskDesc 47 { 48 //Task entry point 49 TTaskEntryPoint taskFunc; 50 51 //Task destroy func from pool (dtor call) 52 TPoolTaskDestroy poolDestroyFunc; 53 54 //Task user data (task data context) 55 void* userData; 56 57 #ifdef MT_INSTRUMENTED_BUILD 58 const mt_char* debugID; 59 MT::Color::Type debugColor; 60 #endif 61 62 TaskDesc() 63 : taskFunc(nullptr) 64 , poolDestroyFunc(nullptr) 65 , userData(nullptr) 66 { 67 #ifdef MT_INSTRUMENTED_BUILD 68 debugID = nullptr; 69 debugColor = MT::Color::Blue; 70 #endif 71 } 72 73 TaskDesc(TTaskEntryPoint _taskFunc, void* _userData) 74 : taskFunc(_taskFunc) 75 , poolDestroyFunc(nullptr) 76 , userData(_userData) 77 { 78 #ifdef MT_INSTRUMENTED_BUILD 79 debugID = nullptr; 80 debugColor = MT::Color::Blue; 81 #endif 82 } 83 84 TaskDesc(TTaskEntryPoint _taskFunc, TPoolTaskDestroy _poolDestroyFunc, void* _userData) 85 : taskFunc(_taskFunc) 86 , poolDestroyFunc(_poolDestroyFunc) 87 , userData(_userData) 88 { 89 #ifdef MT_INSTRUMENTED_BUILD 90 debugID = nullptr; 91 debugColor = MT::Color::Blue; 92 #endif 93 } 94 95 bool IsValid() 96 { 97 return (taskFunc != nullptr); 98 } 99 }; 100 } 101 102 } 103