![]() |
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 extern hlx_scheduler gl_scheduler; 00046 00047 /* 00048 ** PROTOTYPES 00049 */ 00050 00051 void hlx_scheduler_schedule(void); 00052 void hlx_scheduler_construct(void); 00053 void hlx_sheduler_end_all_threads(void); 00054 void hlx_scheduler_destruct(void); 00055 00056 /* 00057 ** FUNCTIONS 00058 */ 00059 00060 int hlx_core_init(void) 00061 { 00062 if (gl_api.memcpy_entry == 0) 00063 gl_api.memcpy_entry = hlx_memcpy; 00064 if (gl_api.malloc_entry == 0 || gl_api.free_entry == 0 || 00065 gl_api.atomic_cas_entry == 0 || gl_api.atomic_dcas_entry == 0 || 00066 gl_api.atomic_incr_entry == 0 || gl_api.atomic_decr_entry == 0 || 00067 gl_api.aligned_free_entry == 0 || gl_api.aligned_malloc_entry == 0) 00068 return (0); 00069 if (gl_api.thread_api.thread_construct == 0 || gl_api.thread_api.thread_destruct == 0 || 00070 gl_api.thread_api.thread_execute == 0 || gl_api.thread_api.thread_pause_if_needed == 0 || 00071 gl_api.thread_api.thread_resume == 0 || gl_api.thread_api.thread_suspend == 0 || 00072 gl_api.thread_api.thread_wait_for == 0 || gl_api.thread_api.thread_yield == 0) 00073 return (0); 00074 _init_channel_manager(); 00075 hlx_scheduler_construct(); 00076 return (1); 00077 } 00078 00079 void hlx_core_start(void) 00080 { 00081 hlx_scheduler_schedule(); 00082 } 00083 00084 void hlx_core_stop(void) 00085 { 00086 hlx_sheduler_end_all_threads(); 00087 } 00088 00089 void hlx_core_destroy(void) 00090 { 00091 hlx_scheduler_destruct(); 00092 _destroy_channel_manager(); 00093 } 00094 00095 #endif /* !HLX_BUILD_WITH_KERNEL_THREAD */ 00096 00097 #ifdef __cplusplus 00098 } 00099 #endif 00100 00101 /* 00102 ** END OF FILE 00103 */