From 682231bb0fea0f1f904de823f0aa3aa4851378b4 Mon Sep 17 00:00:00 2001 From: Matthew Gregan Date: Wed, 5 Dec 2012 09:33:43 +1300 Subject: winmm: process work items in batches to avoid stream starvation. --- src/cubeb_winmm.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cubeb_winmm.c b/src/cubeb_winmm.c index 9615ef7..0afb3a5 100644 --- a/src/cubeb_winmm.c +++ b/src/cubeb_winmm.c @@ -169,9 +169,15 @@ cubeb_buffer_thread(void * user_ptr) rv = WaitForSingleObject(ctx->event, INFINITE); assert(rv == WAIT_OBJECT_0); - while ((item = InterlockedPopEntrySList(ctx->work)) != NULL) { - cubeb_refill_stream(((struct cubeb_stream_item *) item)->stream); - _aligned_free(item); + /* Process work items in batches so that a single stream can't + starve the others by continuously adding new work to the top of + the work item stack. */ + item = InterlockedFlushSList(ctx->work); + while (item != NULL) { + PSLIST_ENTRY tmp = item; + cubeb_refill_stream(((struct cubeb_stream_item *) tmp)->stream); + item = item->Next; + _aligned_free(tmp); } if (ctx->shutdown) { -- cgit v1.2.3