From dc7e61e60fb6957717a978131c3dc2dca58cf44c Mon Sep 17 00:00:00 2001 From: midipix Date: Thu, 9 Aug 2018 04:14:31 -0400 Subject: __ntapi_blt_possess(): use an inlined cmpxchg loop. --- src/blitter/ntapi_blt_block.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/blitter/ntapi_blt_block.c b/src/blitter/ntapi_blt_block.c index 12dc2f7..803e723 100644 --- a/src/blitter/ntapi_blt_block.c +++ b/src/blitter/ntapi_blt_block.c @@ -135,14 +135,21 @@ int32_t __fastcall __ntapi_blt_possess( size_t byte; uintptr_t test; uintptr_t mask; + uintptr_t cmp; + uintptr_t xchg; bit = *blkid % (8*sizeof(size_t)); byte = *blkid / (8*sizeof(size_t)); + mask = (uintptr_t)1 << bit; + + do { + cmp = blitter->bitmap[byte]; + xchg = cmp & ~mask; - mask = ((uintptr_t)1 << bit); - test = at_locked_and( - (intptr_t *)&blitter->bitmap[byte], - ~mask); + test = at_locked_cas( + (intptr_t *)&blitter->bitmap[byte], + cmp,xchg); + } while (test != cmp); if (test & mask) { at_locked_dec(&blitter->info.blocks_avail); -- cgit v1.2.3