📄 kapi.cxx
字号:
Cyg_Mempool_Variable *v = (Cyg_Mempool_Variable *)varpool; cyg_uint8 *base; CYG_ADDRWORD maxfree; info->totalmem = v->get_totalmem(); info->freemem = v->get_freemem(); v->get_arena(base, info->size, maxfree); info->base = (void *)base; info->blocksize = -1; info->maxfree = maxfree;}/* Create a fixed size memory pool */externC void cyg_mempool_fix_create( void *base, // base of memory to use for pool cyg_int32 size, // size of memory in byte cyg_int32 blocksize, // size of allocation in bytes cyg_handle_t *handle, // handle of memory pool cyg_mempool_fix *fix // space to put pool structure in ){ CYG_ASSERT_SIZES( cyg_mempool_fix, Cyg_Mempool_Fixed ); Cyg_Mempool_Fixed *t = new((void *)fix) Cyg_Mempool_Fixed ( (cyg_uint8 *)base, size, blocksize ); t=t; CYG_CHECK_DATA_PTR( handle, "Bad handle pointer" ); *handle = (cyg_handle_t)fix;}/* Delete fixed size memory pool */externC void cyg_mempool_fix_delete(cyg_handle_t fixpool){ ((Cyg_Mempool_Fixed *)fixpool)->~Cyg_Mempool_Fixed();}/* Allocates a block. This waits if the memory is not currently available. */externC void *cyg_mempool_fix_alloc(cyg_handle_t fixpool){ return ((Cyg_Mempool_Fixed *)fixpool)->alloc();}#ifdef CYGFUN_KERNEL_THREADS_TIMER/* Allocates a block. This waits for up to delay ticks, if the memory is not already available. NULL is returned if no memory is available. */externC void *cyg_mempool_fix_timed_alloc( cyg_handle_t fixpool, cyg_tick_count_t abstime){ return ((Cyg_Mempool_Fixed *)fixpool)->alloc(abstime);}#endif/* Allocates a block. NULL is returned if no memory is available. */externC void *cyg_mempool_fix_try_alloc(cyg_handle_t fixpool){ return ((Cyg_Mempool_Fixed *)fixpool)->try_alloc();}/* Frees memory back into fixed size pool. */externC void cyg_mempool_fix_free(cyg_handle_t fixpool, void *p){ cyg_bool b; b = ((Cyg_Mempool_Fixed *)fixpool)->free((cyg_uint8 *)p); CYG_ASSERT( b, "Bad free");}/* Returns true if there are any threads waiting for memory in the given memory pool. */externC cyg_bool_t cyg_mempool_fix_waiting(cyg_handle_t fixpool){ return ((Cyg_Mempool_Fixed *)fixpool)->waiting();}/* Puts information about a variable memory pool into the structure provided. */externC void cyg_mempool_fix_get_info( cyg_handle_t fixpool, cyg_mempool_info *info){ Cyg_Mempool_Fixed *f = (Cyg_Mempool_Fixed *)fixpool; cyg_uint8 *base; cyg_addrword_t blocksize; info->totalmem = f->get_totalmem(); info->freemem = f->get_freemem(); f->get_arena(base, info->size, blocksize); info->base = (void *)base; info->maxfree = info->blocksize = (cyg_int32)blocksize;}/*---------------------------------------------------------------------------*//* Semaphores */externC void cyg_semaphore_init( cyg_sem_t *sem, /* Semaphore to init */ cyg_count32 val /* Initial semaphore value */){ CYG_ASSERT_SIZES( cyg_sem_t, Cyg_Counting_Semaphore ); Cyg_Counting_Semaphore *t = new((void *)sem) Cyg_Counting_Semaphore(val); t=t;}externC void cyg_semaphore_destroy( cyg_sem_t *sem ){ ((Cyg_Counting_Semaphore *)sem)->~Cyg_Counting_Semaphore();}externC void cyg_semaphore_wait( cyg_sem_t *sem ){ ((Cyg_Counting_Semaphore *)sem)->wait();}#ifdef CYGFUN_KERNEL_THREADS_TIMERexternC cyg_bool_t cyg_semaphore_timed_wait( cyg_sem_t *sem, cyg_tick_count_t abstime ){ return ((Cyg_Counting_Semaphore *)sem)->wait(abstime);}#endifexternC int cyg_semaphore_trywait( cyg_sem_t *sem ){ return ((Cyg_Counting_Semaphore *)sem)->trywait();}externC void cyg_semaphore_post( cyg_sem_t *sem ){ ((Cyg_Counting_Semaphore *)sem)->post();}externC void cyg_semaphore_peek( cyg_sem_t *sem, cyg_count32 *val ){ CYG_CHECK_DATA_PTR( val, "Bad val parameter" ); *val = ((Cyg_Counting_Semaphore *)sem)->peek();}/*---------------------------------------------------------------------------*//* Flags */void cyg_flag_init( cyg_flag_t *flag /* Flag to init */){ CYG_ASSERT_SIZES( cyg_flag_t, Cyg_Flag ); CYG_ASSERT( ( Cyg_Flag::AND == CYG_FLAG_WAITMODE_AND ) && ( Cyg_Flag::OR == CYG_FLAG_WAITMODE_OR ) && ( Cyg_Flag::CLR == CYG_FLAG_WAITMODE_CLR ), "CYG_FLAG_WAITMODE_xxx definition != C++ Cyg_Flag::xxx" ); Cyg_Flag *t = new((void *)flag) Cyg_Flag(); t=t;}void cyg_flag_destroy( cyg_flag_t *flag ){ ((Cyg_Flag *)flag)->~Cyg_Flag();}void cyg_flag_setbits( cyg_flag_t *flag, cyg_flag_value_t value){ ((Cyg_Flag *)flag)->setbits( value ); }void cyg_flag_maskbits( cyg_flag_t *flag, cyg_flag_value_t value){ ((Cyg_Flag *)flag)->maskbits( value ); }cyg_flag_value_t cyg_flag_wait( cyg_flag_t *flag, cyg_flag_value_t pattern, cyg_flag_mode_t mode ){ if ( 0 == pattern || 0 != (mode & ~3) ) return 0; return ((Cyg_Flag *)flag)->wait( pattern, mode );}#ifdef CYGFUN_KERNEL_THREADS_TIMERcyg_flag_value_t cyg_flag_timed_wait( cyg_flag_t *flag, cyg_flag_value_t pattern, cyg_flag_mode_t mode, cyg_tick_count_t abstime ){ if ( 0 == pattern || 0 != (mode & ~3) ) return 0; return ((Cyg_Flag *)flag)->wait( pattern, mode, abstime );}#endifcyg_flag_value_t cyg_flag_poll( cyg_flag_t *flag, cyg_flag_value_t pattern, cyg_flag_mode_t mode ){ if ( 0 == pattern || 0 != (mode & ~3) ) return 0; return ((Cyg_Flag *)flag)->poll( pattern, mode );}cyg_flag_value_t cyg_flag_peek( cyg_flag_t *flag ){ return ((Cyg_Flag *)flag)->peek();}cyg_bool_t cyg_flag_waiting( cyg_flag_t *flag ){ return ((Cyg_Flag *)flag)->waiting();}/*---------------------------------------------------------------------------*//* Mutex */externC void cyg_mutex_init( cyg_mutex_t *mutex /* Mutex to init */){ CYG_ASSERT_SIZES( cyg_mutex_t, Cyg_Mutex ); Cyg_Mutex *m = new((void *)mutex) Cyg_Mutex; m=m;}externC void cyg_mutex_destroy( cyg_mutex_t *mutex ){ // no need to do anything here}externC cyg_bool_t cyg_mutex_lock( cyg_mutex_t *mutex ){ return ((Cyg_Mutex *)mutex)->lock();}externC cyg_bool_t cyg_mutex_trylock( cyg_mutex_t *mutex ){ return ((Cyg_Mutex *)mutex)->trylock();}externC void cyg_mutex_unlock( cyg_mutex_t *mutex ){ ((Cyg_Mutex *)mutex)->unlock();}externC void cyg_mutex_release( cyg_mutex_t *mutex ){ ((Cyg_Mutex *)mutex)->release();}/*---------------------------------------------------------------------------*//* Condition Variables */externC void cyg_cond_init( cyg_cond_t *cond, /* condition variable to init */ cyg_mutex_t *mutex /* associated mutex */){ CYG_ASSERT_SIZES( cyg_cond_t, Cyg_Condition_Variable ); Cyg_Condition_Variable *t = new((void *)cond) Cyg_Condition_Variable( *(Cyg_Mutex *)mutex); t=t;}externC void cyg_cond_destroy( cyg_cond_t *cond ){ ((Cyg_Counting_Semaphore *)cond)->~Cyg_Counting_Semaphore();}externC void cyg_cond_wait( cyg_cond_t *cond ){ ((Cyg_Condition_Variable *)cond)->wait();}externC void cyg_cond_signal( cyg_cond_t *cond ){ ((Cyg_Condition_Variable *)cond)->signal();}externC void cyg_cond_broadcast( cyg_cond_t *cond ){ ((Cyg_Condition_Variable *)cond)->broadcast();}#ifdef CYGMFN_KERNEL_SYNCH_CONDVAR_TIMED_WAITexternC cyg_bool_t cyg_cond_timed_wait( cyg_cond_t *cond, cyg_tick_count_t abstime ){ return ((Cyg_Condition_Variable *)cond)->wait(abstime);}#endif// -------------------------------------------------------------------------// Check structure sizes.// This class and constructor get run automatically in debug versions// of the kernel and check that the structures configured in the C// code are the same size as the C++ classes they should match.#ifdef CYGPKG_INFRA_DEBUGclass Cyg_Check_Structure_Sizes{ int dummy;public: Cyg_Check_Structure_Sizes( int x );};#define CYG_CHECK_SIZES(cstruct, cxxstruct) \if( sizeof(cstruct) != sizeof(cxxstruct) ) \{ \ char *fmt = "Size of C struct " #cstruct \ " != size of C++ struct " #cxxstruct ; \ CYG_TRACE2(1, fmt, sizeof(cstruct) , sizeof(cxxstruct) ); \ fail = true; \ fmt = fmt; \}Cyg_Check_Structure_Sizes::Cyg_Check_Structure_Sizes(int x){ cyg_bool fail = false; dummy = x+1; CYG_CHECK_SIZES( cyg_thread, Cyg_Thread ); CYG_CHECK_SIZES( cyg_interrupt, Cyg_Interrupt ); CYG_CHECK_SIZES( cyg_counter, Cyg_Counter ); CYG_CHECK_SIZES( cyg_clock, Cyg_Clock ); CYG_CHECK_SIZES( cyg_alarm, Cyg_Alarm ); CYG_CHECK_SIZES( cyg_mbox, Cyg_Mbox ); CYG_CHECK_SIZES( cyg_mempool_var, Cyg_Mempool_Variable ); CYG_CHECK_SIZES( cyg_mempool_fix, Cyg_Mempool_Fixed ); CYG_CHECK_SIZES( cyg_sem_t, Cyg_Counting_Semaphore ); CYG_CHECK_SIZES( cyg_flag_t, Cyg_Flag ); CYG_CHECK_SIZES( cyg_mutex_t, Cyg_Mutex ); CYG_CHECK_SIZES( cyg_cond_t, Cyg_Condition_Variable ); CYG_ASSERT( !fail, "Size checks failed");}Cyg_Check_Structure_Sizes check_structure_sizes(1);#endif// -------------------------------------------------------------------------#endif// EOF common/kapi.cxx
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -