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

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

Issue 23748003: Cleanup Semaphore class. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Build fix for Mac OS X. 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-solaris.cc ('k') | src/platform/semaphore.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 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 1598 matching lines...) Expand 10 before | Expand all | Expand 10 after
1609 } 1609 }
1610 1610
1611 1611
1612 1612
1613 void Thread::YieldCPU() { 1613 void Thread::YieldCPU() {
1614 Sleep(0); 1614 Sleep(0);
1615 } 1615 }
1616 1616
1617 1617
1618 // ---------------------------------------------------------------------------- 1618 // ----------------------------------------------------------------------------
1619 // Win32 semaphore support.
1620 //
1621 // On Win32 semaphores are implemented using Win32 Semaphore objects. The
1622 // semaphores are anonymous. Also, the semaphores are initialized to have
1623 // no upper limit on count.
1624
1625
1626 class Win32Semaphore : public Semaphore {
1627 public:
1628 explicit Win32Semaphore(int count) {
1629 sem = ::CreateSemaphoreA(NULL, count, 0x7fffffff, NULL);
1630 }
1631
1632 ~Win32Semaphore() {
1633 CloseHandle(sem);
1634 }
1635
1636 void Wait() {
1637 WaitForSingleObject(sem, INFINITE);
1638 }
1639
1640 bool Wait(int timeout) {
1641 // Timeout in Windows API is in milliseconds.
1642 DWORD millis_timeout = timeout / 1000;
1643 return WaitForSingleObject(sem, millis_timeout) != WAIT_TIMEOUT;
1644 }
1645
1646 void Signal() {
1647 LONG dummy;
1648 ReleaseSemaphore(sem, 1, &dummy);
1649 }
1650
1651 private:
1652 HANDLE sem;
1653 };
1654
1655
1656 Semaphore* OS::CreateSemaphore(int count) {
1657 return new Win32Semaphore(count);
1658 }
1659
1660
1661 // ----------------------------------------------------------------------------
1662 // Win32 socket support. 1619 // Win32 socket support.
1663 // 1620 //
1664 1621
1665 class Win32Socket : public Socket { 1622 class Win32Socket : public Socket {
1666 public: 1623 public:
1667 explicit Win32Socket() { 1624 explicit Win32Socket() {
1668 // Create the socket. 1625 // Create the socket.
1669 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 1626 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
1670 } 1627 }
1671 explicit Win32Socket(SOCKET socket): socket_(socket) { } 1628 explicit Win32Socket(SOCKET socket): socket_(socket) { }
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1861 limit_mutex = new Mutex(); 1818 limit_mutex = new Mutex();
1862 } 1819 }
1863 1820
1864 1821
1865 void OS::TearDown() { 1822 void OS::TearDown() {
1866 delete limit_mutex; 1823 delete limit_mutex;
1867 } 1824 }
1868 1825
1869 1826
1870 } } // namespace v8::internal 1827 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-solaris.cc ('k') | src/platform/semaphore.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698