timer.c

来自「CS架构的多平台的GUI系统」· C语言 代码 · 共 107 行

C
107
字号
/***************************************************************************    begin                : Mon May 23 2005    copyright            : (C) 2005 by Alper Akcan    email                : distchx@yahoo.com ***************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU Lesser General Public License as        * *   published by the Free Software Foundation; either version 2.1 of the  * *   License, or (at your option) any later version.                       * *                                                                         * ***************************************************************************/#include "xynth_.h"int s_timer_init (s_timer_t **timer){	*timer = (s_timer_t *) s_malloc(sizeof(s_timer_t));	(*timer)->timeval = -1;	(*timer)->interval = -1;	(*timer)->cb = NULL;	(*timer)->user_data = NULL;	return 0;}int s_timer_timeval (s_window_t *window, s_timer_t *timer, int timeval){	s_thread_mutex_lock(window->timers->mut);	timer->timeval = timeval;	timer->interval = timeval;	s_thread_mutex_unlock(window->timers->mut);	s_client_wakeup(window);	return 0;}int s_timer_uninit (s_timer_t *timer){	s_free(timer);	return 0;}int s_timer_del (s_window_t *window, s_timer_t *timer){	int r;		s_thread_mutex_lock(window->timers->mut);	r = s_list_remove(window->timers->timers, s_list_get_pos(window->timers->timers, timer));	s_thread_mutex_unlock(window->timers->mut);	s_client_wakeup(window);	return r;}int s_timer_add (s_window_t *window, s_timer_t *timer){	int ret = 0;	if ((timer->timeval < 0) ||	    (timer->cb == NULL)) {		goto end;	}	timer->interval = timer->timeval;		s_thread_mutex_lock(window->timers->mut);	if (s_list_get_pos(window->timers->timers, timer) < 0) {		ret = s_list_add(window->timers->timers, timer, -1);	}	s_thread_mutex_unlock(window->timers->mut);	s_client_wakeup(window);end:	return ret;}int s_timers_init (s_window_t *window){	window->timers = (s_timers_t *) s_malloc(sizeof(s_timers_t));	if (s_thread_mutex_init(&(window->timers->mut))) {		goto err0;	}	window->timers->timers = (s_list_t *) s_malloc(sizeof(s_list_t));	return s_list_init(window->timers->timers);err0:	s_free(window->timers);	return -1;}int s_timers_uninit (s_window_t *window){	s_timer_t *t;	s_thread_mutex_lock(window->timers->mut);	while (!s_list_eol(window->timers->timers, 0)) {		t = (s_timer_t *) s_list_get(window->timers->timers, 0);		s_list_remove(window->timers->timers, 0);		s_timer_uninit(t);			}	s_thread_mutex_unlock(window->timers->mut);	s_thread_mutex_destroy(window->timers->mut);	s_free(window->timers->timers);	s_free(window->timers);	return 0;}

⌨️ 快捷键说明

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