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

Side by Side Diff: test/unittests/base/platform/semaphore-unittest.cc

Issue 1088993003: Replace OVERRIDE->override and FINAL->final since we now require C++11. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 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
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <cstring> 5 #include <cstring>
6 6
7 #include "src/base/platform/platform.h" 7 #include "src/base/platform/platform.h"
8 #include "src/base/platform/semaphore.h" 8 #include "src/base/platform/semaphore.h"
9 #include "src/base/platform/time.h" 9 #include "src/base/platform/time.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace v8 { 12 namespace v8 {
13 namespace base { 13 namespace base {
14 14
15 namespace { 15 namespace {
16 16
17 static const char kAlphabet[] = "XKOAD"; 17 static const char kAlphabet[] = "XKOAD";
18 static const size_t kAlphabetSize = sizeof(kAlphabet) - 1; 18 static const size_t kAlphabetSize = sizeof(kAlphabet) - 1;
19 static const size_t kBufferSize = 987; // GCD(buffer size, alphabet size) = 1 19 static const size_t kBufferSize = 987; // GCD(buffer size, alphabet size) = 1
20 static const size_t kDataSize = kBufferSize * kAlphabetSize * 10; 20 static const size_t kDataSize = kBufferSize * kAlphabetSize * 10;
21 21
22 22
23 class ProducerThread FINAL : public Thread { 23 class ProducerThread final : public Thread {
24 public: 24 public:
25 ProducerThread(char* buffer, Semaphore* free_space, Semaphore* used_space) 25 ProducerThread(char* buffer, Semaphore* free_space, Semaphore* used_space)
26 : Thread(Options("ProducerThread")), 26 : Thread(Options("ProducerThread")),
27 buffer_(buffer), 27 buffer_(buffer),
28 free_space_(free_space), 28 free_space_(free_space),
29 used_space_(used_space) {} 29 used_space_(used_space) {}
30 virtual ~ProducerThread() {} 30 virtual ~ProducerThread() {}
31 31
32 virtual void Run() OVERRIDE { 32 virtual void Run() override {
33 for (size_t n = 0; n < kDataSize; ++n) { 33 for (size_t n = 0; n < kDataSize; ++n) {
34 free_space_->Wait(); 34 free_space_->Wait();
35 buffer_[n % kBufferSize] = kAlphabet[n % kAlphabetSize]; 35 buffer_[n % kBufferSize] = kAlphabet[n % kAlphabetSize];
36 used_space_->Signal(); 36 used_space_->Signal();
37 } 37 }
38 } 38 }
39 39
40 private: 40 private:
41 char* buffer_; 41 char* buffer_;
42 Semaphore* const free_space_; 42 Semaphore* const free_space_;
43 Semaphore* const used_space_; 43 Semaphore* const used_space_;
44 }; 44 };
45 45
46 46
47 class ConsumerThread FINAL : public Thread { 47 class ConsumerThread final : public Thread {
48 public: 48 public:
49 ConsumerThread(const char* buffer, Semaphore* free_space, 49 ConsumerThread(const char* buffer, Semaphore* free_space,
50 Semaphore* used_space) 50 Semaphore* used_space)
51 : Thread(Options("ConsumerThread")), 51 : Thread(Options("ConsumerThread")),
52 buffer_(buffer), 52 buffer_(buffer),
53 free_space_(free_space), 53 free_space_(free_space),
54 used_space_(used_space) {} 54 used_space_(used_space) {}
55 virtual ~ConsumerThread() {} 55 virtual ~ConsumerThread() {}
56 56
57 virtual void Run() OVERRIDE { 57 virtual void Run() override {
58 for (size_t n = 0; n < kDataSize; ++n) { 58 for (size_t n = 0; n < kDataSize; ++n) {
59 used_space_->Wait(); 59 used_space_->Wait();
60 EXPECT_EQ(kAlphabet[n % kAlphabetSize], buffer_[n % kBufferSize]); 60 EXPECT_EQ(kAlphabet[n % kAlphabetSize], buffer_[n % kBufferSize]);
61 free_space_->Signal(); 61 free_space_->Signal();
62 } 62 }
63 } 63 }
64 64
65 private: 65 private:
66 const char* buffer_; 66 const char* buffer_;
67 Semaphore* const free_space_; 67 Semaphore* const free_space_;
68 Semaphore* const used_space_; 68 Semaphore* const used_space_;
69 }; 69 };
70 70
71 71
72 class WaitAndSignalThread FINAL : public Thread { 72 class WaitAndSignalThread final : public Thread {
73 public: 73 public:
74 explicit WaitAndSignalThread(Semaphore* semaphore) 74 explicit WaitAndSignalThread(Semaphore* semaphore)
75 : Thread(Options("WaitAndSignalThread")), semaphore_(semaphore) {} 75 : Thread(Options("WaitAndSignalThread")), semaphore_(semaphore) {}
76 virtual ~WaitAndSignalThread() {} 76 virtual ~WaitAndSignalThread() {}
77 77
78 virtual void Run() OVERRIDE { 78 virtual void Run() override {
79 for (int n = 0; n < 100; ++n) { 79 for (int n = 0; n < 100; ++n) {
80 semaphore_->Wait(); 80 semaphore_->Wait();
81 ASSERT_FALSE(semaphore_->WaitFor(TimeDelta::FromMicroseconds(1))); 81 ASSERT_FALSE(semaphore_->WaitFor(TimeDelta::FromMicroseconds(1)));
82 semaphore_->Signal(); 82 semaphore_->Signal();
83 } 83 }
84 } 84 }
85 85
86 private: 86 private:
87 Semaphore* const semaphore_; 87 Semaphore* const semaphore_;
88 }; 88 };
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 semaphore.Signal(); 136 semaphore.Signal();
137 ASSERT_TRUE(semaphore.WaitFor(TimeDelta::FromMicroseconds(0))); 137 ASSERT_TRUE(semaphore.WaitFor(TimeDelta::FromMicroseconds(0)));
138 semaphore.Signal(); 138 semaphore.Signal();
139 ASSERT_TRUE(semaphore.WaitFor(TimeDelta::FromMicroseconds(100))); 139 ASSERT_TRUE(semaphore.WaitFor(TimeDelta::FromMicroseconds(100)));
140 semaphore.Signal(); 140 semaphore.Signal();
141 ASSERT_TRUE(semaphore.WaitFor(TimeDelta::FromMicroseconds(1000))); 141 ASSERT_TRUE(semaphore.WaitFor(TimeDelta::FromMicroseconds(1000)));
142 } 142 }
143 143
144 } // namespace base 144 } // namespace base
145 } // namespace v8 145 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/base/platform/platform-unittest.cc ('k') | test/unittests/compiler/change-lowering-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698