OSDN Git Service

Use atomic operations to specify shared memory access order
authorAlexis Hetu <sugoi@google.com>
Wed, 20 Sep 2017 15:24:52 +0000 (11:24 -0400)
committerAlexis Hétu <sugoi@google.com>
Thu, 21 Sep 2017 18:02:59 +0000 (18:02 +0000)
commit6b164c337c647c0898a0e54cdb260f0ee91ae4a6
tree050ee4247b8bb58d4b8bb0bcb532b1c6e67e63be
parent0c5035bec3bfdd41c38b55c7880e63bea8347e43
Use atomic operations to specify shared memory access order

TSAN detected many data race errors in the SwiftShader Renderer
class. x86 has a strong memory ordering model which guarantees
that changes are observed in the same order by other threads.
However, C++ does not provide such guarantees unless specified
using atomic operations. In order to fix these, a new AtomicInt
class was added which is a basically a wrapper class for
std::atomic<int> and which only exposes the portion of the API
required by SwiftShader.

Since std::atomic isn't available on older versions of Android,
a fallback class was implemented without using std::atomic, which
is closer to the previous implementation. Both classes appear to
work properly after performing a few dEQP tests. Both also perform
similarly.

A few minor changes were made in order to attempt to reduce the use
of atomic integer operations when possible.

Change-Id: Ife6d3a2b6113346f8f8163b692e79c2a0e03b22f
Reviewed-on: https://swiftshader-review.googlesource.com/12308
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
src/Common/Thread.hpp
src/Renderer/Clipper.cpp
src/Renderer/Renderer.cpp
src/Renderer/Renderer.hpp
src/Renderer/Surface.hpp