|
Toshihiro Shimizu |
890ddd |
#include "igs_resource_thread.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "igs_resource_multithread.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Shinya Kitaoka |
120a6e |
#if defined _WIN32 // vc compile_type
|
|
Toshihiro Shimizu |
890ddd |
unsigned __stdcall
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
void *
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Shinya Kitaoka |
120a6e |
function_(void *param) {
|
|
Shinya Kitaoka |
120a6e |
igs::resource::thread_execute_interface *pp =
|
|
Shinya Kitaoka |
120a6e |
static_cast<igs::resource::thread_execute_interface *="">(param);</igs::resource::thread_execute_interface>
|
|
Shinya Kitaoka |
120a6e |
pp->run();
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void igs::resource::multithread::add(void *thread_execute_instance) {
|
|
Shinya Kitaoka |
120a6e |
this->thre_exec_.push_back(thread_execute_instance);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void igs::resource::multithread::run(void) {
|
|
Shinya Kitaoka |
120a6e |
if (1 == this->thre_exec_.size()) {
|
|
Shinya Kitaoka |
120a6e |
/* 指定が一個の場合はスレッド実行せず、ただ実行 */
|
|
Shinya Kitaoka |
120a6e |
igs::resource::thread_execute_interface *pp =
|
|
Shinya Kitaoka |
120a6e |
static_cast<igs::resource::thread_execute_interface *="">(</igs::resource::thread_execute_interface>
|
|
Shinya Kitaoka |
120a6e |
this->thre_exec_.at(0));
|
|
Shinya Kitaoka |
120a6e |
pp->run();
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// pthread_t = unsigned long int(rhel4)
|
|
Toshihiro Shimizu |
890ddd |
// HANDLE = unsigned long(vc6.0) = void *(vc2005)
|
|
Shinya Kitaoka |
120a6e |
#if defined _WIN32 // vc compile_type
|
|
Shinya Kitaoka |
120a6e |
std::vector<handle> id;</handle>
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Shinya Kitaoka |
120a6e |
std::vector<pthread_t> id;</pthread_t>
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
std::vector<void *="">::iterator it;</void>
|
|
Shinya Kitaoka |
120a6e |
for (it = this->thre_exec_.begin(); it != this->thre_exec_.end(); ++it) {
|
|
Shinya Kitaoka |
120a6e |
id.push_back(igs::resource::thread_run(function_, *it));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
#if defined _WIN32 // vc compile_type
|
|
Shinya Kitaoka |
120a6e |
std::vector<handle>::iterator it;</handle>
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Shinya Kitaoka |
120a6e |
std::vector<pthread_t>::iterator it;</pthread_t>
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Shinya Kitaoka |
120a6e |
for (it = id.begin(); it != id.end(); ++it) {
|
|
Shinya Kitaoka |
120a6e |
igs::resource::thread_join(*it);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
id.clear();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
120a6e |
void igs::resource::multithread::clear(void) { this->thre_exec_.clear(); }
|