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

Side by Side Diff: src/platform/mutex.cc

Issue 23548007: Import ConditionVariable class. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rename OperandSize enum names. Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform/mutex.h ('k') | src/platform/time.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 int result = pthread_mutex_trylock(mutex); 94 int result = pthread_mutex_trylock(mutex);
95 if (result == EBUSY) { 95 if (result == EBUSY) {
96 return false; 96 return false;
97 } 97 }
98 ASSERT_EQ(0, result); 98 ASSERT_EQ(0, result);
99 return true; 99 return true;
100 } 100 }
101 101
102 #elif V8_OS_WIN 102 #elif V8_OS_WIN
103 103
104 static V8_INLINE(void InitializeNativeHandle(CRITICAL_SECTION* cs)) { 104 static V8_INLINE(void InitializeNativeHandle(PCRITICAL_SECTION cs)) {
105 InitializeCriticalSection(cs); 105 InitializeCriticalSection(cs);
106 } 106 }
107 107
108 108
109 static V8_INLINE(void InitializeRecursiveNativeHandle(CRITICAL_SECTION* cs)) { 109 static V8_INLINE(void InitializeRecursiveNativeHandle(PCRITICAL_SECTION cs)) {
110 InitializeCriticalSection(cs); 110 InitializeCriticalSection(cs);
111 } 111 }
112 112
113 113
114 static V8_INLINE(void DestroyNativeHandle(CRITICAL_SECTION* cs)) { 114 static V8_INLINE(void DestroyNativeHandle(PCRITICAL_SECTION cs)) {
115 DeleteCriticalSection(cs); 115 DeleteCriticalSection(cs);
116 } 116 }
117 117
118 118
119 static V8_INLINE(void LockNativeHandle(CRITICAL_SECTION* cs)) { 119 static V8_INLINE(void LockNativeHandle(PCRITICAL_SECTION cs)) {
120 EnterCriticalSection(cs); 120 EnterCriticalSection(cs);
121 } 121 }
122 122
123 123
124 static V8_INLINE(void UnlockNativeHandle(CRITICAL_SECTION* cs)) { 124 static V8_INLINE(void UnlockNativeHandle(PCRITICAL_SECTION cs)) {
125 LeaveCriticalSection(cs); 125 LeaveCriticalSection(cs);
126 } 126 }
127 127
128 128
129 static V8_INLINE(bool TryLockNativeHandle(CRITICAL_SECTION* cs)) { 129 static V8_INLINE(bool TryLockNativeHandle(PCRITICAL_SECTION cs)) {
130 return TryEnterCriticalSection(cs); 130 return TryEnterCriticalSection(cs);
131 } 131 }
132 132
133 #endif // V8_OS_POSIX 133 #endif // V8_OS_POSIX
134 134
135 135
136 Mutex::Mutex() { 136 Mutex::Mutex() {
137 InitializeNativeHandle(&native_handle_); 137 InitializeNativeHandle(&native_handle_);
138 #ifdef DEBUG 138 #ifdef DEBUG
139 level_ = 0; 139 level_ = 0;
140 #endif 140 #endif
141 } 141 }
142 142
143 143
144 Mutex::~Mutex() { 144 Mutex::~Mutex() {
145 DestroyNativeHandle(&native_handle_); 145 DestroyNativeHandle(&native_handle_);
146 ASSERT_EQ(0, level_); 146 ASSERT_EQ(0, level_);
147 } 147 }
148 148
149 149
150 void Mutex::Lock() { 150 void Mutex::Lock() {
151 LockNativeHandle(&native_handle_); 151 LockNativeHandle(&native_handle_);
152 #ifdef DEBUG 152 AssertUnheldAndMark();
153 ASSERT_EQ(0, level_);
154 level_++;
155 #endif
156 } 153 }
157 154
158 155
159 void Mutex::Unlock() { 156 void Mutex::Unlock() {
160 #ifdef DEBUG 157 AssertHeldAndUnmark();
161 ASSERT_EQ(1, level_);
162 level_--;
163 #endif
164 UnlockNativeHandle(&native_handle_); 158 UnlockNativeHandle(&native_handle_);
165 } 159 }
166 160
167 161
168 bool Mutex::TryLock() { 162 bool Mutex::TryLock() {
169 if (!TryLockNativeHandle(&native_handle_)) { 163 if (!TryLockNativeHandle(&native_handle_)) {
170 return false; 164 return false;
171 } 165 }
172 #ifdef DEBUG 166 AssertUnheldAndMark();
173 ASSERT_EQ(0, level_);
174 level_++;
175 #endif
176 return true; 167 return true;
177 } 168 }
178 169
179 170
180 RecursiveMutex::RecursiveMutex() { 171 RecursiveMutex::RecursiveMutex() {
181 InitializeRecursiveNativeHandle(&native_handle_); 172 InitializeRecursiveNativeHandle(&native_handle_);
182 #ifdef DEBUG 173 #ifdef DEBUG
183 level_ = 0; 174 level_ = 0;
184 #endif 175 #endif
185 } 176 }
(...skipping 28 matching lines...) Expand all
214 return false; 205 return false;
215 } 206 }
216 #ifdef DEBUG 207 #ifdef DEBUG
217 ASSERT_LE(0, level_); 208 ASSERT_LE(0, level_);
218 level_++; 209 level_++;
219 #endif 210 #endif
220 return true; 211 return true;
221 } 212 }
222 213
223 } } // namespace v8::internal 214 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform/mutex.h ('k') | src/platform/time.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698