eLynx SDK
v3.3.0 C++ image processing API reference |
00001 //============================================================================ 00002 // TaskScheduler.h Core.Component package 00003 //============================================================================ 00004 // Usage : Timer class. 00005 //---------------------------------------------------------------------------- 00006 // Copyright (C) 2006 by eLynx project 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // Library General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Library General Public 00019 // License along with this library; if not, write to the Free 00020 // Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00021 // 00022 //---------------------------------------------------------------------------- 00023 #ifndef __TaskScheduler_h__ 00024 #define __TaskScheduler_h__ 00025 00026 #include <elx/core/CoreOS.h> 00027 #include <elx/core/CoreLib.h> 00028 00029 #ifdef elxUSE_THREAD 00030 00031 #include <vector> 00032 #include <boost/function.hpp> 00033 #include <elx/core/CoreTypes.h> 00034 00035 namespace eLynx { 00036 00041 class ExportedByCore TaskScheduler 00042 { 00043 public: 00044 typedef boost::function0<uint32> Task; 00045 // we should use typedef boost::function<uint32 ()> Task; 00046 00048 TaskScheduler(); 00049 00052 void AddTask(Task iTask); 00053 00055 uint32 Run(); 00056 00059 static uint32 GetCPUCount(); 00060 00061 private: 00063 uint32 RunSingleCore(); 00064 00066 uint32 RunMultiCore(); 00067 00070 struct CoreTask 00071 { 00075 CoreTask(Task iTask, size_t iCPU); 00076 00078 uint32 operator()(); 00079 00080 Task _task; 00081 size_t _CPU; 00082 uint32 _status; 00083 }; 00084 00085 const static size_t _nCPU; 00086 std::vector<CoreTask> _tasks; 00087 size_t _CPU; 00088 }; 00089 00090 } // namespace eLynx 00091 00092 #else // elxUSE_THREAD 00093 00094 namespace eLynx { 00095 00096 class ExportedByCore TaskScheduler 00097 { 00098 public: 00101 static uint32 GetCPUCount(); 00102 }; 00103 00104 } // namespace eLynx 00105 00106 00107 #endif //elxUSE_THREAD 00108 00109 #endif // __TaskScheduler_h__