![]() |
Helixis 1.0
Task Programming API
|
00001 /* 00002 ** Copyright 2009-2011, helixis.org 00003 ** All rights reserved. 00004 ** 00005 ** Redistribution and use in source and binary forms, with or without modification, are permitted provided 00006 ** that the following conditions are met: 00007 ** 00008 ** Redistributions of source code must retain the above copyright notice, this list of conditions and the 00009 ** following disclaimer. 00010 ** 00011 ** Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 00012 ** the following disclaimer in the documentation and/or other materials provided with the distribution. 00013 ** 00014 ** Neither the name of the helixis.org nor the names of its contributors may be used to endorse or promote 00015 ** products derived from this software without specific prior written permission. 00016 ** 00017 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 00018 ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00019 ** PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00020 ** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00021 ** TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00022 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00023 ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00024 ** POSSIBILITY OF SUCH DAMAGE. 00025 */ 00026 00027 /* 00028 ** INCLUDES 00029 */ 00030 00031 #include "hlx/core.h" 00032 #include "helixis_internal.h" 00033 00034 #if !defined(HLX_BUILD_WITH_PARALLEL_THREADING) 00035 00036 #ifdef __cplusplus 00037 extern "C" { 00038 #endif 00039 00040 /* 00041 ** EXTERNALS 00042 */ 00043 00044 extern hlx_api gl_api; 00045 00046 /* 00047 ** GLOBALS 00048 */ 00049 00050 hlx_scheduler gl_scheduler; 00051 00052 /* 00053 ** PROTOTYPES 00054 */ 00055 00056 hlx_group* hlx_sheduler_find_lighter_group(void); 00057 hlx_task* hlx_scheduler_init_task(hlx_task_func task_func, void* data, hlx_group* group, hlx_task_callback callback); 00058 void hlx_scheduler_schedule(void); 00059 int hlx_scheduler_schedule_group(hlx_group*); 00060 00061 /* 00062 ** FUNCTIONS 00063 */ 00064 00065 void hlx_core_add_task_in_group_callback(hlx_task_func task_func, void* data, hlx_group_id group_id, hlx_group_id self_group_id, hlx_task_callback callback) 00066 { 00067 hlx_task* task; 00068 hlx_group* group; 00069 00070 HLX_UNUSED(self_group_id); 00071 group = (hlx_group*)group_id; 00072 task = hlx_scheduler_init_task(task_func, data, group, callback); 00073 if (!task) 00074 return; 00075 hlx_group_add_task(group, task); 00076 } 00077 00078 void hlx_core_add_task_in_group(hlx_task_func task_func, void* data, hlx_group_id group_id) 00079 { 00080 hlx_core_add_task_in_group_callback(task_func, data, group_id, 0, 0); 00081 } 00082 00083 void hlx_core_add_task_callback(hlx_task_func task_func, void* data, hlx_group_id self_group_id, hlx_task_callback callback) 00084 { 00085 hlx_core_add_task_in_group_callback(task_func, data, hlx_sheduler_find_lighter_group()->id, self_group_id, callback); 00086 } 00087 00088 void hlx_scheduler_schedule() 00089 { 00090 hlx_list_node* it; 00091 unsigned int i; 00092 unsigned int count; 00093 unsigned int flag_try; 00094 00095 count = 1; 00096 flag_try = 0; 00097 gl_scheduler.loop = 1; 00098 while (gl_scheduler.loop && count) 00099 { 00100 count = 0; 00101 for (i = 0, it = gl_scheduler.groups.first; it != 0; it = it->next, ++i) 00102 count += hlx_scheduler_schedule_group(it->data); 00103 if (flag_try && count) 00104 flag_try = 0; 00105 if (!count && !flag_try) 00106 { 00107 count = 1; 00108 flag_try = 1; 00109 } 00110 } 00111 } 00112 00113 #endif /* HLX_BUILD_WITH_PARALLEL_THREADING */ 00114 00115 #ifdef __cplusplus 00116 } 00117 #endif 00118 00119 /* 00120 ** END OF FILE 00121 */