⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdb.c

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 C
📖 第 1 页 / 共 2 页
字号:
    entry->context.status |= SUBS_STATUS_RECONF;  }  pthread_mutex_unlock( &entry->mutex_config );  if ( ( SUBS_STATUS_RECONF & entry->context.status ) &&       call_reconf ){    PR_DBG( 4, "Trying to reconfigure\n" );    swr_sdb_send_msg( id, SUBS_MSG_RECONFIG, 0, -1 );  }  return ret;swr_sdb_set_config_error:  pthread_mutex_unlock( &entry->mutex_config );  return ret;}/** * @short Returns a value from the config-structure */int swr_sdb_get_config_parameter_value( swr_sdb_id id, int param, void *data ) {  sdb_t *entry;  int ret = -1;  if ( id < 0 )    return -1;  entry = &ENTRY(id);  if ( SUBS_STATUS_RECONF & entry->context.status ){    PR_DBG( 4, "Trying to reconfigure in get_config\n" );    swr_sdb_send_msg( id, SUBS_MSG_RECONFIG, 0, -1 );  }  pthread_mutex_lock( &entry->mutex_config );  if ( entry->context.id != id )    goto swr_sdb_get_config_error;  if ( swr_spc_get_config_parameter_value( entry->context.cdb_desc,       entry->config_data, param, data ) )    ret = 0;swr_sdb_get_config_error:  pthread_mutex_unlock( &entry->mutex_config );  return ret;}/** * @short Returns the type of a certain parameter */parameter_type_t swr_sdb_get_config_parameter_type( swr_sdb_id id, int param ) {  sdb_t *entry;  int ret = UNDEFINED;  // id < -1 will be reflected to support some strange behaviour of  // swr_sdb_set_config  if ( id < 0 ){    if ( id < -1 ){      id = -id;    } else {      // Well, this is not a module-id      return UNDEFINED;    }  }  entry = &ENTRY(id);  pthread_mutex_lock( &entry->mutex_config );  if ( entry->context.id != id )    goto swr_sdb_get_config_error;  ret = swr_spc_get_config_type( entry->context.cdb_desc, param );swr_sdb_get_config_error:  pthread_mutex_unlock( &entry->mutex_config );  return ret;}/** * @short Returns the number of a certain parameter */int swr_sdb_get_stats_parameter_nbr( swr_sdb_id id, char *name ) {  sdb_t *entry;  int ret = -1;  if ( id < 0 )    return -1;  entry = &ENTRY(id);  pthread_mutex_lock( &entry->mutex_stats );  if ( entry->context.id != id )    goto swr_sdb_get_stat_param_error;  ret = swr_spc_get_stats_parameter_nbr( entry->context.cdb_desc, name );swr_sdb_get_stat_param_error:  pthread_mutex_unlock( &entry->mutex_stats );  return ret;}/** * @short Writes a new value to the stat-structure */int swr_sdb_set_stats_parameter_value( swr_sdb_id id, int param, void *data ) {  sdb_t *entry;  int ret = -1;  if ( id < 0 )    return -1;  PR_DBG( 0, "Writing stats params is BAD\n" );  entry = &ENTRY(id);  pthread_mutex_lock( &entry->mutex_stats );  if ( entry->context.id != id )    goto swr_sdb_set_stat_error;  if ( swr_spc_set_stats_parameter_value( entry->context.cdb_desc,                                          entry->stats_data, param, data ) )    ret = 0;swr_sdb_set_stat_error:  pthread_mutex_unlock( &entry->mutex_stats );  return ret;}/** * @short Returns a value from the stat-structure */int swr_sdb_get_stats_parameter_value( swr_sdb_id id, int param, void *data ) {  sdb_t *entry;  int ret = -1;  if ( id < 0 )    return -1;  entry = &ENTRY(id);  if ( SUBS_STATUS_RECONF & entry->context.status ){    PR_DBG( 4, "Trying to reconfigure in get_stats\n" );    swr_sdb_send_msg( id, SUBS_MSG_RECONFIG, 0, -1 );  }  pthread_mutex_lock( &entry->mutex_stats );  if ( entry->context.id != id )    goto swr_sdb_get_stat_error;  if ( swr_spc_get_stats_parameter_value( entry->context.cdb_desc,                                          entry->stats_data, param, data ) )    ret = 0;swr_sdb_get_stat_error:  pthread_mutex_unlock( &entry->mutex_stats );  return ret;}/** * @short Returns the type of a certain parameter */parameter_type_t swr_sdb_get_stats_parameter_type( swr_sdb_id id, int param ) {  sdb_t *entry;  int ret = UNDEFINED;  if ( id < 0 )    return UNDEFINED;  entry = &ENTRY(id);  pthread_mutex_lock( &entry->mutex_config );  if ( entry->context.id != id )    goto swr_sdb_get_config_error;  ret = swr_spc_get_stats_type( entry->context.cdb_desc, param );swr_sdb_get_config_error:  pthread_mutex_unlock( &entry->mutex_config );  return ret;}/** * @short Gets a config- or stats-structure and locks the subsystem */int swr_sdb_get_config_struct( swr_sdb_id id, void **str ) {  sdb_t *entry;  if ( id < 0 )    return -1;  entry = &ENTRY(id);  pthread_mutex_lock( &entry->mutex_config );  if ( entry->context.id != id )    goto swr_sdb_get_config_struct_error;  *str = entry->config_data;  return 0;swr_sdb_get_config_struct_error:  PR_DBG( 0, "ID not valid\n" );  pthread_mutex_unlock( &entry->mutex_config );  return -1;}int swr_sdb_get_stats_struct( swr_sdb_id id, void **str ) {  sdb_t *entry;  if ( id < 0 )    return -1;  entry = &ENTRY(id);  pthread_mutex_lock( &entry->mutex_stats );  if ( entry->context.id != id )    goto swr_sdb_get_stats_struct_error;  *str = entry->stats_data;  return 0;swr_sdb_get_stats_struct_error:  PR_DBG( 0, "ID not valid\n" );  pthread_mutex_unlock( &entry->mutex_stats );  return -1;}/** * @short Unlocks a config- or stats-structure */int swr_sdb_free_config_struct( swr_sdb_id id, void **str ) {  CHECK_ID( id );  *str = NULL;  pthread_mutex_unlock( &ENTRY(id).mutex_config );  return 0;}int swr_sdb_free_stats_struct( swr_sdb_id id, void **str ) {  CHECK_ID( id );  *str = NULL;  pthread_mutex_unlock( &ENTRY(id).mutex_stats );  return 0;}/** * Get the size of a single entity of this signal, in bytes */int swr_sdb_get_input_port_size(const swr_sdb_id id,                                int port) {  CHECK_ID( id );  if ( port >= ENTRY(id).context.cdb_desc->inputs.nbr_ports ) {    PR_DBG( 0, "Input-port-# too high\n" );    return -1;  }  return ENTRY(id).context.port_in[ port ].size;}int swr_sdb_get_output_port_size(const swr_sdb_id id,                                 int port)  {  CHECK_ID( id );  if ( port >= ENTRY(id).context.cdb_desc->outputs.nbr_ports ) {    PR_DBG( 0, "Output-port-# too high\n" );    return -1;  }  return ENTRY(id).context.port_out[ port ].size;}/** * Get the data from a given output-port */int swr_sdb_get_output_port_data(const swr_sdb_id id, int port, void *dst) {  void *src;  swr_port_t *p;  CHECK_ID( id );  if ( port >= ENTRY(id).context.cdb_desc->outputs.nbr_ports ) {    PR_DBG( 0, "Output-port-# too high\n" );    return -1;  }  p = &ENTRY(id).context.port_out[port];  src = p->data;  if ( !src ) {    PR_DBG( 0, "Asking for empty port" );    return -1;  }  memcpy( dst, src, p->size * swr_spc_get_type_size( p->type ) );  return 0;}/** * @short gets one profile */int swr_sdb_get_profile( swr_sdb_id id, enum swr_profiling profile, 			 long long int *time, long long int *calls ) {  CHECK_ID( id );  if ( time ) {    *time = ENTRY(id).context.profiling.time[ profile ];  }  if ( calls ) {    *calls = ENTRY(id).context.profiling.calls[ profile ];  }  return 0;}/** * @short Sets a profile to zero */int swr_sdb_clear_profile( swr_sdb_id id ) {  int i;  CHECK_ID( id );  for ( i=0; i<=profiling_total; i++ ) {    ENTRY(id).context.profiling.time[ i ] = 0;    ENTRY(id).context.profiling.calls[ i ] = 0;  }  return 0;}#define TIME_STR_LEN 10char *disp_time( char *str, long int time ) {  if ( time < 100000 ) {    snprintf( str, TIME_STR_LEN, "%5li[us]", time );  } else if ( ( time /= 1000 ) < 100000 ) {    snprintf( str, TIME_STR_LEN, "%5li[ms]", time );  } else if ( ( time /= 1000 ) < 6000 ) {    snprintf( str, TIME_STR_LEN, "%5li[ s]", time );  } else if ( ( time /= 60 ) < 6000 ) {    snprintf( str, TIME_STR_LEN, "%5li[ m]", time );  } else {    snprintf( str, TIME_STR_LEN, "%5li[ h]", time / 60 );  }  return str;}/** * @short Displays a complete profile */int swr_sdb_show_profile( swr_sdb_id id ) {  int i;  long long int time, calls, mean;  char name[SWR_CDB_MAX_NAME_LENGTH];  char str1[TIME_STR_LEN], str2[TIME_STR_LEN];  CHECK_ID( id );  swr_cdb_get_name( ENTRY(id).context.cdb_desc->id, name );  PR_DBG( 0, "Profile for %s(%i):\n", name, id );  for ( i=0; i<=profiling_total; i++ ) {    swr_sdb_get_profile( id, i, &time, &calls );    mean = calls?time/calls:time;    PR_DBG( 0, "%s: %s / %6lli[calls] = %s per %s\n",            swr_profile_name[i], disp_time( str1, time ), calls,            disp_time( str2, mean ), swr_profile_name[i] );  }  return 0;}//----------------------------------------------------------------------// Initialisation and Freeing//----------------------------------------------------------------------int sdb_init( void ) {  int i;  curr_sdb_id = 2;  sdb_table = swr_malloc( sizeof( sdb_t )                          * MAX_SUBSYSTEMS );  if ( !sdb_table )    return -1;  for ( i=0; i < MAX_SUBSYSTEMS; i++ ) {    sdb_table[i].context.id = -1;  }  // This mutex is NOT spinlock  pthread_mutex_init( &mutex_table, NULL );  return 0;}void sdb_cleanup( void ) {  pthread_mutex_destroy( &mutex_table );  if ( sdb_table ) {    swr_free( sdb_table );  } else {    PR_DBG( 0, "Error while freeing sdb_table\n" );  }}/** * This function is called when the module is loaded */int swr_sdb_init(void) {  if ( sdb_init() < 0 )    goto setup_conn_table_failed;  PR_DBG( 2, "%i subsystems initialised\n", MAX_SUBSYSTEMS );  if ( swr_conn_init() )    goto setup_conn_failed;  return 0;setup_conn_failed:  swr_free( sdb_table );setup_conn_table_failed:  PR_DBG( 0, "Subsystem init failed\n" );  return 1;}/** * This function is called when the module is unloaded. */void swr_sdb_cleanup(void) {  swr_conn_cleanup();  sdb_cleanup();  PR_DBG( 2, "Subsystems cleaned up\n" );}/** * Kernel macros which define the initialization and finalization * function. */module_init(swr_sdb_init);module_exit(swr_sdb_cleanup);/** * The following symbols are exported: */EXPORT_SYMBOL(swr_sdb_spm);EXPORT_SYMBOL(swr_sdb_send_msg);EXPORT_SYMBOL(swr_sdb_instantiate_id);EXPORT_SYMBOL(swr_sdb_instantiate_name);EXPORT_SYMBOL(swr_sdb_destroy);EXPORT_SYMBOL(swr_sdb_call_module);EXPORT_SYMBOL(swr_sdb_list);EXPORT_SYMBOL(swr_sdb_get_struct);EXPORT_SYMBOL(swr_sdb_get_config_struct);EXPORT_SYMBOL(swr_sdb_get_stats_struct);EXPORT_SYMBOL(swr_sdb_free_config_struct);EXPORT_SYMBOL(swr_sdb_free_stats_struct);EXPORT_SYMBOL(swr_sdb_get_config_parameter_nbr);EXPORT_SYMBOL(swr_sdb_set_config_parameter_value);EXPORT_SYMBOL(swr_sdb_get_config_parameter_value);EXPORT_SYMBOL(swr_sdb_get_config_parameter_type);EXPORT_SYMBOL(swr_sdb_get_stats_parameter_nbr);EXPORT_SYMBOL(swr_sdb_set_stats_parameter_value);EXPORT_SYMBOL(swr_sdb_get_stats_parameter_value);EXPORT_SYMBOL(swr_sdb_get_stats_parameter_type);EXPORT_SYMBOL(swr_sdb_get_output_port_data);EXPORT_SYMBOL(swr_sdb_get_profile);EXPORT_SYMBOL(swr_sdb_show_profile);EXPORT_SYMBOL(swr_sdb_clear_profile);EXPORT_SYMBOL(swr_sdb_get_input_port_size);EXPORT_SYMBOL(swr_sdb_get_output_port_size);EXPORT_SYMBOL(swr_stats_track);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -