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

Unified Diff: Source/wtf/SpinLock.h

Issue 21666003: Enhancements to PartitionAlloc to support threading and arbitrary allocation sizes. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Review comments. Created 7 years, 4 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
« no previous file with comments | « Source/wtf/PartitionAllocTest.cpp ('k') | Source/wtf/SpinLockTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/SpinLock.h
diff --git a/Source/wtf/testing/WTFTestHelpers.h b/Source/wtf/SpinLock.h
similarity index 74%
copy from Source/wtf/testing/WTFTestHelpers.h
copy to Source/wtf/SpinLock.h
index 7d8bb3193fbac7f0352eb63067326f4c8b9eea8c..ae2f11675f7e006b22994b0de6695d700f2e4dda 100644
--- a/Source/wtf/testing/WTFTestHelpers.h
+++ b/Source/wtf/SpinLock.h
@@ -28,29 +28,32 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef WTFTestHelpers_h
-#define WTFTestHelpers_h
+#ifndef WTF_SpinLock_h
+#define WTF_SpinLock_h
-#include "wtf/text/CString.h"
-#include "wtf/text/WTFString.h"
+// DESCRIPTION
+// spinLockLock() and spinLockUnlock() are simple spinlock primitives based on
+// the standard CPU primitive of atomic increment and decrement of an int at
+// a given memory address.
-#include <ostream> // NOLINT
+#include "wtf/Atomics.h"
namespace WTF {
-// Output stream operator so gTest's macros work with WebCore strings.
-static std::ostream& operator<<(std::ostream& out, const String& str)
+ALWAYS_INLINE void spinLockLock(int volatile* lock)
{
- return str.isEmpty() ? out : out << str.utf8().data();
+ while (atomicIncrement(lock) != 1)
+ atomicDecrement(lock);
}
-// Output stream operator so gtest can print WTF::CString.
-static std::ostream& operator<<(std::ostream& out, const CString& str)
+ALWAYS_INLINE void spinLockUnlock(int volatile* lock)
{
- return out << str.data();
+ atomicDecrement(lock);
}
} // namespace WTF
+using WTF::spinLockLock;
+using WTF::spinLockUnlock;
-#endif // WTFTestHelpers_h
+#endif // WTF_PartitionAlloc_h
« no previous file with comments | « Source/wtf/PartitionAllocTest.cpp ('k') | Source/wtf/SpinLockTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698