tahoma2d/toonz/sources/stdfx/igs_resource_thread_unix.cpp

50 lines
1.8 KiB
C++
Raw Normal View History

2016-06-15 18:43:10 +12:00
#include <stdexcept> // std::domain_error()
2016-03-19 06:57:51 +13:00
#include "igs_resource_msg_from_err.h"
#include "igs_resource_thread.h"
//--------------------------------------------------------------------
// pthread_t = unsigned long int(rhel4)
/*
2016-06-15 18:43:10 +12:00
state
PTHREAD_CREATE_JOINABLE pthread_join()
PTHREAD_CREATE_DETACHED
thread終了を知るには自前で仕掛けが必要
2016-03-19 06:57:51 +13:00
*/
pthread_t igs::resource::thread_run(
2016-06-15 18:43:10 +12:00
void *(*function)(void *), void *func_arg,
const int state // PTHREAD_CREATE_JOINABLE/PTHREAD_CREATE_DETACHED
) {
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(-)");
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
pthread_t thread_id = 0;
const int erno = ::pthread_create(&(thread_id), &attr, function, func_arg);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (0 != erno) {
throw std::domain_error(
igs_resource_msg_from_err("pthread_create(-)", erno));
}
return thread_id;
2016-03-19 06:57:51 +13:00
}
/*
const bool igs::resource::thread_was_done(const pthread_t thread_id) {
??????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????
threadの終了方法を見る関数は見つからない
???
}
*/
2016-06-15 18:43:10 +12:00
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));
}
2016-03-19 06:57:51 +13:00
}