![]() |
pl-nk v0.4.5
Plonk|Plink|Plank are a set of cross-platform C/C++ frameworks for audio software development
|
00001 /* 00002 ------------------------------------------------------------------------------- 00003 This file is part of the Plink, Plonk, Plank libraries 00004 by Martin Robinson 00005 00006 http://code.google.com/p/pl-nk/ 00007 00008 Copyright University of the West of England, Bristol 2011-14 00009 All rights reserved. 00010 00011 Redistribution and use in source and binary forms, with or without 00012 modification, are permitted provided that the following conditions are met: 00013 00014 * Redistributions of source code must retain the above copyright 00015 notice, this list of conditions and the following disclaimer. 00016 * Redistributions in binary form must reproduce the above copyright 00017 notice, this list of conditions and the following disclaimer in the 00018 documentation and/or other materials provided with the distribution. 00019 * Neither the name of University of the West of England, Bristol nor 00020 the names of its contributors may be used to endorse or promote products 00021 derived from this software without specific prior written permission. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00024 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00025 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00026 DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF THE WEST OF ENGLAND, BRISTOL BE 00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 00034 This software makes use of third party libraries. For more information see: 00035 doc/license.txt included in the distribution. 00036 ------------------------------------------------------------------------------- 00037 */ 00038 00039 #ifndef PLANK_THREAD_H 00040 #define PLANK_THREAD_H 00041 00042 #include "../containers/atomic/plank_Atomic.h" 00043 00044 PLANK_BEGIN_C_LINKAGE 00045 00056 typedef struct PlankThread* PlankThreadRef; 00057 00060 #if PLANK_WIN 00061 typedef PlankUI PlankThreadID; 00062 #else 00063 typedef PlankUL PlankThreadID; 00064 #endif 00065 00098 typedef PlankResult (*PlankThreadFunction)(PlankThreadRef); 00099 00103 PlankResult pl_ThreadSleep (PlankD seconds); 00104 00109 PlankResult pl_ThreadYield(); 00110 00113 PlankThreadID pl_ThreadCurrentID(); 00114 00117 PlankThreadRef pl_Thread_CreateAndInit(); 00118 00121 PlankThreadRef pl_Thread_Create(); 00122 00126 PlankResult pl_Thread_Init (PlankThreadRef p); 00127 00131 PlankResult pl_Thread_DeInit (PlankThreadRef p); 00132 00136 PlankResult pl_Thread_Destroy (PlankThreadRef p); 00137 00141 PlankThreadID pl_Thread_GetID (PlankThreadRef p); 00142 00147 PlankResult pl_Thread_SetName (PlankThreadRef p, const char* name); 00148 00154 PlankResult pl_Thread_SetFunction (PlankThreadRef p, PlankThreadFunction function); 00155 00163 PlankResult pl_Thread_SetUserData (PlankThreadRef p, PlankP userData); 00164 00169 PlankP pl_Thread_GetUserData (PlankThreadRef p); 00170 00175 PlankResult pl_Thread_Start (PlankThreadRef p); 00176 00183 PlankResult pl_Thread_Cancel (PlankThreadRef p); 00184 00188 PlankResult pl_Thread_Wait (PlankThreadRef p); 00189 00190 PlankResult pl_Thread_Pause (PlankThreadRef p); 00191 PlankResult pl_Thread_PauseWithTimeout (PlankThreadRef p, double duration); 00192 PlankResult pl_Thread_Resume (PlankThreadRef p); 00193 00194 00198 PlankB pl_Thread_IsRunning (PlankThreadRef p); 00199 00206 PlankResult pl_Thread_SetShouldExit (PlankThreadRef p); 00207 00214 PlankB pl_Thread_GetShouldExit (PlankThreadRef p); 00215 00216 PlankResult pl_Thread_SetPriority (PlankThreadRef p, int priority); 00217 PlankResult pl_Thread_SetPriorityAudio (PlankThreadRef p, int blockSize, double sampleRate); 00218 PlankResult pl_Thread_SetAffinity (PlankThreadRef p, int affinity); 00219 00222 PLANK_END_C_LINKAGE 00223 00224 #if !DOXYGEN 00225 #if PLANK_APPLE || PLANK_LINUX 00226 typedef pthread_t PlankThreadNativeHandle; 00227 typedef void* PlankThreadNativeReturn; 00228 #define PLANK_THREADCALL 00229 #endif // PLANK_APPLE 00230 00231 #if PLANK_ANDROID 00232 typedef pthread_t PlankThreadNativeHandle; 00233 typedef void* PlankThreadNativeReturn; 00234 #define PLANK_THREADCALL 00235 #endif // PLANK_ANDROID 00236 00237 #if PLANK_WIN 00238 typedef uintptr_t PlankThreadNativeHandle; 00239 typedef unsigned PlankThreadNativeReturn; 00240 #define PLANK_THREADCALL __stdcall 00241 #endif // PLANK_WINDOWS 00242 00243 #define PLANK_THREAD_MAXNAMELENGTH 256 00244 00245 typedef struct PlankThread 00246 { 00247 // could pack thread, shouldExitAtom and isRunningAtom into a PX 00248 PlankThreadNativeHandle thread; 00249 PlankThreadID threadID; 00250 PlankThreadFunction function; 00251 PLANK_ALIGN(PLANK_WIDESIZE) PlankAtomicPX userDataAtom; 00252 PLANK_ALIGN(4) PlankAtomicI shouldExitAtom; 00253 PLANK_ALIGN(4) PlankAtomicI isRunningAtom; 00254 PLANK_ALIGN(4) PlankAtomicI paused; 00255 char name[PLANK_THREAD_MAXNAMELENGTH]; 00256 int priority; 00257 int affinity; 00258 } PlankThread; 00259 #endif 00260 00261 00262 #endif // PLANK_THREAD_H