[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / content / common / gpu / sync_point_manager.h
blob77a4e6d0b75b5fce4c093b1442b9c7da5e8ff9d2
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 CONTENT_COMMON_GPU_SYNC_POINT_MANAGER_H_
6 #define CONTENT_COMMON_GPU_SYNC_POINT_MANAGER_H_
8 #include <vector>
10 #include "base/callback.h"
11 #include "base/containers/hash_tables.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/synchronization/lock.h"
14 #include "base/threading/thread_checker.h"
16 namespace content {
18 // This class manages the sync points, which allow cross-channel
19 // synchronization.
20 class SyncPointManager : public base::RefCountedThreadSafe<SyncPointManager> {
21 public:
22 SyncPointManager();
24 // Generates a sync point, returning its ID. This can me called on any thread.
25 // IDs start at a random number. Never return 0.
26 uint32 GenerateSyncPoint();
28 // Retires a sync point. This will call all the registered callbacks for this
29 // sync point. This can only be called on the main thread.
30 void RetireSyncPoint(uint32 sync_point);
32 // Adds a callback to the sync point. The callback will be called when the
33 // sync point is retired, or immediately (from within that function) if the
34 // sync point was already retired (or not created yet). This can only be
35 // called on the main thread.
36 void AddSyncPointCallback(uint32 sync_point, const base::Closure& callback);
38 bool IsSyncPointRetired(uint32 sync_point);
40 private:
41 friend class base::RefCountedThreadSafe<SyncPointManager>;
42 typedef std::vector<base::Closure> ClosureList;
43 typedef base::hash_map<uint32, ClosureList > SyncPointMap;
45 ~SyncPointManager();
47 base::ThreadChecker thread_checker_;
49 // Protects the 2 fields below. Note: callbacks shouldn't be called with this
50 // held.
51 base::Lock lock_;
52 SyncPointMap sync_point_map_;
53 uint32 next_sync_point_;
55 DISALLOW_COPY_AND_ASSIGN(SyncPointManager);
58 } // namespace content
60 #endif // CONTENT_COMMON_GPU_SYNC_POINT_MANAGER_H_