![]() |
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 #ifndef __HLX_API_H__ 00028 # define __HLX_API_H__ 00029 00030 #ifdef __cplusplus 00031 extern "C" { 00032 #endif 00033 00034 /* 00035 ** TYPES 00036 */ 00037 00038 typedef void* (*hlx_malloc_entry_addr)(unsigned int); 00039 typedef void (*hlx_free_entry_addr)(void *); 00040 typedef void* (*hlx_aligned_malloc_entry_addr)(unsigned int size, unsigned int align); 00041 typedef void (*hlx_aligned_free_entry_addr)(void *); 00042 typedef atom_t (*hlx_atomic_incr_entry_addr)(atom_t *); 00043 typedef atom_t (*hlx_atomic_decr_entry_addr)(atom_t *); 00044 typedef atom_t (*hlx_atomic_cas_entry_addr)(volatile atom_t* dest, atom_t exchange, atom_t compare); 00045 typedef unsigned char (*hlx_atomic_dcas_entry_addr)(volatile atom_t *dest, atom_t* exchange, atom_t* compare); 00046 typedef unsigned int (*hlx_get_cpu_count_entry_addr)(void); 00047 typedef void* (*hlx_memcpy_entry_addr)(void*, const void*, unsigned int); 00048 00049 /* Thread API */ 00050 00051 typedef struct _hlx_thread hlx_thread; 00052 typedef void (*hlx_thread_func)(hlx_thread*, void*); 00053 00054 typedef struct _hlx_thread_param hlx_thread_param; 00055 struct _hlx_thread_param 00056 { 00057 hlx_thread* thread; 00058 void* data; 00059 }; 00060 00061 typedef enum 00062 { 00063 HLX_THREAD_PAUSED = 0, 00064 HLX_THREAD_LOCKED = 1, 00065 HLX_THREAD_RUNNING = 2 00066 } hlx_thread_status; 00067 00068 struct _hlx_thread 00069 { 00070 hlx_thread_func thread_func; 00071 hlx_thread_param param; 00072 hlx_thread_status status; 00073 void *user1; 00074 void *user2; 00075 }; 00076 00077 typedef void (*hlx_thread_construct)(hlx_thread *); 00078 typedef void (*hlx_thread_destruct)(hlx_thread *); 00079 typedef void (*hlx_thread_execute)(hlx_thread *, hlx_thread_func, void *); 00080 typedef void (*hlx_thread_suspend)(hlx_thread *); 00081 typedef void (*hlx_thread_resume)(hlx_thread *); 00082 typedef void (*hlx_thread_wait_for)(hlx_thread *); 00083 typedef void (*hlx_thread_pause_if_needed)(hlx_thread *); 00084 typedef void (*hlx_thread_yield)(void); 00085 00086 typedef struct 00087 { 00088 hlx_thread_construct thread_construct; 00089 hlx_thread_destruct thread_destruct; 00090 hlx_thread_execute thread_execute; 00091 hlx_thread_suspend thread_suspend; 00092 hlx_thread_resume thread_resume; 00093 hlx_thread_wait_for thread_wait_for; 00094 hlx_thread_pause_if_needed thread_pause_if_needed; 00095 hlx_thread_yield thread_yield; 00096 } hlx_thread_api; 00097 00098 /* Helixis core API */ 00099 typedef struct 00100 { 00101 hlx_malloc_entry_addr malloc_entry; 00102 hlx_free_entry_addr free_entry; 00103 /* PARALLEL THREADING only */ 00104 hlx_aligned_malloc_entry_addr aligned_malloc_entry; 00105 hlx_aligned_free_entry_addr aligned_free_entry; 00106 hlx_atomic_incr_entry_addr atomic_incr_entry; 00107 hlx_atomic_decr_entry_addr atomic_decr_entry; 00108 hlx_atomic_cas_entry_addr atomic_cas_entry; 00109 hlx_atomic_dcas_entry_addr atomic_dcas_entry; 00110 hlx_thread_api thread_api; 00111 /* OPTIONNAL */ 00112 hlx_get_cpu_count_entry_addr get_cpu_count_entry; 00113 hlx_memcpy_entry_addr memcpy_entry; 00114 } hlx_api; 00115 00116 /* 00117 ** FUNCTIONS 00118 */ 00119 00124 hlx_api* hlx_get_api_entries(void); 00125 00126 #ifdef __cplusplus 00127 } 00128 #endif 00129 00130 #endif /* !__HLX_API_H__ */ 00131 00132 /* 00133 ** END OF FILE 00134 */