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

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

Issue 21087012: Simplify implementation of Mutex. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix unit test. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform-solaris.cc ('k') | src/sampler.cc » ('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 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 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 } 1698 }
1699 1699
1700 1700
1701 1701
1702 void Thread::YieldCPU() { 1702 void Thread::YieldCPU() {
1703 Sleep(0); 1703 Sleep(0);
1704 } 1704 }
1705 1705
1706 1706
1707 // ---------------------------------------------------------------------------- 1707 // ----------------------------------------------------------------------------
1708 // Win32 mutex support.
1709 //
1710 // On Win32 mutexes are implemented using CRITICAL_SECTION objects. These are
1711 // faster than Win32 Mutex objects because they are implemented using user mode
1712 // atomic instructions. Therefore we only do ring transitions if there is lock
1713 // contention.
1714
1715 class Win32Mutex : public Mutex {
1716 public:
1717 Win32Mutex() { InitializeCriticalSection(&cs_); }
1718
1719 virtual ~Win32Mutex() { DeleteCriticalSection(&cs_); }
1720
1721 virtual int Lock() {
1722 EnterCriticalSection(&cs_);
1723 return 0;
1724 }
1725
1726 virtual int Unlock() {
1727 LeaveCriticalSection(&cs_);
1728 return 0;
1729 }
1730
1731
1732 virtual bool TryLock() {
1733 // Returns non-zero if critical section is entered successfully entered.
1734 return TryEnterCriticalSection(&cs_);
1735 }
1736
1737 private:
1738 CRITICAL_SECTION cs_; // Critical section used for mutex
1739 };
1740
1741
1742 Mutex* OS::CreateMutex() {
1743 return new Win32Mutex();
1744 }
1745
1746
1747 // ----------------------------------------------------------------------------
1748 // Win32 semaphore support. 1708 // Win32 semaphore support.
1749 // 1709 //
1750 // On Win32 semaphores are implemented using Win32 Semaphore objects. The 1710 // On Win32 semaphores are implemented using Win32 Semaphore objects. The
1751 // semaphores are anonymous. Also, the semaphores are initialized to have 1711 // semaphores are anonymous. Also, the semaphores are initialized to have
1752 // no upper limit on count. 1712 // no upper limit on count.
1753 1713
1754 1714
1755 class Win32Semaphore : public Semaphore { 1715 class Win32Semaphore : public Semaphore {
1756 public: 1716 public:
1757 explicit Win32Semaphore(int count) { 1717 explicit Win32Semaphore(int count) {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1980 1940
1981 1941
1982 void OS::SetUp() { 1942 void OS::SetUp() {
1983 // Seed the random number generator. 1943 // Seed the random number generator.
1984 // Convert the current time to a 64-bit integer first, before converting it 1944 // Convert the current time to a 64-bit integer first, before converting it
1985 // to an unsigned. Going directly can cause an overflow and the seed to be 1945 // to an unsigned. Going directly can cause an overflow and the seed to be
1986 // set to all ones. The seed will be identical for different instances that 1946 // set to all ones. The seed will be identical for different instances that
1987 // call this setup code within the same millisecond. 1947 // call this setup code within the same millisecond.
1988 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); 1948 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
1989 srand(static_cast<unsigned int>(seed)); 1949 srand(static_cast<unsigned int>(seed));
1990 limit_mutex = CreateMutex(); 1950 limit_mutex = new Mutex;
1991 } 1951 }
1992 1952
1993 1953
1994 void OS::TearDown() { 1954 void OS::TearDown() {
1995 delete limit_mutex; 1955 delete limit_mutex;
1996 } 1956 }
1997 1957
1998 1958
1999 } } // namespace v8::internal 1959 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-solaris.cc ('k') | src/sampler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698