示例#1
0
/**
 *
 * Close the serial port associated with @a serialfd.
 *
 * Before the closing of the file descriptor, a command is sent to the UART
 * so that it will stop the watchdog timer. This is not necessary when
 * powering off the machine, but *is* important when the system
 * administrator has, for some reason, stopped the daemon for some kind of
 * maintenance.
 *
 * FIXME: The memory used by the linked list of events is freed. This should
 * probably be better to keep split in another function. Also, the file
 * descriptor used for syslog is closed (optional, but nice).  Perhaps the
 * function should just be renamed, instead of being split in many smaller
 * functions?
 */
static void close_serial(void)
{
	if (serialfd != 0) {
		/* Stop the watchdog timer */
		write_to_uart(0x4B);	/* 'K' */
		close(serialfd);
	}

	/* Destroy the macro timer objects */
	destroy_timer(off_timer);
	destroy_timer(on_timer);

	closelog();
}
示例#2
0
int plugin_fini(int type)
{
    switch (type)
    {
    case PROC_MAIN:
        break;
    case PROC_CONN:
        break;
    case PROC_WORK:
    {
        switch (get_work_idx())
        {
        case PROC_PROXY:
            break;
        case PROC_COLLECT:
            // 采集进程
            fini_collect();
            break;
        case PROC_COMMAND:
            fini_log_archive();
            break;
        case PROC_MYSQL:
            fini_mysql_instance();
            break;
        default:
            break;
        }
        destroy_timer();
    }
    }
    return 0;
}
void end_in_game_state( game* _pGame )
{
    destroy_top_bar( ((in_game_state*)_pGame->p_current_state)->p_top_bar );

    unload_image( ((in_game_state*)_pGame->p_current_state)->p_esc_menu_img );

    unload_button( ((in_game_state*)_pGame->p_current_state)->p_continue  );
    unload_button( ((in_game_state*)_pGame->p_current_state)->p_main_menu );
    unload_button( ((in_game_state*)_pGame->p_current_state)->p_exit      );

    destroy_map( ((in_game_state*)_pGame->p_current_state)->p_map );

    for ( int i = 0; i < ((in_game_state*)_pGame->p_current_state)->NPC_count; i++ )
        destroy_NPC( ((in_game_state*)_pGame->p_current_state)->pp_NPCs[i] );

    free( ((in_game_state*)_pGame->p_current_state)->pp_NPCs );

    destroy_player( ((in_game_state*)_pGame->p_current_state)->p_player );

    destroy_timer( ((in_game_state*)_pGame->p_current_state)->game_ended_timer );

    free( _pGame->p_current_state );

    _pGame->p_current_state = NULL;
}
示例#4
0
int  fini_service(int isparent)
{
	if (!isparent) {
		destroy_timer();
	}
	return 0;
}
示例#5
0
文件: Timer.c 项目: demilich/utility
int main(void)
{
	char arg[50];
	char tstr[200];
	int ret;
	struct timespec time;
	time.tv_sec = 0,
	time.tv_nsec= 100000000;

	init_timer(MAX_TIMER_NUM);

	id[0] = add_timer(1, timer1_cb, NULL, 0);
	printf("Register timer id[0]=%d\n", id[0]);

	id[1] = add_timer(2, timer2_cb, arg, 50);
	printf("Register timer id[1]=%d\n", id[1]);

	while (1) {
		if (call_cnt > 10) {
			break;
		}

		nanosleep(&time, NULL);
	}

	ret = destroy_timer();
	printf("main: %s destroy_timer, ret=%d\n", fmt_time(tstr), ret);
	return 0;
}
示例#6
0
文件: metrics.c 项目: CpuID/statsite
// Timer map cleanup
static int timer_delete_cb(void *data, const char *key, void *value) {
    timer_hist *t = value;
    destroy_timer(&t->tm);
    if (t->counts) free(t->counts);
    free(t);
    return 0;
}
示例#7
0
文件: timer.c 项目: a-c-m/couchnode
static void timer_callback(lcb_socket_t sock, short which, void *arg)
{
    lcb_timer_t timer = arg;
    lcb_t instance = timer->instance;

    lcb_assert(TMR_IS_ARMED(timer));
    lcb_assert(!TMR_IS_DESTROYED(timer));

    timer->state |= LCB_TIMER_S_ENTERED;

    lcb_timer_disarm(timer);
    timer->callback(timer, instance, timer->cookie);

    if (TMR_IS_DESTROYED(timer) == 0 && TMR_IS_PERIODIC(timer) != 0) {
        lcb_timer_rearm(timer, timer->usec_);
        return;
    }

    if (! TMR_IS_STANDALONE(timer)) {
        lcb_aspend_del(&instance->pendops, LCB_PENDTYPE_TIMER, timer);
        lcb_maybe_breakout(instance);
    }

    if (TMR_IS_DESTROYED(timer)) {
        destroy_timer(timer);
    } else {
        timer->state &= ~LCB_TIMER_S_ENTERED;
    }

    (void)sock;
    (void)which;
}
示例#8
0
文件: clock.c 项目: BunsenLabs/tint2
void cleanup_clock()
{
    pango_font_description_free(time1_font_desc);
    time1_font_desc = NULL;
    pango_font_description_free(time2_font_desc);
    time2_font_desc = NULL;
    free(time1_format);
    time1_format = NULL;
    free(time2_format);
    time2_format = NULL;
    free(time_tooltip_format);
    time_tooltip_format = NULL;
    free(time1_timezone);
    time1_timezone = NULL;
    free(time2_timezone);
    time2_timezone = NULL;
    free(time_tooltip_timezone);
    time_tooltip_timezone = NULL;
    free(clock_lclick_command);
    clock_lclick_command = NULL;
    free(clock_mclick_command);
    clock_mclick_command = NULL;
    free(clock_rclick_command);
    clock_rclick_command = NULL;
    free(clock_uwheel_command);
    clock_uwheel_command = NULL;
    free(clock_dwheel_command);
    clock_dwheel_command = NULL;
    destroy_timer(&clock_timer);
}
  /// Destructor flushes buffered data.
  virtual ~basic_socket_streambuf()
  {
    if (pptr() != pbase())
      overflow(traits_type::eof());

    destroy_timer();
  }
示例#10
0
void tm_timer_cleanup() {
	while (timers_head) {
		tm_timer* t = timers_head;
		timers_head = t->next;
		destroy_timer(t);
	}
	tm_event_unref(&tm_timer_event);
}
示例#11
0
void destroy_NPC( NPC* _pNPC )
{
    if ( _pNPC )
    {
        for ( int i = 0; i < GC_NPC_frames; i++ )
            unload_image( _pNPC->NPC_up_frames[i] );

        destroy_timer( _pNPC->walk_timer  );
        destroy_timer( _pNPC->AI_timer    );
        destroy_timer( _pNPC->frame_timer );

        free( _pNPC->NPC_up_frames );

        free( _pNPC );
        _pNPC = NULL;
    }
}
示例#12
0
文件: switch.cpp 项目: Zhanyin/taomee
/**
  * @brief AsyncServer框架要求实现的接口之一。 
  *
  */
extern "C" int  fini_service(int isparent)
{
	if (!isparent) {
		Online::fini();
		destroy_timer();
	}
	return 0;
}
void alarm( void* arg )
{
  int* count = (int*)arg;
  os_timer_log("time is coming,value = %d", (*count)++ );

  if( *count == 10 )
    destroy_timer();
}
示例#14
0
extern "C" int fini_service(int isparent)
{
    if (isparent) {
	} else {
		destroy_timer();
		clear_online();
	}
    return 0;
}
示例#15
0
/**
 * Clean up on exit. This should be called before exiting.
 * \param show_status set to one to display the mem status
 */
void cleanup(int show_status)
{
	LM_INFO("cleanup\n");
	/*clean-up*/

	/* hack: force-unlock the shared memory lock in case
	   		 some process crashed and let it locked; this will
	   		 allow an almost gracious shutdown */
	if (mem_lock)
#ifdef HP_MALLOC
	{
		int i;

		for (i = 0; i < HP_HASH_SIZE; i++)
			shm_unlock(i);
	}
#else
		shm_unlock();
#endif

	handle_ql_shutdown();
	destroy_modules();
#ifdef USE_TCP
	destroy_tcp();
#endif
#ifdef USE_TLS
	destroy_tls();
#endif
	destroy_timer();
	destroy_stats_collector();
	destroy_script_cb();
	pv_free_extra_list();
	destroy_argv_list();
	destroy_black_lists();
#ifdef PKG_MALLOC
	if (show_status){
		LM_GEN1(memdump, "Memory status (pkg):\n");
		pkg_status();
	}
#endif
#ifdef SHM_MEM
	cleanup_debug();

	if (pt) shm_free(pt);
	pt=0;
	if (show_status){
			LM_GEN1(memdump, "Memory status (shm):\n");
			shm_status();
	}

	/* zero all shmem alloc vars that we still use */
	shm_mem_destroy();
#endif
	if (pid_file) unlink(pid_file);
	if (pgid_file) unlink(pgid_file);
}
示例#16
0
文件: login.cpp 项目: Zhanyin/taomee
/**
* @brief AsyncServer框架要求实现的接口之一。 
*
*/
extern "C" int  fini_service(int isparent)
{
	if (!isparent) {
		destroy_timer();
		// finalize service
		login.fini();
	}

	return 0;
}
示例#17
0
文件: switch.cpp 项目: Zhanyin/taomee
/**
 * @brief fini_service 异步框架要求实现的接口之一
 *
 * @param isparent
 *
 * @return
 */
int fini_service(int isparent)
{
    DEBUG_LOG("isparent:%d", isparent);
    if(!isparent)
    {
        g_online.uninit();
        g_shop.uninit();
        g_ed_fight.uninit();
        destroy_timer();
    }
    return 0;
}
示例#18
0
文件: tq.c 项目: apprisi/illumos-gate
void
iu_tq_destroy(iu_tq_t *tq)
{
	iu_timer_node_t *node, *next_node;

	for (node = tq->iutq_head; node != NULL; node = next_node) {
		next_node = node->iutn_next;
		destroy_timer(tq, node);
	}

	free(tq);
}
示例#19
0
/**
  * @brief AsyncServer框架要求实现的接口之一。 
  *
  */
extern "C" int  fini_service(int isparent)
{
	if (!isparent) {
		destroy_timer();

		std::map<uint32_t, CChatCheck*>::iterator it;
		for (it = game_chat_check.begin(); it != game_chat_check.end(); it ++) {
			delete it->second;
		}
		game_chat_check.clear();
	}
	return 0;
}
示例#20
0
/**
 * Clean up on exit. This should be called before exiting.
 * \param show_status set to one to display the mem status 
 */
void cleanup(int show_status)
{
	LM_INFO("cleanup\n");
	/*clean-up*/
	if (mem_lock) 
		shm_unlock(); /* hack: force-unlock the shared memory lock in case
					 some process crashed and let it locked; this will 
					 allow an almost gracious shutdown */
	handle_ql_shutdown();
	destroy_modules();
#ifdef USE_TCP
	destroy_tcp();
#endif
#ifdef USE_TLS
	destroy_tls();
#endif
	destroy_timer();
	destroy_stats_collector();
	destroy_script_cb();
	pv_free_extra_list();
	destroy_argv_list();
	destroy_black_lists();
#ifdef CHANGEABLE_DEBUG_LEVEL
	if (debug!=&debug_init) {
		reset_proc_debug_level();
		debug_init = *debug;
		shm_free(debug);
		debug = &debug_init;
	}
#endif
#ifdef PKG_MALLOC
	if (show_status){
		LM_GEN1(memdump, "Memory status (pkg):\n");
		pkg_status();
	}
#endif
#ifdef SHM_MEM
	if (pt) shm_free(pt);
	pt=0;
	if (show_status){
			LM_GEN1(memdump, "Memory status (shm):\n");
			shm_status();
	}
	/* zero all shmem alloc vars that we still use */
	shm_mem_destroy();
#endif
	if (pid_file) unlink(pid_file);
	if (pgid_file) unlink(pgid_file);
}
示例#21
0
文件: service.c 项目: Zhanyin/taomee
int handle_fini ()
{
	int i;

	for (i = 0; i < epi.maxfd; i++) {
		if (epi.fds[i].type == REMOTE_TYPE_FD && epi.fds[i].cb.sendlen > 0)
			return 0;
	}

	destroy_timer ();
	fini_sprites ();
	unload_dlls ();

	return 1;
}
示例#22
0
int plugin_fini(int type)
{
    switch (type)
    {
        case PROC_MAIN:
            break;
        case PROC_CONN:
            break;
        case PROC_WORK:
            fini_nodes();
            destroy_timer();
            break;
        default:
            break;
    }
    return 0;
}
示例#23
0
文件: timer.c 项目: a-c-m/couchnode
LIBCOUCHBASE_API
lcb_error_t lcb_timer_destroy(lcb_t instance, lcb_timer_t timer)
{
    int standalone = timer->options & LCB_TIMER_STANDALONE;

    if (!standalone) {
        lcb_aspend_del(&instance->pendops, LCB_PENDTYPE_TIMER, timer);
    }

    lcb_timer_disarm(timer);

    if (timer->state & LCB_TIMER_S_ENTERED) {
        timer->state |= LCB_TIMER_S_DESTROYED;
        lcb_assert(TMR_IS_DESTROYED(timer));
    } else {
        destroy_timer(timer);
    }
    return LCB_SUCCESS;
}
示例#24
0
/// Cancel and free a timeout by id
void tm_cleartimeout(unsigned id) {
	tm_timer** p = &timers_head;
	while (*p) {
		tm_timer* t = *p;
		if (t->id == id) {
			if (t->next) {
				t->next->time += t->time;
			}
			*p = t->next;
			destroy_timer(t);
			break;
		}
		p = &t->next;
	}

	if (p == &timers_head) {
		configure_timer_interrupt();
	}
}
示例#25
0
文件: tq.c 项目: apprisi/illumos-gate
int
iu_cancel_timer(iu_tq_t *tq, iu_timer_id_t timer_id, void **arg)
{
	iu_timer_node_t	*node;

	if (timer_id == -1)
		return (0);

	for (node = tq->iutq_head; node != NULL; node = node->iutn_next) {
		if (node->iutn_timer_id == timer_id) {
			if (arg != NULL)
				*arg = node->iutn_arg;
			remove_timer(tq, node);
			destroy_timer(tq, node);
			return (1);
		}
	}
	return (0);
}
示例#26
0
int  fini_service(int isparent)
{
	if (!isparent) {
		KDEBUG_LOG(0, "FINI SERVICE");
		destroy_timer();
		fini_sprites();
		fini_home_maps();
		unload_maps();
		fini_mail();
		fini_all_items();
		fini_beast_grp();
		fini_rand_infos();
		fini_npcs(1);
		fini_all_skills();
		fini_all_clothes();
		fini_sys_info();
		fini_all_tasks();
		fini_shops();
	}
	return 0;
}
示例#27
0
文件: main.c 项目: OPSF/uClinux
/* call it before exiting; if show_status==1, mem status is displayed */
void cleanup(show_status)
{
	/*clean-up*/
	if (mem_lock) 
		shm_unlock(); /* hack: force-unlock the shared memory lock in case
					 some process crashed and let it locked; this will 
					 allow an almost gracious shutdown */
	destroy_modules();
#ifdef USE_TCP
	destroy_tcp();
#endif
#ifdef USE_TLS
	destroy_tls();
#endif
	destroy_timer();
	close_unixsock_server();
	destroy_fifo();
	destroy_script_cb();
#ifdef PKG_MALLOC
	if (show_status){
		LOG(memlog, "Memory status (pkg):\n");
		pkg_status();
	}
#endif
#ifdef SHM_MEM
	if (pt) shm_free(pt);
	pt=0;
	if (show_status){
			LOG(memlog, "Memory status (shm):\n");
			shm_status();
	}
	/* zero all shmem alloc vars that we still use */
	shm_mem_destroy();
#endif
	if (pid_file) unlink(pid_file);
	if (pgid_file) unlink(pgid_file);
}
示例#28
0
/// Callback enqueued by the timer ISR. It is safe for this to be called more
/// often than necessary
void timer_cb(tm_event* event) {
	(void) event;
	
	unsigned prev_time = last_time;
	last_time = tm_uptime_micro();
	unsigned elapsed = last_time - prev_time;

	while (timers_head) {
		tm_timer* t = timers_head;

		if (t->time > elapsed) {
			t->time -= elapsed;
			break;
		}

		elapsed -= t->time;
		timers_head = t->next;

		lua_rawgeti(tm_lua_state, LUA_REGISTRYINDEX, t->lua_cb);

		if (t->repeat != 0) {
			// It's back in the queue, so clearInterval within the callback can cancel it
			enqueue_timer(t->repeat, t);
		} else {
			// Clean up before calling lua, as it can setjmp. The callback is safely rooted on the lua stack above.
			destroy_timer(t);
			t = NULL;
		}

		lua_getfield(tm_lua_state, LUA_GLOBALSINDEX, "global");
		tm_checked_call(tm_lua_state, 1);
	}

	// If lua setjmps, these will be cleaned up when the timer state is reset
	configure_timer_interrupt();
}
void destroy_game(Game* G)
{
    destroy_timer(G->timer);
    destroy_graphics(G->graphics);
    free(G);
}
示例#30
0
文件: timer.c 项目: kamailio/kamailio
/* ret 0 on success, <0 on error*/
int init_timer()
{
	int r;
	int ret;

	ret=-1;

	/* init the locks */
	timer_lock=lock_alloc();
	if (timer_lock==0){
		ret=E_OUT_OF_MEM;
		goto error;
	}
	if (lock_init(timer_lock)==0){
		lock_dealloc(timer_lock);
		timer_lock=0;
		ret=-1;
		goto error;
	}
	/* init the shared structs */
	ticks=shm_malloc(sizeof(ticks_t));
	timer_lst=shm_malloc(sizeof(struct timer_lists));
	if (ticks==0){
		SHM_MEM_CRITICAL;
		ret=E_OUT_OF_MEM;
		goto error;
	}
	if (timer_lst==0){
		SHM_MEM_CRITICAL;
		ret=E_OUT_OF_MEM;
		goto error;
	}
	running_timer=shm_malloc(sizeof(struct timer_ln*));
	if (running_timer==0){
		SHM_MEM_CRITICAL;
		ret=E_OUT_OF_MEM;
		goto error;
	}

	/* initial values */
	memset(timer_lst, 0, sizeof(struct timer_lists));
	*ticks=random(); /* random value for start, for debugging */
	prev_ticks=last_ticks=last_adj_check=*ticks;
	*running_timer=0;
	if (gettimeofday(&start_time, 0)<0){
		LM_ERR("gettimeofday failed: %s [%d]\n", strerror(errno), errno);
		ret=-1;
		goto error;
	}
	last_time=start_time;
	LM_DBG("starting with *ticks=%u\n", (unsigned) *ticks);

	/* init timer structures */
	for (r=0; r<H0_ENTRIES; r++)
		_timer_init_list(&timer_lst->h0[r]);
	for (r=0; r<H1_ENTRIES; r++)
		_timer_init_list(&timer_lst->h1[r]);
	for (r=0; r<H2_ENTRIES; r++)
		_timer_init_list(&timer_lst->h2[r]);
	_timer_init_list(&timer_lst->expired);

#ifdef USE_SLOW_TIMER

	/* init the locks */
	slow_timer_lock=lock_alloc();
	if (slow_timer_lock==0){
		ret=E_OUT_OF_MEM;
		goto error;
	}
	if (lock_init(slow_timer_lock)==0){
		lock_dealloc(slow_timer_lock);
		slow_timer_lock=0;
		ret=-1;
		goto error;
	}
	t_idx=shm_malloc(sizeof(*t_idx));
	s_idx=shm_malloc(sizeof(*s_idx));
	slow_timer_lists=shm_malloc(sizeof(struct timer_head)*SLOW_LISTS_NO);
	running_timer2=shm_malloc(sizeof(struct timer_ln*));
	if ((t_idx==0)||(s_idx==0) || (slow_timer_lists==0) ||(running_timer2==0)){
		SHM_MEM_ERROR;
		ret=E_OUT_OF_MEM;
		goto error;
	}
	*t_idx=*s_idx=0;
	*running_timer2=0;
	for (r=0; r<SLOW_LISTS_NO; r++)
		_timer_init_list(&slow_timer_lists[r]);

#endif

	LM_DBG("timer_list between %p and %p\n",
			&timer_lst->h0[0], &timer_lst->h2[H2_ENTRIES]);
	return 0;
error:
	destroy_timer();
	return ret;
}