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

Side by Side Diff: src/platform-win32.cc

Issue 23625003: Cleanup Mutex and related classes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 // determining that pointers are outside the heap (used mostly in assertions 839 // determining that pointers are outside the heap (used mostly in assertions
840 // and verification). The estimate is conservative, i.e., not all addresses in 840 // and verification). The estimate is conservative, i.e., not all addresses in
841 // 'allocated' space are actually allocated to our heap. The range is 841 // 'allocated' space are actually allocated to our heap. The range is
842 // [lowest, highest), inclusive on the low and and exclusive on the high end. 842 // [lowest, highest), inclusive on the low and and exclusive on the high end.
843 static void* lowest_ever_allocated = reinterpret_cast<void*>(-1); 843 static void* lowest_ever_allocated = reinterpret_cast<void*>(-1);
844 static void* highest_ever_allocated = reinterpret_cast<void*>(0); 844 static void* highest_ever_allocated = reinterpret_cast<void*>(0);
845 845
846 846
847 static void UpdateAllocatedSpaceLimits(void* address, int size) { 847 static void UpdateAllocatedSpaceLimits(void* address, int size) {
848 ASSERT(limit_mutex != NULL); 848 ASSERT(limit_mutex != NULL);
849 ScopedLock lock(limit_mutex); 849 LockGuard<Mutex> lock_guard(limit_mutex);
850 850
851 lowest_ever_allocated = Min(lowest_ever_allocated, address); 851 lowest_ever_allocated = Min(lowest_ever_allocated, address);
852 highest_ever_allocated = 852 highest_ever_allocated =
853 Max(highest_ever_allocated, 853 Max(highest_ever_allocated,
854 reinterpret_cast<void*>(reinterpret_cast<char*>(address) + size)); 854 reinterpret_cast<void*>(reinterpret_cast<char*>(address) + size));
855 } 855 }
856 856
857 857
858 bool OS::IsOutsideAllocatedSpace(void* pointer) { 858 bool OS::IsOutsideAllocatedSpace(void* pointer) {
859 if (pointer < lowest_ever_allocated || pointer >= highest_ever_allocated) 859 if (pointer < lowest_ever_allocated || pointer >= highest_ever_allocated)
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 } 1701 }
1702 1702
1703 1703
1704 1704
1705 void Thread::YieldCPU() { 1705 void Thread::YieldCPU() {
1706 Sleep(0); 1706 Sleep(0);
1707 } 1707 }
1708 1708
1709 1709
1710 // ---------------------------------------------------------------------------- 1710 // ----------------------------------------------------------------------------
1711 // Win32 mutex support.
1712 //
1713 // On Win32 mutexes are implemented using CRITICAL_SECTION objects. These are
1714 // faster than Win32 Mutex objects because they are implemented using user mode
1715 // atomic instructions. Therefore we only do ring transitions if there is lock
1716 // contention.
1717
1718 class Win32Mutex : public Mutex {
1719 public:
1720 Win32Mutex() { InitializeCriticalSection(&cs_); }
1721
1722 virtual ~Win32Mutex() { DeleteCriticalSection(&cs_); }
1723
1724 virtual int Lock() {
1725 EnterCriticalSection(&cs_);
1726 return 0;
1727 }
1728
1729 virtual int Unlock() {
1730 LeaveCriticalSection(&cs_);
1731 return 0;
1732 }
1733
1734
1735 virtual bool TryLock() {
1736 // Returns non-zero if critical section is entered successfully entered.
1737 return TryEnterCriticalSection(&cs_);
1738 }
1739
1740 private:
1741 CRITICAL_SECTION cs_; // Critical section used for mutex
1742 };
1743
1744
1745 Mutex* OS::CreateMutex() {
1746 return new Win32Mutex();
1747 }
1748
1749
1750 // ----------------------------------------------------------------------------
1751 // Win32 semaphore support. 1711 // Win32 semaphore support.
1752 // 1712 //
1753 // On Win32 semaphores are implemented using Win32 Semaphore objects. The 1713 // On Win32 semaphores are implemented using Win32 Semaphore objects. The
1754 // semaphores are anonymous. Also, the semaphores are initialized to have 1714 // semaphores are anonymous. Also, the semaphores are initialized to have
1755 // no upper limit on count. 1715 // no upper limit on count.
1756 1716
1757 1717
1758 class Win32Semaphore : public Semaphore { 1718 class Win32Semaphore : public Semaphore {
1759 public: 1719 public:
1760 explicit Win32Semaphore(int count) { 1720 explicit Win32Semaphore(int count) {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1983 1943
1984 1944
1985 void OS::SetUp() { 1945 void OS::SetUp() {
1986 // Seed the random number generator. 1946 // Seed the random number generator.
1987 // Convert the current time to a 64-bit integer first, before converting it 1947 // Convert the current time to a 64-bit integer first, before converting it
1988 // to an unsigned. Going directly can cause an overflow and the seed to be 1948 // to an unsigned. Going directly can cause an overflow and the seed to be
1989 // set to all ones. The seed will be identical for different instances that 1949 // set to all ones. The seed will be identical for different instances that
1990 // call this setup code within the same millisecond. 1950 // call this setup code within the same millisecond.
1991 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); 1951 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
1992 srand(static_cast<unsigned int>(seed)); 1952 srand(static_cast<unsigned int>(seed));
1993 limit_mutex = CreateMutex(); 1953 limit_mutex = new Mutex();
1994 } 1954 }
1995 1955
1996 1956
1997 void OS::TearDown() { 1957 void OS::TearDown() {
1998 delete limit_mutex; 1958 delete limit_mutex;
1999 } 1959 }
2000 1960
2001 1961
2002 } } // namespace v8::internal 1962 } } // namespace v8::internal
OLDNEW
« src/isolate.cc ('K') | « src/platform-solaris.cc ('k') | src/sampler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698