OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium 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 #ifndef MOJO_EDK_SYSTEM_WAITER_TEST_UTILS_H_ | 5 #ifndef MOJO_EDK_SYSTEM_WAITER_TEST_UTILS_H_ |
6 #define MOJO_EDK_SYSTEM_WAITER_TEST_UTILS_H_ | 6 #define MOJO_EDK_SYSTEM_WAITER_TEST_UTILS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 // This is a very simple thread that has a |Waiter|, on which it waits | 23 // This is a very simple thread that has a |Waiter|, on which it waits |
24 // indefinitely (and records the result). It will create and initialize the | 24 // indefinitely (and records the result). It will create and initialize the |
25 // |Waiter| on creation, but the caller must start the thread with |Start()|. It | 25 // |Waiter| on creation, but the caller must start the thread with |Start()|. It |
26 // will join the thread on destruction. | 26 // will join the thread on destruction. |
27 // | 27 // |
28 // One usually uses it like: | 28 // One usually uses it like: |
29 // | 29 // |
30 // MojoResult result; | 30 // MojoResult result; |
31 // { | 31 // { |
32 // WaiterList waiter_list; | 32 // AwakableList awakable_list; |
33 // test::SimpleWaiterThread thread(&result); | 33 // test::SimpleWaiterThread thread(&result); |
34 // waiter_list.AddWaiter(thread.waiter(), ...); | 34 // awakable_list.Add(thread.waiter(), ...); |
35 // thread.Start(); | 35 // thread.Start(); |
36 // ... some stuff to wake the waiter ... | 36 // ... some stuff to wake the waiter ... |
37 // waiter_list.RemoveWaiter(thread.waiter()); | 37 // awakable_list.Remove(thread.waiter()); |
38 // } // Join |thread|. | 38 // } // Join |thread|. |
39 // EXPECT_EQ(..., result); | 39 // EXPECT_EQ(..., result); |
40 // | 40 // |
41 // There's a bit of unrealism in its use: In this sort of usage, calls such as | 41 // There's a bit of unrealism in its use: In this sort of usage, calls such as |
42 // |Waiter::Init()|, |AddWaiter()|, and |RemoveWaiter()| are done in the main | 42 // |Waiter::Init()|, |AddAwakable()|, and |RemoveAwakable()| are done in the |
43 // (test) thread, not the waiter thread (as would actually happen in real code). | 43 // main (test) thread, not the waiter thread (as would actually happen in real |
44 // (We accept this unrealism for simplicity, since |WaiterList| is | 44 // code). (We accept this unrealism for simplicity, since |AwakableList| is |
45 // thread-unsafe so making it more realistic would require adding nontrivial | 45 // thread-unsafe so making it more realistic would require adding nontrivial |
46 // synchronization machinery.) | 46 // synchronization machinery.) |
47 class SimpleWaiterThread : public base::SimpleThread { | 47 class SimpleWaiterThread : public base::SimpleThread { |
48 public: | 48 public: |
49 // For the duration of the lifetime of this object, |*result| belongs to it | 49 // For the duration of the lifetime of this object, |*result| belongs to it |
50 // (in the sense that it will write to it whenever it wants). | 50 // (in the sense that it will write to it whenever it wants). |
51 SimpleWaiterThread(MojoResult* result, uint32_t* context); | 51 SimpleWaiterThread(MojoResult* result, uint32_t* context); |
52 ~SimpleWaiterThread() override; // Joins the thread. | 52 ~SimpleWaiterThread() override; // Joins the thread. |
53 | 53 |
54 Waiter* waiter() { return &waiter_; } | 54 Waiter* waiter() { return &waiter_; } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 Waiter waiter_; | 96 Waiter waiter_; |
97 | 97 |
98 DISALLOW_COPY_AND_ASSIGN(WaiterThread); | 98 DISALLOW_COPY_AND_ASSIGN(WaiterThread); |
99 }; | 99 }; |
100 | 100 |
101 } // namespace test | 101 } // namespace test |
102 } // namespace system | 102 } // namespace system |
103 } // namespace mojo | 103 } // namespace mojo |
104 | 104 |
105 #endif // MOJO_EDK_SYSTEM_WAITER_TEST_UTILS_H_ | 105 #endif // MOJO_EDK_SYSTEM_WAITER_TEST_UTILS_H_ |
OLD | NEW |