Shinya Kitaoka 810553
#pragma once
Shinya Kitaoka 810553
Toshihiro Shimizu 890ddd
#ifndef igs_resource_thread_h
Toshihiro Shimizu 890ddd
#define igs_resource_thread_h
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#if defined _WIN32    //-------------------------------------------------
Shinya Kitaoka 120a6e
#include <windows.h>  // HANDLE</windows.h>
Shinya Kitaoka 120a6e
#include <process.h>  // _beginthreadex()</process.h>
Toshihiro Shimizu 890ddd
#ifndef IGS_RESOURCE_IFX_EXPORT
Toshihiro Shimizu 890ddd
#define IGS_RESOURCE_IFX_EXPORT
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
namespace igs {
Shinya Kitaoka 120a6e
namespace resource {
Shinya Kitaoka 120a6e
// HANDLE = unsigned long(vc6.0) = void *(vc2005)
Toshihiro Shimizu 890ddd
IGS_RESOURCE_IFX_EXPORT const HANDLE thread_run(
Shinya Kitaoka 120a6e
    unsigned(__stdcall *function)(void *), void *func_arg,
Shinya Kitaoka 120a6e
    const int priority = THREAD_PRIORITY_NORMAL
Shinya Kitaoka 120a6e
    /*
Shinya Kitaoka 120a6e
    priorityに与える値を優先度の高いものから順に並べます。
Shinya Kitaoka 120a6e
    THREAD_PRIORITY_TIME_CRITICAL		プロセスにより15 or 31
Shinya Kitaoka 120a6e
    THREAD_PRIORITY_HIGHEST			標準より2ポイント高い
Shinya Kitaoka 120a6e
    THREAD_PRIORITY_ABOVE_NORMAL		標準より1ポイント高い
Shinya Kitaoka 120a6e
    THREAD_PRIORITY_NORMAL			標準
Shinya Kitaoka 120a6e
    THREAD_PRIORITY_BELOW_NORMAL		標準より1ポイント低い
Shinya Kitaoka 120a6e
    THREAD_PRIORITY_LOWEST			標準より2ポイント低い
Shinya Kitaoka 120a6e
    THREAD_PRIORITY_IDLE			プロセスにより1 or 16
Shinya Kitaoka 120a6e
    */
Shinya Kitaoka 120a6e
    );
Toshihiro Shimizu 890ddd
IGS_RESOURCE_IFX_EXPORT const bool thread_was_done(const HANDLE thread_id);
Toshihiro Shimizu 890ddd
IGS_RESOURCE_IFX_EXPORT void thread_join(const HANDLE thread_id);
Toshihiro Shimizu 890ddd
IGS_RESOURCE_IFX_EXPORT void thread_wait(const HANDLE thread_id);
Toshihiro Shimizu 890ddd
IGS_RESOURCE_IFX_EXPORT void thread_close(const HANDLE thread_id);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
#else  //--------------------------------------------------------------
Shinya Kitaoka 120a6e
#include <pthread.h>  // pthread_t,pthread_create(),pthread_join()</pthread.h>
Shinya Kitaoka 120a6e
namespace igs {
Shinya Kitaoka 120a6e
namespace resource {
Shinya Kitaoka 120a6e
// pthread_t = unsigned long int(rhel4)
Toshihiro Shimizu 890ddd
pthread_t thread_run(
Shinya Kitaoka 120a6e
    void *(*function)(void *), void *func_arg,
Shinya Kitaoka 120a6e
    const int state = PTHREAD_CREATE_JOINABLE
Shinya Kitaoka 120a6e
    /*
Shinya Kitaoka 120a6e
    state が
Shinya Kitaoka 120a6e
    PTHREAD_CREATE_JOINABLE なら、pthread_join()を呼んで終了を待つ
Shinya Kitaoka 120a6e
    PTHREAD_CREATE_DETACHED なら、なにも呼ぶ必要がないが、
Shinya Kitaoka 120a6e
            thread終了を知るには自前で仕掛けが必要。
Shinya Kitaoka 120a6e
    */
Shinya Kitaoka 120a6e
    );
Toshihiro Shimizu 890ddd
void thread_join(const pthread_t thread_id);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
#endif  //-------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif /* !igs_resource_thread_h */