void *my_log_thread(void *t_conf) { int do_exit = 0; /* get pointer to cl_thread_settings_t struct */ cl_thread_settings_t *thread_config = (cl_thread_settings_t*)t_conf; /* setup thread config ( at least done by call to cl_thread_func_startup() ) */ if ( cl_thread_set_thread_config(thread_config) != CL_RETVAL_OK) { printf("cl_thread_set_thread_config() error\n"); } CL_LOG( CL_LOG_INFO, "starting initialization ..."); /* setup thread begin */ /* enter setup code here ... */ /* setup thread end */ /* thread init done, trigger startup conditon variable*/ cl_thread_func_startup(thread_config); CL_LOG( CL_LOG_INFO, "init done ..."); CL_LOG( CL_LOG_INFO, "starting main loop ..."); /* ok, thread main */ while (do_exit == 0) { int ret_val; /* check for cancel */ cl_thread_func_testcancel(thread_config); /* sleep till event arives */ if ((ret_val = cl_thread_wait_for_event(thread_config,0,25000)) != CL_RETVAL_OK) { /* nothing to do */ switch(ret_val) { case CL_RETVAL_CONDITION_WAIT_TIMEOUT: break; default: { CL_LOG_INT(CL_LOG_INFO, ">got error<: ", ret_val); do_exit = 1; } } } } /* this only happens on error */ CL_LOG( CL_LOG_INFO, "exiting ..."); /* at least set exit state */ cl_thread_func_cleanup(thread_config); return(NULL); }
void *timeout_thread_main(void *t_conf) { /* get pointer to cl_thread_settings_t struct */ int ret_val; int pthread_cleanup_pop_execute = 0; /* workaround for irix compiler warning */ cl_thread_settings_t *thread_config = (cl_thread_settings_t*)t_conf; pthread_cleanup_push((void (*)(void *)) cl_thread_default_cleanup_function, (void*) thread_config ); /* setup thread */ if (thread_config) { printf("thread %d: initialize\n", thread_config->thread_id); /* thread init done, trigger startup conditon variable*/ ret_val = cl_thread_func_startup(thread_config); if (ret_val != CL_RETVAL_OK) { printf("thread %d: cl_thread_func_startup() - %d\n", thread_config->thread_id, ret_val); } /* ok, thread main */ printf("thread %d: enter mainloop\n", thread_config->thread_id); if ((ret_val=cl_thread_wait_for_event(thread_config,10,0)) != CL_RETVAL_OK) { /* nothing to do */ switch(ret_val) { case CL_RETVAL_CONDITION_WAIT_TIMEOUT: printf("thread %d: got timeout\n", thread_config->thread_id); break; default: printf("thread %d: got error: %d\n", thread_config->thread_id, ret_val); } } printf("thread %d: exit\n", thread_config->thread_id); /* at least set exit state */ ret_val = cl_thread_func_cleanup(thread_config); if (ret_val != CL_RETVAL_OK) { printf("thread %d: cl_thread_func_cleanup() - %d\n", thread_config->thread_id, ret_val); } } pthread_cleanup_pop(pthread_cleanup_pop_execute); return(NULL); }
void *my_test_thread(void *t_conf) { cl_thread_settings_t* thread_p = NULL; int counter = 0; int do_exit = 0; /* get pointer to cl_thread_settings_t struct */ cl_thread_settings_t *thread_config = (cl_thread_settings_t*)t_conf; /* setup thread config ( at least done by call to cl_thread_func_startup() ) */ if (cl_thread_set_thread_config(thread_config) != CL_RETVAL_OK) { printf("cl_thread_set_thread_config() error\n"); } CL_LOG( CL_LOG_INFO, "starting initialization ..."); /* setup thread begin */ /* enter setup code here ... */ /* setup thread end */ /* thread init done, trigger startup conditon variable*/ cl_thread_func_startup(thread_config); CL_LOG( CL_LOG_INFO, "starting main loop ..."); /* ok, thread main */ while (do_exit == 0) { int ret_val; /* check for cancel */ cl_thread_func_testcancel(thread_config); CL_LOG( CL_LOG_INFO, "try to get thread list lock ..."); if (cl_raw_list_lock(thread_list) == CL_RETVAL_OK) { int id; CL_LOG( CL_LOG_INFO, "locked thread list"); if (thread_config->thread_id == 1) { thread_p = cl_thread_list_get_thread_by_id(thread_list,2); id = 2; } else { thread_p = cl_thread_list_get_thread_by_id(thread_list,1); id = 1; } if (thread_p) { if (thread_config->thread_id == 1) { cl_thread_trigger_event(thread_p); counter++; CL_LOG_INT( CL_LOG_INFO, "events triggered: ", counter); } } else { CL_LOG_INT( CL_LOG_INFO, "can't find thread : ", id); } CL_LOG( CL_LOG_INFO, "unlocking thread list ..."); cl_raw_list_unlock(thread_list); } /* sleep till event arives */ if ((ret_val = cl_thread_wait_for_event(thread_config,0,10000)) != CL_RETVAL_OK) { /* nothing to do */ switch(ret_val) { case CL_RETVAL_CONDITION_WAIT_TIMEOUT: /* printf("thread %d: got timeout\n", thread_config->thread_id); */ break; default: { CL_LOG_INT( CL_LOG_INFO, ">got error<: ", ret_val); do_exit = 1; } } } } /* this only happens on error */ CL_LOG( CL_LOG_INFO, "exiting ..."); /* at least set exit state */ cl_thread_func_cleanup(thread_config); return(NULL); }
void *my_thread(void *t_conf) { cl_thread_settings_t* thread_p = NULL; int counter = 0; int do_exit = 0; /* get pointer to cl_thread_settings_t struct */ cl_thread_settings_t *thread_config = (cl_thread_settings_t*)t_conf; /* setup thread */ printf("thread %d: initialize\n", thread_config->thread_id); /* thread init done, trigger startup conditon variable*/ cl_thread_func_startup(thread_config); printf("thread %d: enter mainloop\n", thread_config->thread_id); /* ok, thread main */ while (do_exit == 0) { int ret_val; printf("thread %d: try locking thread_list ...\n", thread_config->thread_id); /* check for cancel */ cl_thread_func_testcancel(thread_config); if (cl_raw_list_lock(thread_list) == CL_RETVAL_OK) { int id; printf("thread %d: locked thread_list\n", thread_config->thread_id); if (thread_config->thread_id == 1) { thread_p = cl_thread_list_get_thread_by_id(thread_list,2); id = 2; } else { thread_p = cl_thread_list_get_thread_by_id(thread_list,1); id = 1; } if (thread_p) { if (thread_config->thread_id == 1) { cl_thread_trigger_event(thread_p); counter++; printf("thread %d: triggered %d events\n", thread_config->thread_id, counter); } } else { printf("thread %d: thread %d not found\n", thread_config->thread_id,id); } printf("thread %d: unlocking thread_list\n", thread_config->thread_id); cl_raw_list_unlock(thread_list); } if ((ret_val = cl_thread_wait_for_event(thread_config,0,10000)) != CL_RETVAL_OK) { /* nothing to do */ switch(ret_val) { case CL_RETVAL_CONDITION_WAIT_TIMEOUT: /* printf("thread %d: got timeout\n", thread_config->thread_id); */ break; default: { printf("thread %d: got error: %d\n", thread_config->thread_id, ret_val); do_exit = 1; } } } } printf("thread %d: exit\n", thread_config->thread_id); /* at least set exit state */ cl_thread_func_cleanup(thread_config); return(NULL); }