Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
miniaudio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
miniaudio
Commits
fc1a6930
Commit
fc1a6930
authored
Jun 08, 2020
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove dependency on ma_context from the thread API.
parent
d54b9efc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
24 deletions
+22
-24
miniaudio.h
miniaudio.h
+22
-24
No files found.
miniaudio.h
View file @
fc1a6930
...
@@ -7719,14 +7719,14 @@ static int ma_thread_priority_to_win32(ma_thread_priority priority)
...
@@ -7719,14 +7719,14 @@ static int ma_thread_priority_to_win32(ma_thread_priority priority)
}
}
}
}
static ma_result ma_thread_create__win32(ma_
context* pContext, ma_thread* pThread
, ma_thread_entry_proc entryProc, void* pData)
static ma_result ma_thread_create__win32(ma_
thread* pThread, ma_thread_priority priority
, ma_thread_entry_proc entryProc, void* pData)
{
{
pThread->win32.hThread = CreateThread(NULL, 0, entryProc, pData, 0, NULL);
pThread->win32.hThread = CreateThread(NULL, 0, entryProc, pData, 0, NULL);
if (pThread->win32.hThread == NULL) {
if (pThread->win32.hThread == NULL) {
return ma_result_from_GetLastError(GetLastError());
return ma_result_from_GetLastError(GetLastError());
}
}
SetThreadPriority((HANDLE)pThread->win32.hThread, ma_thread_priority_to_win32(p
Context->threadP
riority));
SetThreadPriority((HANDLE)pThread->win32.hThread, ma_thread_priority_to_win32(priority));
return MA_SUCCESS;
return MA_SUCCESS;
}
}
...
@@ -7843,7 +7843,7 @@ typedef int (* ma_pthread_attr_setschedpolicy_proc)(pthread_attr_t *attr, int po
...
@@ -7843,7 +7843,7 @@ typedef int (* ma_pthread_attr_setschedpolicy_proc)(pthread_attr_t *attr, int po
typedef int (* ma_pthread_attr_getschedparam_proc)(const pthread_attr_t *attr, struct sched_param *param);
typedef int (* ma_pthread_attr_getschedparam_proc)(const pthread_attr_t *attr, struct sched_param *param);
typedef int (* ma_pthread_attr_setschedparam_proc)(pthread_attr_t *attr, const struct sched_param *param);
typedef int (* ma_pthread_attr_setschedparam_proc)(pthread_attr_t *attr, const struct sched_param *param);
static ma_result ma_thread_create__posix(ma_
context* pContext, ma_thread* pThread
, ma_thread_entry_proc entryProc, void* pData)
static ma_result ma_thread_create__posix(ma_
thread* pThread, ma_thread_priority priority
, ma_thread_entry_proc entryProc, void* pData)
{
{
int result;
int result;
pthread_attr_t* pAttr = NULL;
pthread_attr_t* pAttr = NULL;
...
@@ -7851,17 +7851,17 @@ static ma_result ma_thread_create__posix(ma_context* pContext, ma_thread* pThrea
...
@@ -7851,17 +7851,17 @@ static ma_result ma_thread_create__posix(ma_context* pContext, ma_thread* pThrea
#if !defined(__EMSCRIPTEN__)
#if !defined(__EMSCRIPTEN__)
/* Try setting the thread priority. It's not critical if anything fails here. */
/* Try setting the thread priority. It's not critical if anything fails here. */
pthread_attr_t attr;
pthread_attr_t attr;
if (
((ma_pthread_attr_init_proc)pContext->posix.pthread_attr_init)
(&attr) == 0) {
if (
pthread_attr_init
(&attr) == 0) {
int scheduler = -1;
int scheduler = -1;
if (p
Context->threadP
riority == ma_thread_priority_idle) {
if (priority == ma_thread_priority_idle) {
#ifdef SCHED_IDLE
#ifdef SCHED_IDLE
if (
((ma_pthread_attr_setschedpolicy_proc)pContext->posix.pthread_attr_setschedpolicy)
(&attr, SCHED_IDLE) == 0) {
if (
pthread_attr_setschedpolicy
(&attr, SCHED_IDLE) == 0) {
scheduler = SCHED_IDLE;
scheduler = SCHED_IDLE;
}
}
#endif
#endif
} else if (p
Context->threadP
riority == ma_thread_priority_realtime) {
} else if (priority == ma_thread_priority_realtime) {
#ifdef SCHED_FIFO
#ifdef SCHED_FIFO
if (
((ma_pthread_attr_setschedpolicy_proc)pContext->posix.pthread_attr_setschedpolicy)
(&attr, SCHED_FIFO) == 0) {
if (
pthread_attr_setschedpolicy
(&attr, SCHED_FIFO) == 0) {
scheduler = SCHED_FIFO;
scheduler = SCHED_FIFO;
}
}
#endif
#endif
...
@@ -7877,13 +7877,13 @@ static ma_result ma_thread_create__posix(ma_context* pContext, ma_thread* pThrea
...
@@ -7877,13 +7877,13 @@ static ma_result ma_thread_create__posix(ma_context* pContext, ma_thread* pThrea
int priorityStep = (priorityMax - priorityMin) / 7; /* 7 = number of priorities supported by miniaudio. */
int priorityStep = (priorityMax - priorityMin) / 7; /* 7 = number of priorities supported by miniaudio. */
struct sched_param sched;
struct sched_param sched;
if (
((ma_pthread_attr_getschedparam_proc)pContext->posix.pthread_attr_getschedparam)
(&attr, &sched) == 0) {
if (
pthread_attr_getschedparam
(&attr, &sched) == 0) {
if (p
Context->threadP
riority == ma_thread_priority_idle) {
if (priority == ma_thread_priority_idle) {
sched.sched_priority = priorityMin;
sched.sched_priority = priorityMin;
} else if (p
Context->threadP
riority == ma_thread_priority_realtime) {
} else if (priority == ma_thread_priority_realtime) {
sched.sched_priority = priorityMax;
sched.sched_priority = priorityMax;
} else {
} else {
sched.sched_priority += ((int)p
Context->threadP
riority + 5) * priorityStep; /* +5 because the lowest priority is -5. */
sched.sched_priority += ((int)priority + 5) * priorityStep; /* +5 because the lowest priority is -5. */
if (sched.sched_priority < priorityMin) {
if (sched.sched_priority < priorityMin) {
sched.sched_priority = priorityMin;
sched.sched_priority = priorityMin;
}
}
...
@@ -7892,17 +7892,17 @@ static ma_result ma_thread_create__posix(ma_context* pContext, ma_thread* pThrea
...
@@ -7892,17 +7892,17 @@ static ma_result ma_thread_create__posix(ma_context* pContext, ma_thread* pThrea
}
}
}
}
if (
((ma_pthread_attr_setschedparam_proc)pContext->posix.pthread_attr_setschedparam)
(&attr, &sched) == 0) {
if (
pthread_attr_setschedparam
(&attr, &sched) == 0) {
pAttr = &attr;
pAttr = &attr;
}
}
}
}
}
}
((ma_pthread_attr_destroy_proc)pContext->posix.pthread_attr_destroy)
(&attr);
pthread_attr_destroy
(&attr);
}
}
#endif
#endif
result =
((ma_pthread_create_proc)pContext->posix.pthread_create)
(&pThread->posix.thread, pAttr, entryProc, pData);
result =
pthread_create
(&pThread->posix.thread, pAttr, entryProc, pData);
if (result != 0) {
if (result != 0) {
return ma_result_from_errno(result);
return ma_result_from_errno(result);
}
}
...
@@ -7912,7 +7912,7 @@ static ma_result ma_thread_create__posix(ma_context* pContext, ma_thread* pThrea
...
@@ -7912,7 +7912,7 @@ static ma_result ma_thread_create__posix(ma_context* pContext, ma_thread* pThrea
static void ma_thread_wait__posix(ma_thread* pThread)
static void ma_thread_wait__posix(ma_thread* pThread)
{
{
((ma_pthread_join_proc)pThread->pContext->posix.pthread_join)
(pThread->posix.thread, NULL);
pthread_join
(pThread->posix.thread, NULL);
}
}
#if !defined(MA_EMSCRIPTEN)
#if !defined(MA_EMSCRIPTEN)
...
@@ -8048,19 +8048,17 @@ static ma_bool32 ma_semaphore_release__posix(ma_semaphore* pSemaphore)
...
@@ -8048,19 +8048,17 @@ static ma_bool32 ma_semaphore_release__posix(ma_semaphore* pSemaphore)
}
}
#endif
#endif
static ma_result ma_thread_create(ma_
context* pContext, ma_thread* pThread
, ma_thread_entry_proc entryProc, void* pData)
static ma_result ma_thread_create(ma_
thread* pThread, ma_thread_priority priority
, ma_thread_entry_proc entryProc, void* pData)
{
{
if (p
Context == NULL || p
Thread == NULL || entryProc == NULL) {
if (pThread == NULL || entryProc == NULL) {
return MA_FALSE;
return MA_FALSE;
}
}
pThread->pContext = pContext;
#ifdef MA_WIN32
#ifdef MA_WIN32
return ma_thread_create__win32(p
Context, pThread
, entryProc, pData);
return ma_thread_create__win32(p
Thread, priority
, entryProc, pData);
#endif
#endif
#ifdef MA_POSIX
#ifdef MA_POSIX
return ma_thread_create__posix(p
Context, pThread
, entryProc, pData);
return ma_thread_create__posix(p
Thread, priority
, entryProc, pData);
#endif
#endif
}
}
...
@@ -9657,7 +9655,7 @@ static ma_result ma_device_init__null(ma_context* pContext, const ma_device_conf
...
@@ -9657,7 +9655,7 @@ static ma_result ma_device_init__null(ma_context* pContext, const ma_device_conf
return result;
return result;
}
}
result = ma_thread_create(
pContext, &pDevice->thread
, ma_device_thread__null, pDevice);
result = ma_thread_create(
&pDevice->thread, pContext->threadPriority
, ma_device_thread__null, pDevice);
if (result != MA_SUCCESS) {
if (result != MA_SUCCESS) {
return result;
return result;
}
}
...
@@ -30444,7 +30442,7 @@ MA_API ma_result ma_device_init(ma_context* pContext, const ma_device_config* pC
...
@@ -30444,7 +30442,7 @@ MA_API ma_result ma_device_init(ma_context* pContext, const ma_device_config* pC
/* Some backends don't require the worker thread. */
/* Some backends don't require the worker thread. */
if (!ma_context_is_backend_asynchronous(pContext)) {
if (!ma_context_is_backend_asynchronous(pContext)) {
/* The worker thread. */
/* The worker thread. */
result = ma_thread_create(
pContext, &pDevice->thread
, ma_worker_thread, pDevice);
result = ma_thread_create(
&pDevice->thread, pContext->threadPriority
, ma_worker_thread, pDevice);
if (result != MA_SUCCESS) {
if (result != MA_SUCCESS) {
ma_device_uninit(pDevice);
ma_device_uninit(pDevice);
return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "Failed to create worker thread.", result);
return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "Failed to create worker thread.", result);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment