![]() |
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 static _hlx_channel_manager gl_channel_manager; 00051 00052 /* 00053 ** FUNCTIONS 00054 */ 00055 00056 static _hlx_channel* _hlx_get_channel_by_hash(unsigned long id) 00057 { 00058 _hlx_channel* chan; 00059 struct slist_element* it; 00060 00061 it = 0; 00062 while (slist_get_head_and_then_next(gl_channel_manager.channels, &it)) 00063 if (slist_get_user_data_from_element(it, (void **)&chan) && chan->hash_code == id) 00064 return (chan); 00065 return (0); 00066 } 00067 00068 HLX_CHAN_WRITE_GENERATOR(short, short, s) 00069 HLX_CHAN_READ_GENERATOR(short, short, s) 00070 00071 HLX_CHAN_WRITE_GENERATOR(int, int, i) 00072 HLX_CHAN_READ_GENERATOR(int, int, i) 00073 00074 HLX_CHAN_WRITE_GENERATOR(char, char, c) 00075 HLX_CHAN_READ_GENERATOR(char, char, c) 00076 00077 HLX_CHAN_WRITE_GENERATOR(float, float, f) 00078 HLX_CHAN_READ_GENERATOR(float, float, f) 00079 00080 HLX_CHAN_WRITE_GENERATOR(ptr, void *, p) 00081 HLX_CHAN_READ_GENERATOR(ptr, void *, p) 00082 00083 hlx_channel_errors hlx_chan_create(unsigned long id) 00084 { 00085 _hlx_channel *chan; 00086 00087 chan = _hlx_get_channel_by_hash(id); 00088 if (chan != 0) 00089 return (CHAN_ERROR_ALREADY_EXISTS); 00090 if ((chan = gl_api.malloc_entry(sizeof(_hlx_channel))) == 0) 00091 return (CHAN_ERROR_MEMORY_EXHAUSTED); 00092 chan->hash_code = id; 00093 chan->status = HLX_CHAN_AVAILABLE; 00094 if (slist_new(&gl_channel_manager.channels, 0, 0) == 0 || slist_new_head(gl_channel_manager.channels, chan) == 0) 00095 { 00096 gl_api.free_entry(chan); 00097 return (EV_ERROR_MEMORY_EXHAUSTED); 00098 } 00099 return (CHAN_ERROR_SUCCESS); 00100 } 00101 00102 void _init_channel_manager(void) 00103 { 00104 slist_new(&gl_channel_manager.channels, 0, 0); 00105 } 00106 00107 void _destroy_channel_manager(void) 00108 { 00109 struct slist_element* it; 00110 _hlx_channel* chan; 00111 00112 it = 0; 00113 while (slist_get_head_and_then_next(gl_channel_manager.channels, &it)) 00114 { 00115 slist_get_user_data_from_element(it, (void **)&chan); 00116 gl_api.free_entry(chan); 00117 } 00118 slist_delete(gl_channel_manager.channels); 00119 } 00120 00121 #endif /* !HLX_BUILD_WITH_PARALLEL_THREADING */ 00122 00123 #ifdef __cplusplus 00124 } 00125 #endif 00126 00127 /* 00128 ** END OF FILE 00129 */