| #include <stdexcept> // std::domain_error() |
| #include "igs_resource_msg_from_err.h" |
| #include "igs_resource_thread.h" |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| pthread_t igs::resource::thread_run( |
| void *(*function)(void *), void *func_arg, |
| const int state |
| ) { |
| pthread_attr_t attr; |
| if (::pthread_attr_init(&attr)) { |
| throw std::domain_error("pthread_attr_init(-)"); |
| } |
| if (::pthread_attr_setdetachstate(&attr, state)) { |
| throw std::domain_error("pthread_attr_setdetachstate(-)"); |
| } |
| |
| pthread_t thread_id = 0; |
| const int erno = ::pthread_create(&(thread_id), &attr, function, func_arg); |
| |
| if (0 != erno) { |
| throw std::domain_error( |
| igs_resource_msg_from_err("pthread_create(-)", erno)); |
| } |
| return thread_id; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void igs::resource::thread_join(const pthread_t thread_id) { |
| const int erno = ::pthread_join(thread_id, NULL); |
| if (0 != erno) { |
| throw std::domain_error(igs_resource_msg_from_err("pthread_join(-)", erno)); |
| } |
| } |