Elim cr-checkbox
[chromium-blink-merge.git] / gpu / command_buffer / service / sync_point_manager.h
blob98e849b76ced244c3400b171d12cf513c4f4f739
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_
8 #include <vector>
10 #include "base/callback.h"
11 #include "base/containers/hash_tables.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/synchronization/condition_variable.h"
14 #include "base/synchronization/lock.h"
15 #include "gpu/gpu_export.h"
17 namespace gpu {
19 // This class manages the sync points, which allow cross-channel
20 // synchronization.
21 class GPU_EXPORT SyncPointManager {
22 public:
23 explicit SyncPointManager(bool allow_threaded_wait);
24 ~SyncPointManager();
26 // Generates a sync point, returning its ID. This can me called on any thread.
27 // IDs start at a random number. Never return 0.
28 uint32 GenerateSyncPoint();
30 // Retires a sync point. This will call all the registered callbacks for this
31 // sync point. This can only be called on the main thread.
32 void RetireSyncPoint(uint32 sync_point);
34 // Adds a callback to the sync point. The callback will be called when the
35 // sync point is retired, or immediately (from within that function) if the
36 // sync point was already retired (or not created yet). This can only be
37 // called on the main thread.
38 void AddSyncPointCallback(uint32 sync_point, const base::Closure& callback);
40 bool IsSyncPointRetired(uint32 sync_point);
42 // Block and wait until a sync point is signaled. This is only useful when
43 // the sync point is signaled on another thread.
44 void WaitSyncPoint(uint32 sync_point);
46 private:
47 typedef std::vector<base::Closure> ClosureList;
48 typedef base::hash_map<uint32, ClosureList> SyncPointMap;
51 bool IsSyncPointRetiredLocked(uint32 sync_point);
53 const bool allow_threaded_wait_;
55 // Protects the 2 fields below. Note: callbacks shouldn't be called with this
56 // held.
57 base::Lock lock_;
58 SyncPointMap sync_point_map_;
59 uint32 next_sync_point_;
60 base::ConditionVariable retire_cond_var_;
62 DISALLOW_COPY_AND_ASSIGN(SyncPointManager);
65 } // namespace gpu
67 #endif // GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_