tahoma2d/toonz/sources/stdfx/igs_resource_multithread.cpp

59 lines
1.5 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
#include "igs_resource_thread.h"
#include "igs_resource_multithread.h"
2016-06-15 18:43:10 +12:00
namespace {
#if defined _WIN32 // vc compile_type
2016-03-19 06:57:51 +13:00
unsigned __stdcall
#else
void *
#endif
2016-06-15 18:43:10 +12:00
function_(void *param) {
igs::resource::thread_execute_interface *pp =
static_cast<igs::resource::thread_execute_interface *>(param);
pp->run();
return 0;
2016-03-19 06:57:51 +13:00
};
}
2016-06-15 18:43:10 +12:00
void igs::resource::multithread::add(void *thread_execute_instance) {
this->thre_exec_.push_back(thread_execute_instance);
2016-03-19 06:57:51 +13:00
}
2016-06-15 18:43:10 +12:00
void igs::resource::multithread::run(void) {
if (1 == this->thre_exec_.size()) {
/* 指定が一個の場合はスレッド実行せず、ただ実行 */
igs::resource::thread_execute_interface *pp =
static_cast<igs::resource::thread_execute_interface *>(
this->thre_exec_.at(0));
pp->run();
return;
}
2016-03-19 06:57:51 +13:00
// pthread_t = unsigned long int(rhel4)
// HANDLE = unsigned long(vc6.0) = void *(vc2005)
2016-06-15 18:43:10 +12:00
#if defined _WIN32 // vc compile_type
std::vector<HANDLE> id;
2016-03-19 06:57:51 +13:00
#else
2016-06-15 18:43:10 +12:00
std::vector<pthread_t> id;
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
{
std::vector<void *>::iterator it;
for (it = this->thre_exec_.begin(); it != this->thre_exec_.end(); ++it) {
id.push_back(igs::resource::thread_run(function_, *it));
}
}
{
#if defined _WIN32 // vc compile_type
std::vector<HANDLE>::iterator it;
2016-03-19 06:57:51 +13:00
#else
2016-06-15 18:43:10 +12:00
std::vector<pthread_t>::iterator it;
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
for (it = id.begin(); it != id.end(); ++it) {
igs::resource::thread_join(*it);
}
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
id.clear();
2016-03-19 06:57:51 +13:00
}
2016-06-15 18:43:10 +12:00
void igs::resource::multithread::clear(void) { this->thre_exec_.clear(); }