示例#1
0
文件: main.c 项目: rrader/system-sw
int main(int argc, char *argv[]) {
    srand(time(NULL));
    read_args(argc, argv);

    alc_init(amount);
    printf("\n");
    mem_dump();
    printf("\n");

    if (test) {
        test_mem();
    }

    if (stats) {
        get_stats();
    }
}
示例#2
0
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
{
    (void)lpReserved;

    // Perform actions based on the reason for calling.
    switch(ul_reason_for_call)
    {
        case DLL_PROCESS_ATTACH:
            DisableThreadLibraryCalls(hModule);
            alc_init();
            break;

        case DLL_PROCESS_DETACH:
            alc_deinit();
            break;
    }
    return TRUE;
}
示例#3
0
int open_alc_session(alc_arguments_t *a) {

  alc_session_t *s;
  int i;
  int retval;
  struct timeb timeb_current_time;
  
#if ABSOLUTE_PATH
  char fullpath[MAX_PATH_LENGTH];
#endif

  lock_session();
  
  if(!lib_init) {
    alc_init();
    /* alc session list initialization */
    memset(alc_session_list, 0, MAX_ALC_SESSIONS * sizeof(alc_session_t*));
  }
  
  if(nb_alc_session >= MAX_ALC_SESSIONS) {
    /* Could not create new alc session */
    printf("Could not create new alc session: too many sessions!\n");
    unlock_session();
    return -1;
  }
  
  if (!(s = (alc_session_t*)calloc(1, sizeof(alc_session_t)))) {
    printf("Could not alloc memory for alc session!\n");
    unlock_session();
    return -1;
  }

  memset(s, 0, sizeof(alc_session_t));

  s->mode = a->mode;
  s->tsi = a->tsi;
  s->state = SActive;
  s->addr_family = a->addr_family;
  s->addr_type = a->addr_type;
  s->cc_id = a->cc_id;
  
  if(s->cc_id == RLC) {
    retval = init_mad_rlc(s);
    
    if(retval < 0) {
      unlock_session();
      return retval;
    }
  }
  
  s->rx_memory_mode = a->rx_memory_mode;
  s->verbosity = a->verbosity;
  s->starttime = a->start_time;
  s->stoptime = a->stop_time;
  s->simul_losses = a->simul_losses;
  s->loss_ratio1 = a->loss_ratio1;
  s->loss_ratio2 = a->loss_ratio2;
  
  if(s->mode == SENDER) {

    ftime(&timeb_current_time);
	s->ftimestarttime = timeb_current_time.time+timeb_current_time.millitm/1000.0;

    memcpy(s->base_dir, a->base_dir, strlen(a->base_dir));
    
    s->nb_channel = 0;
    s->max_channel = a->nb_channel;
    s->def_fec_ratio = a->fec_ratio; 
    s->sent_bytes = 0;
    s->obj_sent_bytes = 0;
    s->last_print_tx_percent = 0;
    s->a_flag = 0;
    s->fdt_instance_id = 0; /*uplimit 16777215;*/
    s->def_ttl = a->ttl;
    s->def_fec_enc_id = a->fec_enc_id;
    s->def_fec_inst_id = a->fec_inst_id;
    s->def_max_sblen = a->max_sb_len;
    s->def_eslen = a->es_len;
    s->use_fec_oti_ext_hdr = a->use_fec_oti_ext_hdr;
    s->def_tx_rate = a->tx_rate;
    s->tx_queue_begin = NULL;
    s->tx_queue_end = NULL;
    s->tx_queue_size = 0;
    s->first_unit_in_loop = TRUE;
    s->nb_ready_channel = 0;
    s->nb_sending_channel = 0;
    s->half_word = a->half_word;
    s->encode_content = a->encode_content;
    s->optimize_tx_rate =  a->optimize_tx_rate;
    s->calculate_session_size = a->calculate_session_size;

    if(((s->cc_id == RLC) || ((s->cc_id == Null) && (s->max_channel != 1)))) {

      /**** Start tx_thread ****/
      
#ifdef _MSC_VER
      s->handle_tx_thread = (HANDLE)_beginthreadex(NULL, 0, (void*)tx_thread, (void*)s, 0, &s->tx_thread_id);

      if(s->handle_tx_thread == NULL) {
	perror("open_alc_session: _beginthread");
	unlock_session();
	return -1;
      }
#else
      if(pthread_create(&s->tx_thread_id, NULL, tx_thread, (void*)s) != 0) {
	perror("open_alc_session: pthread_create");
	unlock_session();
	return -1;
      }
#endif
    }
  }
  
  if(s->mode == RECEIVER) {
    
#ifdef SSM
    s->ssm = a->use_ssm;
#endif

#if ABSOLUTE_PATH    
#ifdef _MSC_VER
    memset(fullpath, 0, MAX_PATH_LENGTH);
    
    if(_fullpath(fullpath, a->base_dir, MAX_PATH_LENGTH) != NULL) {
      memcpy(s->base_dir, fullpath, strlen(fullpath));
    }
    else {
      memcpy(s->base_dir, a->base_dir, strlen(a->base_dir));
    }
#else
    memset(fullpath, 0, MAX_PATH_LENGTH);
    
    if(a->base_dir[0] != '/') {
      
      if(getcwd(fullpath, MAX_PATH_LENGTH) != NULL) {
	memcpy(s->base_dir, fullpath, strlen(fullpath));
	strcat(s->base_dir, "/");
	strcat(s->base_dir, a->base_dir);
      }
      else {
	memcpy(s->base_dir, a->base_dir, strlen(a->base_dir));
      }
    }
    else {
      memcpy(s->base_dir, a->base_dir, strlen(a->base_dir));
    }
#endif
#else
	 memcpy(s->base_dir, a->base_dir, strlen(a->base_dir));
#endif

    s->nb_channel = 0;
    s->max_channel = a->nb_channel;
    s->obj_list = NULL;
    s->fdt_list = NULL;
    s->wanted_obj_list = NULL;
    s->rx_fdt_instance_list = NULL;
    s->accept_expired_fdt_inst = a->accept_expired_fdt_inst;
    
    memset(s->src_addr, 0, 40);
    
    if(a->src_addr != NULL) {
      memcpy(s->src_addr, a->src_addr, strlen(a->src_addr));
    }
    
    /* Create receiving thread */
    
#ifdef _MSC_VER
    s->handle_rx_thread =
      (HANDLE)_beginthreadex(NULL, 0, (void*)rx_thread, (void*)s, 0, &s->rx_thread_id);
    
    if(s->handle_rx_thread == NULL) {
      perror("open_alc_session: _beginthread");
      unlock_session();
      return -1;
    }
#else
    if(pthread_create(&s->rx_thread_id, NULL, rx_thread, (void*)s) != 0) {
      perror("open_alc_session: pthread_create");
      unlock_session();
      return -1;
    }
#endif
    
  }
  
  for(i = 0; i < MAX_ALC_SESSIONS; i++) {
    if(alc_session_list[i] == NULL) {
      s->s_id = i;
      alc_session_list[s->s_id] = s;
      break;
    }
  }
  
  nb_alc_session++;
  
  unlock_session();
  return s->s_id;
}