OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "gpu/command_buffer/client/atomicops.h" | |
6 | |
7 #include "base/logging.h" | |
8 | |
9 #if !defined(__native_client__) | |
10 #include "base/atomicops.h" | |
11 #include "base/synchronization/lock.h" | |
12 #else | |
13 #include <pthread.h> | |
14 #endif | |
15 | |
16 namespace gpu { | |
17 | |
18 #if defined(__native_client__) | |
19 | |
20 class LockImpl { | |
21 public: | |
22 LockImpl() | |
23 : acquired_(false) { | |
24 pthread_mutex_init(&mutex_, NULL); | |
25 } | |
26 | |
27 ~LockImpl() { | |
28 pthread_mutex_destroy(&mutex_); | |
29 } | |
30 | |
31 void Acquire() { | |
32 pthread_mutex_lock(&mutex_); | |
33 acquired_ = true; | |
34 } | |
35 | |
36 void Release() { | |
37 DCHECK(acquired_); | |
38 acquired_ = false; | |
39 pthread_mutex_unlock(&mutex_); | |
40 } | |
41 | |
42 bool Try() { | |
43 bool acquired = pthread_mutex_trylock(&mutex_) == 0; | |
44 if (acquired) { | |
45 acquired_ = true; | |
46 } | |
47 return acquired; | |
48 } | |
49 | |
50 void AssertAcquired() const { | |
51 DCHECK(acquired_); | |
52 } | |
53 | |
54 private: | |
55 bool acquired_; | |
56 pthread_mutex_t mutex_; | |
57 | |
58 DISALLOW_COPY_AND_ASSIGN(LockImpl); | |
59 }; | |
60 | |
61 #else // !__native_client__ | |
62 | |
63 class LockImpl : public base::Lock { | |
64 }; | |
65 | |
66 #endif // !__native_client__ | |
67 | |
68 Lock::Lock() | |
69 : lock_(new LockImpl()) { | |
70 } | |
71 | |
72 Lock::~Lock() { | |
73 } | |
74 | |
75 void Lock::Acquire() { | |
76 lock_->Acquire(); | |
77 } | |
78 | |
79 void Lock::Release() { | |
80 lock_->Release(); | |
81 } | |
82 | |
83 bool Lock::Try() { | |
84 return lock_->Try(); | |
85 } | |
86 | |
87 void Lock::AssertAcquired() const { | |
88 return lock_->AssertAcquired(); | |
89 } | |
90 | |
91 } // namespace gpu | |
92 | |
OLD | NEW |