Example #1
0
int perf_mon_here(int id, int status)
{
	// here, we assume id is the index of array for efficiency.
	mon_point_p p_point = &g_mon.mon_points[id];
	mon_time_p p_cur = p_point->p_cur;

	switch (status) {
		case ST_START: // start
			gettimeofday(&p_cur->tb, NULL);
			p_cur->status |= ST_START;
			break;

		case ST_END:
			gettimeofday(&p_cur->te, NULL);
			p_cur->status |= ST_END;
			if (!p_cur->p_next) {
				p_cur->p_next = linklist_create(p_point->size/2 + 1, sizeof(mon_time_t));
				p_point->size += p_point->size/2 + 1;
			}
			p_point->p_cur = p_cur->p_next;
			break;

		default:
			return -1;
	}

	return 0;
}
Example #2
0
int main()
{
    linklist H1, H2;
    int a[][2] = {{5, 0}, {2, 1}, {9, 4}, {3, 16}, {8, 8}, {-30, 27}};
    int b[][2] = {{23, 16}, {6, 1}, {-8, 8}, {11, 11}, {25, 25}, {27, 27}};
    int i, j;
    H1 = linklist_create();
    H2 = linklist_create();

    for (i = 0; i < sizeof(a)/sizeof(a[0]); i++)
        linklist_insert(H1, a[i][0], a[i][1]);
            
    for (i = 0; i < sizeof(b)/sizeof(b[0]); i++)
        linklist_insert(H2, b[i][0], b[i][1]);

    linklist_show(H1);
    printf("\n");
    linklist_show(H2);

    printf("******\n");
    linklist_union(H1, H2);
    linklist_show(H1);
    return 0;
}
Example #3
0
void cis_init (void)
{
	static char initd = 0;
	
	if (initd == 1)
		fprintf(stderr,"You attempted to initalize the library twice!\n");
	
	srand(time(0));
	memset(connections,0,sizeof(connections));
	
	cis_init_events();
	cis_init_modules();
	
	reaper_list = linklist_create();
	
	initd = 1;
}
Example #4
0
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  delay_table_add
 *  Description:  add msg to delay table
 * =====================================================================================
 */
void delay_table_add(uint64_t key,struct receiver_msg_st *msg){
	linklist *msg_list=NULL;
	struct receiver_msg_st *cmsg = NULL;
	lnodeptr pnode=NULL;

	delay_table_delete_obsolete(key);	
	msg_list =(linklist *)hash_find(table,key);
	cmsg = copy_message(msg);
	pnode = lnode_malloc((void *)cmsg);
	if(NULL == msg_list){
		lCount++;
		msg_list = linklist_create();
		hash_add(table,key,msg_list);
	}
	mCount++;
	linklist_append(msg_list,pnode);
	return;
}
Example #5
0
END_TEST

START_TEST(test_linklist_add)
{
	const char name[] = "krit kasemosoth";
  	const char title[] = "senior software engineer";

	struct linklist *lnk = linklist_create();

	linklist_add(lnk, (void*)name);
	fail_unless(lnk->size == 1,
		    "Failed to add a new item %s to the list\n",
		    name);
	
	linklist_add(lnk, (void*)title);
	fail_unless(lnk->size == 2,
		    "Failed to add a new item %s to the list\n",
		    name);	
	
}
Example #6
0
hash_table *hash_create(size_t size){
	size_t i =0;
	hash_table * htable  = (hash_table *)malloc(sizeof(hash_table));
	if(! htable){
		perror("cannot malloc memory!");
		logInfo(LOG_ERR,"can't malloc memory for hash table");
		exit(errno);
	}
	htable->size = size;
	htable->lists = (struct linklist **) malloc(sizeof(linklist *) *size);
	if(! htable->lists){
		perror("cannot malloc memory!");
		logInfo(LOG_ERR,"can't malloc memory for hash lists");
		exit(errno);
	}
	for(i=0;i<size;i++){
		htable->lists[i] = linklist_create();
	}
	htable->timeout = DEFAULT_TIMEOUT;
	return htable;
}
Example #7
0
int perf_mon_init(int max_point, int preset_times)
{
	int i;
	mon_point_p p_temp;

	signal(SIGUSR1, perf_statis);

	memset(&g_mon, 0x00, sizeof(perf_mon_t));

	g_mon.pid = getpid();
	g_mon.max = max_point;
	if (preset_times < 0) g_mon.max = DFT_MAX_POINT;

	_ALLOC(g_mon.mon_points, mon_point_p, sizeof(mon_point_t)*g_mon.max, -1);
	for (i = 0; i < g_mon.max; i++) {
		p_temp = &g_mon.mon_points[i];
		p_temp->size = preset_times;
		if (preset_times < 0) p_temp->size = DFT_PRESET_TIMES;
		p_temp->p_head = linklist_create(p_temp->size, sizeof(mon_time_t));
		p_temp->p_cur = p_temp->p_head;
	}

	return 0;
}