From dd7f62059c2ae52b5c05fdbe1b6b5d5fa5bc1b03 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 16 Feb 2017 15:52:00 +0100 Subject: Fix a race in QFreeList The _next variable need the acquire and release fence in next() to synchronize with the equivalent operations in release() (which already have the them) The ordering on the _v[block] is not enough as this does not synchronize the same object. Task-number: QTBUG-58917 Change-Id: I17cc39e6791433348b6227363dbea92bcf03700d Reviewed-by: David Faure Reviewed-by: Thiago Macieira --- src/corelib/tools/qfreelist_p.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib/tools/qfreelist_p.h') diff --git a/src/corelib/tools/qfreelist_p.h b/src/corelib/tools/qfreelist_p.h index c3efc41d62..a8d1132d06 100644 --- a/src/corelib/tools/qfreelist_p.h +++ b/src/corelib/tools/qfreelist_p.h @@ -237,7 +237,7 @@ inline int QFreeList::next() int id, newid, at; ElementType *v; do { - id = _next.load(); + id = _next.loadAcquire(); at = id & ConstantsType::IndexMask; const int block = blockfor(at); @@ -254,7 +254,7 @@ inline int QFreeList::next() } newid = v[at].next.load() | (id & ~ConstantsType::IndexMask); - } while (!_next.testAndSetRelaxed(id, newid)); + } while (!_next.testAndSetRelease(id, newid)); // qDebug("QFreeList::next(): returning %d (_next now %d, serial %d)", // id & ConstantsType::IndexMask, // newid & ConstantsType::IndexMask, -- cgit v1.2.3