示例#1
0
void register_timejob(struct timejob *tj)
{
	pthread_mutex_lock(&timejob_mutex);
	if (__register(tj))
		pthread_cond_signal(&timejob_cond);
	pthread_mutex_unlock(&timejob_mutex);
}
示例#2
0
__api ret __module_register(const common::IRegister* _reg)
{
    if_return(_reg == nullptr_t, ret_args_error);
    __register(network::EventPoll,      _reg);
    __register(network::TcpClient,      _reg);
    __register(network::TcpServer,		_reg);
    __register(network::TcpConnection,	_reg);
    __register(network::HttpServer,     _reg);
    __register(network::HttpConnection, _reg);
    return ret_success;
}
示例#3
0
static void *timejob_thread(void *arg)
{
	struct timejob *tj;
	struct timeval tv;
	struct timespec timeout;
	int sec;
	
	setpriority(PRIO_PROCESS, getpid(), 10);
	pthread_mutex_lock(&timejob_mutex);
	while (timejob_run && pthread_kill(main_thread_id, 0) == 0) {
		tj = list_peek(&timejob_list);
		if (tj) {
			gettimeofday(&tv, NULL);
			if (tv.tv_sec > tj->j_ts.tv_sec ||
			    (tv.tv_sec == tj->j_ts.tv_sec && tv.tv_usec * 1000 >= tj->j_ts.tv_nsec)) {
				timejob_curr = tj;
				list_pop(&timejob_list);
				pthread_mutex_unlock(&timejob_mutex);
				sec = timejob_curr->j_func(timejob_curr->j_arg,
							   timejob_curr->j_arg_sec);
				pthread_mutex_lock(&timejob_mutex);
				if (sec) {
					gettimeofday(&tv, NULL);
					tj->j_ts.tv_sec = tv.tv_sec + sec;
					tj->j_ts.tv_nsec = tv.tv_usec * 1000;
					__register(tj);
				}
				timejob_curr = NULL;
				pthread_cond_signal(&timejob_curr_cond);
			} else {
				/* copy timeout as the struct can be removed from the list */
				timeout = tj->j_ts;
				pthread_cond_timedwait(&timejob_cond, &timejob_mutex, &timeout);
			}
		} else {
			pthread_cond_wait(&timejob_cond, &timejob_mutex);
		}
	}
	timejob_run = 2;
	pthread_cond_signal(&timejob_run_cond);
	pthread_mutex_unlock(&timejob_mutex);
	return NULL;
}