メインページ | アルファベット順一覧 | 構成 | ファイル一覧 | 構成メンバ | ファイルメンバ | 関連ページ

# dkcThread.c

説明を見る。

    00001
    00008 #define DKUTIL_C_THREAD_LOCK_C
    00009
    00010 #include "dkcThread.h"
    00011 #include "dkcStdio.h"
    00012
    00013
    00014 DKC_INLINE DKC_THREAD *WINAPI dkcAllocThread()
    00015 {
    00016     return dkcAllocate(sizeof(DKC_THREAD));
    00017
    00018 }
    00019
    00020 DKC_INLINE int WINAPI dkcFreeThread(DKC_THREAD **pp){
    00021     return dkcFree((void **)pp);
    00022 }
    00023
    00024 DKC_INLINE int WINAPI dkcGetCurrentThread(DKC_THREAD *out)
    00025 {
    00026 #ifdef WIN32
    00027     out->handle = GetCurrentThread();
    00028     out->id = GetCurrentThreadId();
    00029 #else
    00030
    00031 #endif
    00032     return edk_SUCCEEDED;
    00033
    00034 }
    00035
    00036
    00037 DKC_EXTERN int WINAPI dkcGetThreadPriority(DKC_THREAD *p,int *priority)
    00038 {
    00039 #ifdef WIN32
    00040     DWORD d = GetThreadPriority(p->handle);
    00041     switch(d){
    00042     case THREAD_PRIORITY_LOWEST:
    00043         *priority = edkcThreadPriorityLowest;
    00044         break;
    00045     case THREAD_PRIORITY_BELOW_NORMAL:
    00046         *priority = edkcThreadPriorityBelowNormal;
    00047         break;
    00048     case THREAD_PRIORITY_NORMAL:
    00049         *priority = edkcThreadPriorityNormal;
    00050         break;
    00051     case THREAD_PRIORITY_ABOVE_NORMAL:
    00052         *priority = edkcThreadPriorityAboveNormal;
    00053         break;
    00054     case THREAD_PRIORITY_HIGHEST:
    00055         *priority = edkcThreadPriorityHighest;
    00056         break;
    00057     case THREAD_PRIORITY_IDLE:
    00058         *priority = edkcThreadPriorityIdle;
    00059         break;
    00060     case THREAD_PRIORITY_TIME_CRITICAL:
    00061         *priority = edkcThreadPriorityTimeCritical;
    00062         break;
    00063     default:
    00064         return edk_FAILED;
    00065     }
    00066 #else
    00067
    00068
    00069 #endif
    00070     return edk_SUCCEEDED;
    00071 }
    00072 DKC_EXTERN int WINAPI dkcSetThreadPriority(DKC_THREAD *p,int priority)
    00073 {
    00074 #ifdef WIN32
    00075     int tp;
    00076     switch(priority){
    00077     case edkcThreadPriorityLowest:
    00078         tp = THREAD_PRIORITY_LOWEST;
    00079         break;
    00080     case edkcThreadPriorityBelowNormal:
    00081         tp = THREAD_PRIORITY_BELOW_NORMAL;
    00082         break;
    00083     case edkcThreadPriorityNormal:
    00084         tp = THREAD_PRIORITY_NORMAL;
    00085         break;
    00086     case edkcThreadPriorityAboveNormal:
    00087         tp = THREAD_PRIORITY_ABOVE_NORMAL;
    00088         break;
    00089     case edkcThreadPriorityHighest:
    00090         tp = THREAD_PRIORITY_HIGHEST;
    00091         break;
    00092     case edkcThreadPriorityIdle:
    00093         tp = THREAD_PRIORITY_IDLE;
    00094         break;
    00095     case edkcThreadPriorityTimeCritical:
    00096         tp = THREAD_PRIORITY_TIME_CRITICAL;
    00097         break;
    00098     default:
    00099         return edk_FAILED;
    00100     }
    00101     if(FALSE==SetThreadPriority(p->handle,tp)){
    00102         return edk_FAILED;
    00103     }
    00104 #else
    00105
    00106
    00107 #endif
    00108     return edk_SUCCEEDED;
    00109 }
    00110
    00111 DKC_INLINE int WINAPI dkcGetCurrentThreadPriority(int *priority)
    00112 {
    00113     DKC_THREAD t;
    00114     int r;
    00115 #ifdef WIN32
    00116     r = dkcGetCurrentThread(&t);
    00117     if(DKUTIL_FAILED(r)){return r;}
    00118     r = dkcGetThreadPriority(&t,priority);
    00119 #else
    00120
    00121 #endif
    00122     return r;
    00123
    00124 }
    00125
    00126 DKC_INLINE int WINAPI dkcSetCurrentThreadPriority(int priority)
    00127 {
    00128     DKC_THREAD t;
    00129     int r;
    00130 #ifdef WIN32
    00131     r = dkcGetCurrentThread(&t);
    00132     if(DKUTIL_FAILED(r)){return r;}
    00133     r = dkcSetThreadPriority(&t,priority);
    00134 #else
    00135
    00136 #endif
    00137     return r;
    00138
    00139 }
    00140
    00141 int WINAPI dkcGetProcessPriority(DKC_THREAD *p,int *priority)
    00142 {
    00143 #ifdef WIN32
    00144
    00145     DWORD d = GetPriorityClass(p->handle);
    00146     switch(d){
    00147     case HIGH_PRIORITY_CLASS:
    00148         *priority = edkcProcessPriorityHigh;
    00149         break;
    00150     case IDLE_PRIORITY_CLASS:
    00151         *priority = edkcProcessPriorityIdle;
    00152         break;
    00153     case NORMAL_PRIORITY_CLASS:
    00154         *priority = edkcProcessPriorityNormal;
    00155         break;
    00156     case REALTIME_PRIORITY_CLASS:
    00157         *priority = edkcProcessPriorityRealTime;
    00158         break;
    00159     default:
    00160         return edk_FAILED;
    00161     }
    00162
    00163 #else
    00164
    00165 #endif
    00166     return edk_SUCCEEDED;
    00167 }
    00168
    00169 DKC_EXTERN int WINAPI dkcSetProcessPriority(DKC_THREAD *p,int priority){
    00170 #ifdef WIN32
    00171     DWORD pc;
    00172     switch(priority){
    00173     case edkcProcessPriorityHigh:
    00174         pc = HIGH_PRIORITY_CLASS;
    00175         break;
    00176     case edkcProcessPriorityIdle:
    00177         pc =IDLE_PRIORITY_CLASS;
    00178         break;
    00179     case edkcProcessPriorityNormal:
    00180         pc =NORMAL_PRIORITY_CLASS;
    00181         break;
    00182     case edkcProcessPriorityRealTime:
    00183         pc =REALTIME_PRIORITY_CLASS;
    00184         break;
    00185     default:
    00186         return edk_FAILED;
    00187     }
    00188     if(FALSE==SetPriorityClass(p->handle,pc)){
    00189         return edk_FAILED;
    00190     }
    00191 #else
    00192
    00193
    00194 #endif
    00195     return edk_SUCCEEDED;
    00196
    00197
    00198 }
    00199
    00200 int WINAPI dkcGetCurrentProcessPriority(int *priority){
    00201     DKC_THREAD t;
    00202     int r;
    00203 #ifdef WIN32
    00204     r = dkcGetCurrentThread(&t);
    00205     if(DKUTIL_FAILED(r)){return r;}
    00206     r = dkcGetProcessPriority(&t,priority);
    00207 #else
    00208
    00209 #endif
    00210     return r;
    00211 }
    00212 int WINAPI dkcSetCurrentProcessPriority(int priority){
    00213     DKC_THREAD t;
    00214     int r;
    00215 #ifdef WIN32
    00216     r = dkcGetCurrentThread(&t);
    00217     if(DKUTIL_FAILED(r)){return r;}
    00218     r = dkcSetProcessPriority(&t,priority);
    00219 #else
    00220
    00221 #endif
    00222     return r;
    00223 }