コード例 #1
0
bool DictTrie::load_dict(const char *filename, LemmaIdType start_id,
                         LemmaIdType end_id) {
  if (NULL == filename || end_id <= start_id)
    return false;

  FILE *fp = fopen(filename, "rb");
  if (NULL == fp)
    return false;

  free_resource(true);

  dict_list_ = new DictList();
  if (NULL == dict_list_) {
    fclose(fp);
    return false;
  }

  SpellingTrie &spl_trie = SpellingTrie::get_instance();
  NGram &ngram = NGram::get_instance();

  if (!spl_trie.load_spl_trie(fp) || !dict_list_->load_list(fp) ||
      !load_dict(fp) || !ngram.load_ngram(fp) ||
      total_lma_num_ > end_id - start_id + 1) {
    free_resource(true);
    fclose(fp);
    return false;
  }

  fclose(fp);
  return true;
}
コード例 #2
0
ファイル: parse_conf.c プロジェクト: razvip91/bareos
bool CONFIG::remove_resource(int type, const char *name)
{
   int rindex = type - m_r_first;
   RES *last;

   /*
    * Remove resource from list.
    *
    * Note: this is intended for removing a resource that has just been added,
    * but proven to be incorrect (added by console command "configure add").
    * For a general approach, a check if this resource is referenced by other resources must be added.
    * If it is referenced, don't remove it.
    */
   last = NULL;
   for (RES *res = m_res_head[rindex]; res; res = res->next) {
      if (bstrcmp(res->name, name)) {
         if (!last) {
            Dmsg2(900, _("removing resource %s, name=%s (first resource in list)\n"), res_to_str(type), name);
            m_res_head[rindex] = res->next;
        } else {
            Dmsg2(900, _("removing resource %s, name=%s\n"), res_to_str(type), name);
            last->next = res->next;
        }
        res->next = NULL;
        free_resource(res, type);
        return true;
      }
      last = res;
   }

   /*
    * Resource with this name not found
    */
   return false;
}
コード例 #3
0
ファイル: parse_conf.c プロジェクト: halgandd/bacula
void free_config_resources()
{
   for (int i=r_first; i<=r_last; i++) {
      free_resource(res_head[i-r_first], i);
      res_head[i-r_first] = NULL;
   }
}
コード例 #4
0
ファイル: parse_conf.c プロジェクト: halgandd/bacula
/*********************************************************************
 *
 *      Free configuration resources
 *
 */
void CONFIG::free_resources()
{
   for (int i=m_r_first; i<=m_r_last; i++) {
      free_resource(m_res_head[i-m_r_first], i);
      m_res_head[i-m_r_first] = NULL;
   }
}
コード例 #5
0
ファイル: utils.hpp プロジェクト: Dushistov/sdcv
 void reset(T *newp)
 {
     if (p_ != newp) {
         free_resource();
         p_ = newp;
     }
 }
コード例 #6
0
ファイル: proxy.c プロジェクト: Windeal/improxy
static void sig_term_handler()
{
    if (pid_file[0] != 0)
        unlink(pid_file);
    free_resource();
    exit(1);
}
コード例 #7
0
ファイル: dictlist.cpp プロジェクト: SmartisanTech/Wrench
bool DictList::load_list(FILE *fp) {
  if (NULL == fp)
    return false;

  initialized_ = false;

  if (fread(&scis_num_, sizeof(uint32), 1, fp) != 1)
    return false;

  if (fread(start_pos_, sizeof(uint32), kMaxLemmaSize + 1, fp) !=
      kMaxLemmaSize + 1)
    return false;

  if (fread(start_id_, sizeof(uint32), kMaxLemmaSize + 1, fp) !=
      kMaxLemmaSize + 1)
    return false;

  free_resource();

  if (!alloc_resource(start_pos_[kMaxLemmaSize], scis_num_))
    return false;

  if (fread(scis_hz_, sizeof(char16), scis_num_, fp) != scis_num_)
    return false;

  if (fread(scis_splid_, sizeof(SpellingId), scis_num_, fp) != scis_num_)
    return false;

  if (fread(buf_, sizeof(char16), start_pos_[kMaxLemmaSize], fp) !=
      start_pos_[kMaxLemmaSize])
    return false;

  initialized_ = true;
  return true;
}
コード例 #8
0
static void amdgpu_cs_vce_destroy(void)
{
	int len, r;

	num_resources  = 0;
	alloc_resource(&enc.fb[0], 4096, AMDGPU_GEM_DOMAIN_GTT);
	resources[num_resources++] = enc.fb[0].handle;
	resources[num_resources++] = ib_handle;

	len = 0;
	memcpy(ib_cpu, vce_session, sizeof(vce_session));
	len += sizeof(vce_session) / 4;
	memcpy((ib_cpu + len), vce_taskinfo, sizeof(vce_taskinfo));
	ib_cpu[len + 3] = 1;
	len += sizeof(vce_taskinfo) / 4;
	memcpy((ib_cpu + len), vce_feedback, sizeof(vce_feedback));
	ib_cpu[len + 2] = enc.fb[0].addr >> 32;
	ib_cpu[len + 3] = enc.fb[0].addr;
	len += sizeof(vce_feedback) / 4;
	memcpy((ib_cpu + len), vce_destroy, sizeof(vce_destroy));
	len += sizeof(vce_destroy) / 4;

	r = submit(len, AMDGPU_HW_IP_VCE);
	CU_ASSERT_EQUAL(r, 0);

	free_resource(&enc.fb[0]);
}
コード例 #9
0
bool DictTrie::build_dict(const char* fn_raw, const char* fn_validhzs) {
  DictBuilder* dict_builder = new DictBuilder();

  free_resource(true);

  return dict_builder->build_dict(fn_raw, fn_validhzs, this);
}
コード例 #10
0
ファイル: tray_conf.cpp プロジェクト: eneuhauss/bareos
/*
 * Free memory of resource -- called when daemon terminates.
 * NB, we don't need to worry about freeing any references
 * to other resources as they will be freed when that
 * resource chain is traversed.  Mainly we worry about freeing
 * allocated strings (names).
 */
void free_resource(RES *sres, int type)
{
   RES *nres; /* next resource if linked */
   URES *res = (URES *)sres;

   if (res == NULL)
      return;

   /*
    * Common stuff -- free the resource name and description
    */
   nres = (RES *)res->res_monitor.hdr.next;
   if (res->res_monitor.hdr.name) {
      free(res->res_monitor.hdr.name);
   }
   if (res->res_monitor.hdr.desc) {
      free(res->res_monitor.hdr.desc);
   }

   switch (type) {
   case R_MONITOR:
      break;
   case R_CLIENT:
      if (res->res_client.address) {
         free(res->res_client.address);
      }
      if (res->res_client.password) {
         free(res->res_client.password);
      }
      break;
   case R_STORAGE:
      if (res->res_store.address) {
         free(res->res_store.address);
      }
      if (res->res_store.password) {
         free(res->res_store.password);
      }
      break;
   case R_CONSOLE_FONT:
      if (res->con_font.fontface) {
         free(res->con_font.fontface);
      }
      break;
   default:
      printf(_("Unknown resource type %d in free_resource.\n"), type);
   }

   /*
    * Common stuff again -- free the resource, recurse to next one
    */
   if (res) {
      free(res);
   }
   if (nres) {
      free_resource(nres, type);
   }
}
コード例 #11
0
 void move_to_this(DumbArray &that) noexcept {
     if (this != &that) {
         free_resource();
     }
     array_ = that.array_;
     size_ = that.size_;
     that.array_ = nullptr;
     that.size_ = 0;
 }
コード例 #12
0
ファイル: roadmap_res.c プロジェクト: NoamSheffer/WazeWP7
static int roadmap_res_cache_add( RoadMapResource* res, int hash_key )
{
	ResCacheEntry* cache = res->cache;
	int slot;


	/*
	 * If there is still available slots just add
	 */

	if ( res->count < RES_CACHE_SIZE  )
	{
		slot = res->count;
		res->count++;
	}
	else
	{
#ifdef ANDROID
	   roadmap_log( ROADMAP_ERROR, "Exceeding cache entries number %d!!!", RES_CACHE_SIZE );
#endif
	    /*
	     * Remove and deallocate the LRU element in the cache
	     */
		int non_locked_lru = cache[res->cache_head].prev;
		while ( res->slots[non_locked_lru].flags & RES_LOCK )
		{
			non_locked_lru = cache[non_locked_lru].prev;
		} 
		if ( non_locked_lru == res->cache_head )
		{
			roadmap_log( ROADMAP_ERROR, "Cannot find non-locked resource!!! Removing the locked LRU" );
			non_locked_lru = cache[res->cache_head].prev;
			dbg_cache( res, non_locked_lru, "" );
		}

		slot = non_locked_lru;

		roadmap_hash_remove( res->hash, cache[slot].key, slot );
		free_resource( res, slot );
	}

	cache[slot].key = hash_key;
	roadmap_hash_add( res->hash, hash_key, slot );

	/*
	 * Set the element to be MRU
	 */
	if ( res->count > 1 )
	{
		/* For the only element nothing to do */
		roadmap_res_cache_set_MRU( res, slot );
	}
	return slot;
}
コード例 #13
0
adb_ncDescribeResourceResponse_t* ncDescribeResourceMarshal (adb_ncDescribeResource_t* ncDescribeResource, const axutil_env_t *env)
{
    pthread_mutex_lock(&ncHandlerLock);
    adb_ncDescribeResourceType_t * input          = adb_ncDescribeResource_get_ncDescribeResource(ncDescribeResource, env);
    adb_ncDescribeResourceResponse_t * response   = adb_ncDescribeResourceResponse_create(env);
    adb_ncDescribeResourceResponseType_t * output = adb_ncDescribeResourceResponseType_create(env);

    // get standard fields from input
    axis2_char_t * correlationId = adb_ncDescribeResourceType_get_correlationId(input, env);
    axis2_char_t * userId = adb_ncDescribeResourceType_get_userId(input, env);

    // get operation-specific fields from input
    axis2_char_t * resourceType = adb_ncDescribeResourceType_get_resourceType(input, env);

    eventlog("NC", userId, correlationId, "DescribeResource", "begin");
    { // do it
        ncMetadata meta = { correlationId, userId };
        ncResource * outRes;

        int error = doDescribeResource (&meta, resourceType, &outRes);
    
        if (error) {
            logprintfl (EUCAERROR, "ERROR: doDescribeResource() failed error=%d\n", error);
            adb_ncDescribeResourceResponseType_set_return(output, env, AXIS2_FALSE);

        } else {
            // set standard fields in output
            adb_ncDescribeResourceResponseType_set_return(output, env, AXIS2_TRUE);
            adb_ncDescribeResourceResponseType_set_correlationId(output, env, correlationId);
            adb_ncDescribeResourceResponseType_set_userId(output, env, userId);

            // set operation-specific fields in output
            adb_ncDescribeResourceResponseType_set_nodeStatus(output, env, outRes->nodeStatus);
            adb_ncDescribeResourceResponseType_set_memorySizeMax(output, env, outRes->memorySizeMax);
            adb_ncDescribeResourceResponseType_set_memorySizeAvailable(output, env, outRes->memorySizeAvailable);
            adb_ncDescribeResourceResponseType_set_diskSizeMax(output, env, outRes->diskSizeMax);
            adb_ncDescribeResourceResponseType_set_diskSizeAvailable(output, env, outRes->diskSizeAvailable);
            adb_ncDescribeResourceResponseType_set_numberOfCoresMax(output, env, outRes->numberOfCoresMax);
            adb_ncDescribeResourceResponseType_set_numberOfCoresAvailable(output, env, outRes->numberOfCoresAvailable);
            adb_ncDescribeResourceResponseType_set_publicSubnets(output, env, outRes->publicSubnets);
            free_resource ( &outRes);
            
        }
    }
    // set response to output
    adb_ncDescribeResourceResponse_set_ncDescribeResourceResponse(response, env, output);
    pthread_mutex_unlock(&ncHandlerLock);
    
    eventlog("NC", userId, correlationId, "DescribeResource", "end");
    return response;
}
コード例 #14
0
bool DictTrie::load_dict_fd(int sys_fd, long start_offset,
                            long length, LemmaIdType start_id,
                            LemmaIdType end_id) {
  if (start_offset < 0 || length <= 0 || end_id <= start_id)
    return false;

  FILE *fp = fdopen(sys_fd, "rb");
  if (NULL == fp)
    return false;

  if (-1 == fseek(fp, start_offset, SEEK_SET)) {
    fclose(fp);
    return false;
  }

  free_resource(true);

  dict_list_ = new DictList();
  if (NULL == dict_list_) {
    fclose(fp);
    return false;
  }

  SpellingTrie &spl_trie = SpellingTrie::get_instance();
  NGram &ngram = NGram::get_instance();

  if (!spl_trie.load_spl_trie(fp) || !dict_list_->load_list(fp) ||
      !load_dict(fp) || !ngram.load_ngram(fp) ||
      ftell(fp) < start_offset + length ||
      total_lma_num_ > end_id - start_id + 1) {
    free_resource(true);
    fclose(fp);
    return false;
  }

  fclose(fp);
  return true;
}
コード例 #15
0
/*
 *
 * free_resource_list - free a resource list
 *
 *   reslist - the reslist to free
 *
 * returns nothing
 *
 */
void free_resource_list(resource *res_list)
  {
  resource *tmp; /* temporary next resource holder */
  resource *res; /* current resource to free */

  res = res_list;

  while (res != NULL)
    {
    tmp = res -> next;
    free_resource(res);
    res = tmp;
    }
  }
コード例 #16
0
void WIPResourceManager::free_all()
{
    ResHandler* handler;
    file2ptr_map::iterator it;
    for (it = _map.begin(); it != _map.end(); ++it)
    {
        handler = it->second;
        free_resource(handler);
        //::free(it->second);
    }
    _map.clear();
    _ref.clear();

}
コード例 #17
0
ファイル: bat_conf.cpp プロジェクト: dl5rcw/bareos
/*
 * Free memory of resource.
 * NB, we don't need to worry about freeing any references
 * to other resources as they will be freed when that
 * resource chain is traversed.  Mainly we worry about freeing
 * allocated strings (names).
 */
void free_resource(RES *sres, int type)
{
   RES *nres;
   URES *res = (URES *)sres;

   if (res == NULL)
      return;

   /*
    * Common stuff -- free the resource name
    */
   nres = (RES *)res->dir_res.hdr.next;
   if (res->dir_res.hdr.name) {
      free(res->dir_res.hdr.name);
   }
   if (res->dir_res.hdr.desc) {
      free(res->dir_res.hdr.desc);
   }

   switch (type) {
   case R_DIRECTOR:
      if (res->dir_res.address) {
         free(res->dir_res.address);
      }
      free_tls_t(res->dir_res.tls);
      break;
   case R_CONSOLE:
      if (res->con_res.password.value) {
         free(res->con_res.password.value);
      }
      free_tls_t(res->con_res.tls);
      break;
   case R_CONSOLE_FONT:
      if (res->con_font.fontface) {
         free(res->con_font.fontface);
      }
      break;
   default:
      printf(_("Unknown resource type %d\n"), type);
   }
   /*
    * Common stuff again -- free the resource, recurse to next one
    */
   free(res);
   if (nres) {
      free_resource(nres, type);
   }
}
コード例 #18
0
ファイル: dird.c プロジェクト: AlD/bareos
static void free_saved_resources(int table)
{
   int num = my_config->m_r_last - my_config->m_r_first + 1;
   RES **res_tab = reload_table[table].res_table;

   if (!res_tab) {
      Dmsg1(100, "res_tab for table %d already released.\n", table);
      return;
   }
   Dmsg1(100, "Freeing resources for table %d\n", table);
   for (int j=0; j<num; j++) {
      free_resource(res_tab[j], my_config->m_r_first + j);
   }
   free(res_tab);
   reload_table[table].job_count = 0;
   reload_table[table].res_table = NULL;
}
コード例 #19
0
ファイル: roadmap_res.c プロジェクト: NoamSheffer/WazeWP7
void roadmap_res_shutdown ()
{
   int type;
   RoadMapResource *res;
   int i;
   for ( type=0; type<MAX_RESOURCES; type++ )
   {
      res = &Resources[type];
      for ( i=0; i<Resources[type].count; i++ )
      {
         free_resource ( res, i );
      }
      Resources[type].count = 0;
      if ( Resources[type].hash != NULL )
      {
    	  roadmap_hash_free( Resources[type].hash );
      }
   }
}
コード例 #20
0
ファイル: console_conf.c プロジェクト: gearsforwork/bareos
/*
 * Free memory of resource.
 * NB, we don't need to worry about freeing any references
 * to other resources as they will be freed when that
 * resource chain is traversed.  Mainly we worry about freeing
 * allocated strings (names).
 */
void free_resource(RES *sres, int type)
{
   RES *nres;
   URES *res = (URES *)sres;

   if (res == NULL)
      return;

   /* common stuff -- free the resource name */
   nres = (RES *)res->res_dir.hdr.next;
   if (res->res_dir.hdr.name) {
      free(res->res_dir.hdr.name);
   }
   if (res->res_dir.hdr.desc) {
      free(res->res_dir.hdr.desc);
   }

   switch (type) {
   case R_CONSOLE:
      if (res->res_cons.rc_file) {
         free(res->res_cons.rc_file);
      }
      if (res->res_cons.history_file) {
         free(res->res_cons.history_file);
      }
      free_tls_t(res->res_cons.tls);
      break;
   case R_DIRECTOR:
      if (res->res_dir.address) {
         free(res->res_dir.address);
      }
      free_tls_t(res->res_dir.tls);
      break;
   default:
      printf(_("Unknown resource type %d\n"), type);
   }
   /* Common stuff again -- free the resource, recurse to next one */
   free(res);
   if (nres) {
      free_resource(nres, type);
   }
}
コード例 #21
0
/* Checks for currently running processes. Stops it if time is up, Pauses it if queue is not empty */
PcbPtr running_processes() {
	if (current_process) { // if there is a process running
		current_process->remaining_cpu_time = current_process->remaining_cpu_time -1; // decrement time
		if (current_process->remaining_cpu_time <= 0 || (current_process->processor_time - current_process->remaining_cpu_time >= 20)) { // processing time is completed
			pcb_terminate(current_process);
			if (current_process->priority > 0) { // not real time
				io_resources = free_resource(io_resources,current_process);
			}
			/* Free memory relating to the finished process*/
			if (current_process->priority != 0) {
				memFree(current_process->memory);
			}
			pcb_free(current_process);
			current_process = NULL;
		}
		else if (realtime_queue || p1_queue || p2_queue || p3_queue){ // suspend and enqueue process back to roundrobin if other waiting processes
			if (current_process->priority == 0) { //real time process
				return current_process;
			}
			current_process = pcb_suspend(current_process);
			if (current_process-> priority < 3 && current_process->priority != 0){ // reduce priority
				current_process->priority = current_process->priority +1 ;
			}
			switch (current_process->priority) {
				case 1:
					p1_queue = pcb_enqueue(p1_queue,current_process);
					break;
				case 2:
					p2_queue = pcb_enqueue(p2_queue,current_process);
					break;
				case 3:
					p3_queue = pcb_enqueue(p3_queue,current_process);
					break;
				default:
					fprintf(stderr, "Error. Priority is out of bounds\n");
			}
			current_process = NULL;
		}
	}
	return current_process;
}
コード例 #22
0
int WIPResourceManager::free(ResHandler* file, int size)
{
    //remove_ref(file);
    if (file == NULL)
        return SUCC_RELEASE;
    int ret = FAIL;
    unsigned int & ref_num = file->nref;
    if (ref_num>0)
    {
        ref_num--;
        ret = SUCC_SUB;
    }
    if (ref_num <= 0)
    {

        _map.erase(file->file_name);
        free_resource(file);
        ret = SUCC_RELEASE;
    }
    return ret;
}
コード例 #23
0
ファイル: parse_conf.c プロジェクト: razvip91/bareos
void CONFIG::free_resources()
{
   for (int i = m_r_first; i<= m_r_last; i++) {
      free_resource(m_res_head[i-m_r_first], i);
      m_res_head[i-m_r_first] = NULL;
   }

   if (m_config_default_filename) {
      free((void *)m_config_default_filename);
   }

   if (m_config_dir) {
      free((void *)m_config_dir);
   }

   if (m_config_include_dir) {
      free((void *)m_config_include_dir);
   }

   if (m_used_config_path) {
      free((void *)m_used_config_path);
   }

}
コード例 #24
0
static void amdgpu_cs_vce_encode(void)
{
	uint32_t vbuf_size, bs_size = 0x154000, cpb_size;
	int r;

	vbuf_size = enc.width * enc.height * 1.5;
	cpb_size = vbuf_size * 10;
	num_resources = 0;
	alloc_resource(&enc.fb[0], 4096, AMDGPU_GEM_DOMAIN_GTT);
	resources[num_resources++] = enc.fb[0].handle;
	alloc_resource(&enc.fb[1], 4096, AMDGPU_GEM_DOMAIN_GTT);
	resources[num_resources++] = enc.fb[1].handle;
	alloc_resource(&enc.bs[0], bs_size, AMDGPU_GEM_DOMAIN_GTT);
	resources[num_resources++] = enc.bs[0].handle;
	alloc_resource(&enc.bs[1], bs_size, AMDGPU_GEM_DOMAIN_GTT);
	resources[num_resources++] = enc.bs[1].handle;
	alloc_resource(&enc.vbuf, vbuf_size, AMDGPU_GEM_DOMAIN_VRAM);
	resources[num_resources++] = enc.vbuf.handle;
	alloc_resource(&enc.cpb, cpb_size, AMDGPU_GEM_DOMAIN_VRAM);
	resources[num_resources++] = enc.cpb.handle;
	resources[num_resources++] = ib_handle;

	r = amdgpu_bo_cpu_map(enc.vbuf.handle, (void **)&enc.vbuf.ptr);
	CU_ASSERT_EQUAL(r, 0);
	memcpy(enc.vbuf.ptr, frame, sizeof(frame));
	r = amdgpu_bo_cpu_unmap(enc.vbuf.handle);
	CU_ASSERT_EQUAL(r, 0);

	amdgpu_cs_vce_config();

	if (family_id >= AMDGPU_FAMILY_VI) {
		vce_taskinfo[3] = 3;
		amdgpu_cs_vce_encode_idr(&enc);
		amdgpu_cs_vce_encode_p(&enc);
		check_result(&enc);

		/* two pipes */
		vce_encode[16] = 0;
		amdgpu_cs_vce_encode_idr(&enc);
		amdgpu_cs_vce_encode_p(&enc);
		check_result(&enc);

		/* two instances */
		enc.two_instance = true;
		vce_taskinfo[2] = 0x83;
		vce_taskinfo[4] = 1;
		amdgpu_cs_vce_encode_idr(&enc);
		vce_taskinfo[2] = 0xffffffff;
		vce_taskinfo[4] = 2;
		amdgpu_cs_vce_encode_p(&enc);
		check_result(&enc);
	} else {
		vce_taskinfo[3] = 3;
		vce_encode[16] = 0;
		amdgpu_cs_vce_encode_idr(&enc);
		amdgpu_cs_vce_encode_p(&enc);
		check_result(&enc);
	}

	free_resource(&enc.fb[0]);
	free_resource(&enc.fb[1]);
	free_resource(&enc.bs[0]);
	free_resource(&enc.bs[1]);
	free_resource(&enc.vbuf);
	free_resource(&enc.cpb);
}
コード例 #25
0
ファイル: dictlist.cpp プロジェクト: SmartisanTech/Wrench
DictList::~DictList() {
  free_resource();
}
コード例 #26
0
 ~DumbArray() {
     std::cout << "dtor: " << this << std::endl;
     free_resource();
 }
コード例 #27
0
ファイル: proxy.c プロジェクト: Windeal/improxy
int main(int argc, char *argv[])
{
    int opt = 10, pid = 0;
    char    config[1024] = {0};
    int log_level = 0;
    FILE *pidfp;

    memset(&mproxy, 0, sizeof(mcast_proxy));

    mproxy.print_level = LOG_PRI_ERROR;
    mproxy.syslog_level = LOG_PRI_ERROR;

    while((opt = getopt(argc, argv, "c:d:vp:h")) > 0)
    {
        switch (opt) {
            case 'c':
                IMP_LOG_DEBUG("config file is %s\n", optarg);
                strcpy(config, optarg);
                break;
            case 'p':
                IMP_LOG_DEBUG("pid file is %s\n", optarg);
                strcpy(pid_file, optarg);
                break;
            case 'd':
                /*to do log*/
                log_level = atoi(optarg);
                if(log_level < 0) {
                    IMP_LOG_DEBUG("log level must be greater than 0\n");
                    exit(1);
                }
                if(log_level > LOG_PRI_LOWEST)
                    log_level = LOG_PRI_DEBUG;
                mproxy.print_level = log_level;
                IMP_LOG_DEBUG("logLevel = %d\n", log_level);
                break;
            case 'v':
                printf("version: %s\n", IMP_VERSION);
                exit(1);
            case 'h':
                show_usage();
            default:
                show_usage();
        }

    }

    if(config[0] == 0) {

       show_usage();
    }

    /* dump current PID */
    pid = getpid();
    if ((pidfp = fopen(pid_file, "w")) != NULL) {
        fprintf(pidfp, "%d\n", pid);
        fclose(pidfp);
    }
    atexit(free_resource);
    signal(SIGTERM, sig_term_handler);
    signal(SIGINT, sig_term_handler);
    signal(SIGUSR1, sig_usr1_handler);

    imp_interface_init();
    imp_init_timer();
    imp_membership_db_init();


    if (load_config(config) == STATUS_NOK ||
        init_interface(&mproxy) == STATUS_NOK ||
        init_mproxy4(&mproxy) == STATUS_NOK ||
        init_mproxy6(&mproxy) == STATUS_NOK) {

        IMP_LOG_ERROR("exiting.........\n");
        free_resource();
        exit(1);
    }
    add_all_vif();
    init_timer(&mproxy);


    while(1)
    {
        struct timeval* tm;
        fd_set  fdset;
        int max = 0;
        int resval = 0;
        FD_ZERO(&fdset);
        if(mproxy.igmp_socket > 0)
            FD_SET(mproxy.igmp_socket, &fdset);

#ifdef ENABLE_IMP_MLD
        if(mproxy.mld_socket > 0)
            FD_SET(mproxy.mld_socket, &fdset);

        max = mproxy.igmp_socket > mproxy.mld_socket ?
                mproxy.igmp_socket:mproxy.mld_socket;
#else
        max = mproxy.igmp_socket;
#endif
        tm = imp_check_timer();

        resval = select(max + 1, &fdset, NULL, NULL, tm);
        if(resval == -1)
        {
            perror(__FUNCTION__);
        }else if(resval)
            IMP_LOG_DEBUG("Data arrive\n");
        else
            IMP_LOG_DEBUG("timeout\n");

        if(mproxy.igmp_socket > 0 &&
            FD_ISSET(mproxy.igmp_socket, &fdset)) {

            mcast_recv_igmp(mproxy.igmp_socket, mproxy.igmp_version);
        }
#ifdef ENABLE_IMP_MLD
        if (mproxy.mld_socket > 0 &&
            FD_ISSET(mproxy.mld_socket, &fdset)) {

            mcast_recv_mld(mproxy.mld_socket, mproxy.mld_version);
        }
#endif
    }

    free_resource();
    del_all_vif();
    k_stop4_mproxy(mproxy.igmp_socket);
    k_stop6_mproxy(mproxy.mld_socket);
}
コード例 #28
0
ファイル: resource.hpp プロジェクト: 2php/stardict-3
 ~ResourceWrapper() { free_resource(); }
コード例 #29
0
bool DictTrie::load_dict(FILE *fp) {
  if (NULL == fp)
    return false;

  if (fread(&lma_node_num_le0_, sizeof(size_t), 1, fp) != 1)
    return false;

  if (fread(&lma_node_num_ge1_, sizeof(size_t), 1, fp) != 1)
    return false;

  if (fread(&lma_idx_buf_len_, sizeof(size_t), 1, fp) != 1)
    return false;

  if (fread(&top_lmas_num_, sizeof(size_t), 1, fp) != 1 ||
      top_lmas_num_ >= lma_idx_buf_len_)
    return false;

  free_resource(false);

  root_ = static_cast<LmaNodeLE0*>
          (malloc(lma_node_num_le0_ * sizeof(LmaNodeLE0)));
  nodes_ge1_ = static_cast<LmaNodeGE1*>
               (malloc(lma_node_num_ge1_ * sizeof(LmaNodeGE1)));
  lma_idx_buf_ = (unsigned char*)malloc(lma_idx_buf_len_);
  total_lma_num_ = lma_idx_buf_len_ / kLemmaIdSize;

  size_t buf_size = SpellingTrie::get_instance().get_spelling_num() + 1;
  assert(lma_node_num_le0_ <= buf_size);
  splid_le0_index_ = static_cast<uint16*>(malloc(buf_size * sizeof(uint16)));

  // Init the space for parsing.
  parsing_marks_ = new ParsingMark[kMaxParsingMark];
  mile_stones_ = new MileStone[kMaxMileStone];
  reset_milestones(0, kFirstValidMileStoneHandle);

  if (NULL == root_ || NULL == nodes_ge1_ || NULL == lma_idx_buf_ ||
      NULL == splid_le0_index_ || NULL == parsing_marks_ ||
      NULL == mile_stones_) {
    free_resource(false);
    return false;
  }

  if (fread(root_, sizeof(LmaNodeLE0), lma_node_num_le0_, fp)
      != lma_node_num_le0_)
    return false;

  if (fread(nodes_ge1_, sizeof(LmaNodeGE1), lma_node_num_ge1_, fp)
      != lma_node_num_ge1_)
    return false;

  if (fread(lma_idx_buf_, sizeof(unsigned char), lma_idx_buf_len_, fp) !=
      lma_idx_buf_len_)
    return false;

  // The quick index for the first level sons
  uint16 last_splid = kFullSplIdStart;
  size_t last_pos = 0;
  for (size_t i = 1; i < lma_node_num_le0_; i++) {
    for (uint16 splid = last_splid; splid < root_[i].spl_idx; splid++)
      splid_le0_index_[splid - kFullSplIdStart] = last_pos;

    splid_le0_index_[root_[i].spl_idx - kFullSplIdStart] =
        static_cast<uint16>(i);
    last_splid = root_[i].spl_idx;
    last_pos = i;
  }

  for (uint16 splid = last_splid + 1;
       splid < buf_size + kFullSplIdStart; splid++) {
    assert(static_cast<size_t>(splid - kFullSplIdStart) < buf_size);
    splid_le0_index_[splid - kFullSplIdStart] = last_pos + 1;
  }

  return true;
}
コード例 #30
0
DictTrie::~DictTrie() {
  free_resource(true);
}