#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <assert.h>
#include <string.h>
#include <math.h>
#include <errno.h>
#include "pa_util.h"
#include "pa_unix_util.h"
#include "pa_debugprint.h"
void Pa_Sleep | ( | long | msec | ) |
Put the caller to sleep for at least 'msec' milliseconds. This function is provided only as a convenience for authors of portable code (such as the tests and examples in the PortAudio distribution.)
The function may sleep longer than requested so don't rely on this for accurate musical timing.
PaError PaUnixMutex_Initialize | ( | PaUnixMutex * | self | ) |
PaError PaUnixMutex_Lock | ( | PaUnixMutex * | self | ) |
Lock mutex.
We're disabling thread cancellation while the thread is holding a lock, so mutexes are properly unlocked at termination time.
PaError PaUnixMutex_Terminate | ( | PaUnixMutex * | self | ) |
PaError PaUnixMutex_Unlock | ( | PaUnixMutex * | self | ) |
Unlock mutex.
Thread cancellation is enabled again after the mutex is properly unlocked.
PaError PaUnixThread_New | ( | PaUnixThread * | self, | |
void *(*)(void *) | threadFunc, | |||
void * | threadArg, | |||
PaTime | waitForChild, | |||
int | rtSched | |||
) |
Spawn a thread.
Intended for spawning the callback thread from the main thread. This function can even block (for a certain time or indefinitely) untill notified by the callback thread (using PaUnixThread_NotifyParent), which can be useful in order to make sure that callback has commenced before returning from Pa_StartStream.
threadFunc,: | The function to be executed in the child thread. | |
waitForChild,: | If not 0, wait for child thread to call PaUnixThread_NotifyParent. Less than 0 means wait for ever, greater than 0 wait for the specified time. | |
rtSched,: | Enable realtime scheduling? |
PaError PaUnixThread_NotifyParent | ( | PaUnixThread * | self | ) |
Notify waiting parent thread.
PaError PaUnixThread_PrepareNotify | ( | PaUnixThread * | self | ) |
Prepare to notify waiting parent thread.
An internal lock must be held before the parent is notified in PaUnixThread_NotifyParent, call this to acquire it beforehand.
int PaUnixThread_StopRequested | ( | PaUnixThread * | self | ) |
Has the parent thread requested this thread to stop?
PaError PaUnixThread_Terminate | ( | PaUnixThread * | self, | |
int | wait, | |||
PaError * | exitResult | |||
) |
Terminate thread.
wait,: | If true, request that background thread stop and wait untill it does, else cancel it. | |
exitResult,: | If non-null this will upon return contain the exit status of the thread. |
PaError PaUnixThreading_Initialize | ( | ) |
Initialize global threading state.
void* PaUtil_AllocateMemory | ( | long | size | ) |
Allocate size bytes, guaranteed to be aligned to a FIXME byte boundary
PaError PaUtil_CancelThreading | ( | PaUtilThreading * | threading, | |
int | wait, | |||
PaError * | exitResult | |||
) |
int PaUtil_CountCurrentlyAllocatedBlocks | ( | void | ) |
Return the number of currently allocated blocks. This function can be used for detecting memory leaks.
void PaUtil_FreeMemory | ( | void * | block | ) |
Realease block if non-NULL. block may be NULL
PaTime PaUtil_GetTime | ( | void | ) |
Return the system time in seconds. Used to implement CPU load functions
void PaUtil_InitializeClock | ( | void | ) |
Initialize the clock used by PaUtil_GetTime(). Call this before calling PaUtil_GetTime.
PaError PaUtil_InitializeThreading | ( | PaUtilThreading * | threading | ) |
PaError PaUtil_StartThreading | ( | PaUtilThreading * | threading, | |
void *(*)(void *) | threadRoutine, | |||
void * | data | |||
) |
void PaUtil_TerminateThreading | ( | PaUtilThreading * | threading | ) |
pthread_t paUnixMainThread = 0 |