Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(498)

Unified Diff: gpu/command_buffer/service/query_manager.cc

Issue 184223003: gpu: Use explicit atomics instead of assuming that 32bit read/writes are atomic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: re-upload Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: gpu/command_buffer/service/query_manager.cc
diff --git a/gpu/command_buffer/service/query_manager.cc b/gpu/command_buffer/service/query_manager.cc
index 85e273c6c3a02b570cc87b634823c577eaaf63a8..44fb8bb6ffeca49e6771a3f2236a5c4bd69fa037 100644
--- a/gpu/command_buffer/service/query_manager.cc
+++ b/gpu/command_buffer/service/query_manager.cc
@@ -24,7 +24,7 @@ namespace {
class AsyncPixelTransferCompletionObserverImpl
: public AsyncPixelTransferCompletionObserver {
public:
- AsyncPixelTransferCompletionObserverImpl(uint32 submit_count)
+ AsyncPixelTransferCompletionObserverImpl(int32 submit_count)
: submit_count_(submit_count),
cancelled_(false) {}
@@ -42,17 +42,14 @@ class AsyncPixelTransferCompletionObserverImpl
mem_params.shm_data_offset;
QuerySync* sync = static_cast<QuerySync*>(data);
- // Need a MemoryBarrier here to ensure that upload completed before
- // submit_count was written to sync->process_count.
- base::subtle::MemoryBarrier();
- sync->process_count = submit_count_;
+ base::subtle::Release_Store(&sync->process_count, submit_count_);
}
}
private:
virtual ~AsyncPixelTransferCompletionObserverImpl() {}
- uint32 submit_count_;
+ int32 submit_count_;
base::Lock lock_;
bool cancelled_;
@@ -68,7 +65,7 @@ class AsyncPixelTransfersCompletedQuery
QueryManager* manager, GLenum target, int32 shm_id, uint32 shm_offset);
virtual bool Begin() OVERRIDE;
- virtual bool End(uint32 submit_count) OVERRIDE;
+ virtual bool End(int32 submit_count) OVERRIDE;
virtual bool Process() OVERRIDE;
virtual void Destroy(bool have_context) OVERRIDE;
@@ -87,7 +84,7 @@ bool AsyncPixelTransfersCompletedQuery::Begin() {
return true;
}
-bool AsyncPixelTransfersCompletedQuery::End(uint32 submit_count) {
+bool AsyncPixelTransfersCompletedQuery::End(int32 submit_count) {
AsyncMemoryParams mem_params;
// Get the real shared memory since it might need to be duped to prevent
// use-after-free of the memory.
@@ -119,7 +116,7 @@ bool AsyncPixelTransfersCompletedQuery::Process() {
// Check if completion callback has been run. sync->process_count atomicity
// is guaranteed as this is already used to notify client of a completed
// query.
- if (sync->process_count != submit_count())
+ if (base::subtle::Acquire_Load(&sync->process_count) != submit_count())
return true;
UnmarkAsPending();
@@ -145,7 +142,7 @@ class AllSamplesPassedQuery : public QueryManager::Query {
QueryManager* manager, GLenum target, int32 shm_id, uint32 shm_offset,
GLuint service_id);
virtual bool Begin() OVERRIDE;
- virtual bool End(uint32 submit_count) OVERRIDE;
+ virtual bool End(int32 submit_count) OVERRIDE;
virtual bool Process() OVERRIDE;
virtual void Destroy(bool have_context) OVERRIDE;
@@ -169,7 +166,7 @@ bool AllSamplesPassedQuery::Begin() {
return true;
}
-bool AllSamplesPassedQuery::End(uint32 submit_count) {
+bool AllSamplesPassedQuery::End(int32 submit_count) {
EndQueryHelper(target());
return AddToPendingQueue(submit_count);
}
@@ -204,7 +201,7 @@ class CommandsIssuedQuery : public QueryManager::Query {
QueryManager* manager, GLenum target, int32 shm_id, uint32 shm_offset);
virtual bool Begin() OVERRIDE;
- virtual bool End(uint32 submit_count) OVERRIDE;
+ virtual bool End(int32 submit_count) OVERRIDE;
virtual bool Process() OVERRIDE;
virtual void Destroy(bool have_context) OVERRIDE;
@@ -225,7 +222,7 @@ bool CommandsIssuedQuery::Begin() {
return true;
}
-bool CommandsIssuedQuery::End(uint32 submit_count) {
+bool CommandsIssuedQuery::End(int32 submit_count) {
base::TimeDelta elapsed = base::TimeTicks::HighResNow() - begin_time_;
MarkAsPending(submit_count);
return MarkAsCompleted(elapsed.InMicroseconds());
@@ -251,7 +248,7 @@ class CommandLatencyQuery : public QueryManager::Query {
QueryManager* manager, GLenum target, int32 shm_id, uint32 shm_offset);
virtual bool Begin() OVERRIDE;
- virtual bool End(uint32 submit_count) OVERRIDE;
+ virtual bool End(int32 submit_count) OVERRIDE;
virtual bool Process() OVERRIDE;
virtual void Destroy(bool have_context) OVERRIDE;
@@ -268,7 +265,7 @@ bool CommandLatencyQuery::Begin() {
return true;
}
-bool CommandLatencyQuery::End(uint32 submit_count) {
+bool CommandLatencyQuery::End(int32 submit_count) {
base::TimeDelta now = base::TimeTicks::HighResNow() - base::TimeTicks();
MarkAsPending(submit_count);
return MarkAsCompleted(now.InMicroseconds());
@@ -297,7 +294,7 @@ class AsyncReadPixelsCompletedQuery
QueryManager* manager, GLenum target, int32 shm_id, uint32 shm_offset);
virtual bool Begin() OVERRIDE;
- virtual bool End(uint32 submit_count) OVERRIDE;
+ virtual bool End(int32 submit_count) OVERRIDE;
virtual bool Process() OVERRIDE;
virtual void Destroy(bool have_context) OVERRIDE;
@@ -315,7 +312,7 @@ bool AsyncReadPixelsCompletedQuery::Begin() {
return true;
}
-bool AsyncReadPixelsCompletedQuery::End(uint32 submit_count) {
+bool AsyncReadPixelsCompletedQuery::End(int32 submit_count) {
if (!AddToPendingQueue(submit_count)) {
return false;
}
@@ -350,7 +347,7 @@ class GetErrorQuery : public QueryManager::Query {
QueryManager* manager, GLenum target, int32 shm_id, uint32 shm_offset);
virtual bool Begin() OVERRIDE;
- virtual bool End(uint32 submit_count) OVERRIDE;
+ virtual bool End(int32 submit_count) OVERRIDE;
virtual bool Process() OVERRIDE;
virtual void Destroy(bool have_context) OVERRIDE;
@@ -369,7 +366,7 @@ bool GetErrorQuery::Begin() {
return true;
}
-bool GetErrorQuery::End(uint32 submit_count) {
+bool GetErrorQuery::End(int32 submit_count) {
MarkAsPending(submit_count);
return MarkAsCompleted(manager()->decoder()->GetErrorState()->GetGLError());
}
@@ -563,10 +560,7 @@ bool QueryManager::Query::MarkAsCompleted(uint64 result) {
pending_ = false;
sync->result = result;
- // Need a MemoryBarrier here so that sync->result is written before
- // sync->process_count.
- base::subtle::MemoryBarrier();
- sync->process_count = submit_count_;
+ base::subtle::Release_Store(&sync->process_count, submit_count_);
return true;
}
@@ -611,7 +605,7 @@ bool QueryManager::HavePendingTransferQueries() {
return !pending_transfer_queries_.empty();
}
-bool QueryManager::AddPendingQuery(Query* query, uint32 submit_count) {
+bool QueryManager::AddPendingQuery(Query* query, int32 submit_count) {
DCHECK(query);
DCHECK(!query->IsDeleted());
if (!RemovePendingQuery(query)) {
@@ -622,7 +616,7 @@ bool QueryManager::AddPendingQuery(Query* query, uint32 submit_count) {
return true;
}
-bool QueryManager::AddPendingTransferQuery(Query* query, uint32 submit_count) {
+bool QueryManager::AddPendingTransferQuery(Query* query, int32 submit_count) {
DCHECK(query);
DCHECK(!query->IsDeleted());
if (!RemovePendingQuery(query)) {
@@ -668,7 +662,7 @@ bool QueryManager::BeginQuery(Query* query) {
return query->Begin();
}
-bool QueryManager::EndQuery(Query* query, uint32 submit_count) {
+bool QueryManager::EndQuery(Query* query, int32 submit_count) {
DCHECK(query);
if (!RemovePendingQuery(query)) {
return false;
« gpu/command_buffer/common/gles2_cmd_format.h ('K') | « gpu/command_buffer/service/query_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698