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
68f94846
Commit
68f94846
authored
Aug 14, 2021
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Try fixing a few issues with the lock-free job queue.
parent
6972cb53
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
5 deletions
+20
-5
miniaudio.h
miniaudio.h
+20
-5
No files found.
miniaudio.h
View file @
68f94846
...
@@ -58281,6 +58281,15 @@ static MA_INLINE ma_uint64 ma_resource_manager_job_toc_to_allocation(ma_uint64 t
...
@@ -58281,6 +58281,15 @@ static MA_INLINE ma_uint64 ma_resource_manager_job_toc_to_allocation(ma_uint64 t
return ((ma_uint64)ma_resource_manager_job_extract_refcount(toc) << 32) | (ma_uint64)ma_resource_manager_job_extract_slot(toc);
return ((ma_uint64)ma_resource_manager_job_extract_refcount(toc) << 32) | (ma_uint64)ma_resource_manager_job_extract_slot(toc);
}
}
static MA_INLINE ma_uint64 ma_resource_manager_job_set_refcount(ma_uint64 toc, ma_uint32 refcount)
{
/* Clear the reference count first. */
toc = toc & ~((ma_uint64)0xFFFFFFFF << 32);
toc = toc | ((ma_uint64)refcount << 32);
return toc;
}
MA_API ma_resource_manager_job ma_resource_manager_job_init(ma_uint16 code)
MA_API ma_resource_manager_job ma_resource_manager_job_init(ma_uint16 code)
{
{
...
@@ -58486,6 +58495,12 @@ MA_API void ma_resource_manager_job_queue_uninit(ma_resource_manager_job_queue*
...
@@ -58486,6 +58495,12 @@ MA_API void ma_resource_manager_job_queue_uninit(ma_resource_manager_job_queue*
}
}
}
}
static ma_bool32 ma_resource_manager_job_queue_cas(volatile ma_uint64* dst, ma_uint64 expected, ma_uint64 desired)
{
/* The new counter is taken from the expected value. */
return c89atomic_compare_and_swap_64(dst, expected, ma_resource_manager_job_set_refcount(desired, ma_resource_manager_job_extract_refcount(expected) + 1)) == expected;
}
MA_API ma_result ma_resource_manager_job_queue_post(ma_resource_manager_job_queue* pQueue, const ma_resource_manager_job* pJob)
MA_API ma_result ma_resource_manager_job_queue_post(ma_resource_manager_job_queue* pQueue, const ma_resource_manager_job* pJob)
{
{
/*
/*
...
@@ -58522,15 +58537,15 @@ MA_API ma_result ma_resource_manager_job_queue_post(ma_resource_manager_job_queu
...
@@ -58522,15 +58537,15 @@ MA_API ma_result ma_resource_manager_job_queue_post(ma_resource_manager_job_queu
if (ma_resource_manager_job_toc_to_allocation(tail) == ma_resource_manager_job_toc_to_allocation(c89atomic_load_64(&pQueue->tail))) {
if (ma_resource_manager_job_toc_to_allocation(tail) == ma_resource_manager_job_toc_to_allocation(c89atomic_load_64(&pQueue->tail))) {
if (ma_resource_manager_job_extract_slot(next) == 0xFFFF) {
if (ma_resource_manager_job_extract_slot(next) == 0xFFFF) {
if (
c89atomic_compare_and_swap_64(&pQueue->pJobs[ma_resource_manager_job_extract_slot(tail)].next, next, slot) == next
) {
if (
ma_resource_manager_job_queue_cas(&pQueue->pJobs[ma_resource_manager_job_extract_slot(tail)].next, next, slot)
) {
break;
break;
}
}
} else {
} else {
c89atomic_compare_and_swap_64(&pQueue->tail, tail, next
);
ma_resource_manager_job_queue_cas(&pQueue->tail, tail, ma_resource_manager_job_extract_slot(next)
);
}
}
}
}
}
}
c89atomic_compare_and_swap_64
(&pQueue->tail, tail, slot);
ma_resource_manager_job_queue_cas
(&pQueue->tail, tail, slot);
/* Signal the semaphore as the last step if we're using synchronous mode. */
/* Signal the semaphore as the last step if we're using synchronous mode. */
...
@@ -58583,10 +58598,10 @@ MA_API ma_result ma_resource_manager_job_queue_next(ma_resource_manager_job_queu
...
@@ -58583,10 +58598,10 @@ MA_API ma_result ma_resource_manager_job_queue_next(ma_resource_manager_job_queu
if (ma_resource_manager_job_extract_slot(next) == 0xFFFF) {
if (ma_resource_manager_job_extract_slot(next) == 0xFFFF) {
return MA_NO_DATA_AVAILABLE;
return MA_NO_DATA_AVAILABLE;
}
}
c89atomic_compare_and_swap_64
(&pQueue->tail, tail, next);
ma_resource_manager_job_queue_cas
(&pQueue->tail, tail, next);
} else {
} else {
*pJob = pQueue->pJobs[ma_resource_manager_job_extract_slot(next)];
*pJob = pQueue->pJobs[ma_resource_manager_job_extract_slot(next)];
if (
c89atomic_compare_and_swap_64(&pQueue->head, head, next) == head
) {
if (
ma_resource_manager_job_queue_cas(&pQueue->head, head, next)
) {
break;
break;
}
}
}
}
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