| 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 "mojo/edk/system/dispatcher.h" | 10 #include "mojo/edk/system/dispatcher.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 // There's a bit of unrealism in its use: In this sort of usage, calls such as | 42 // There's a bit of unrealism in its use: In this sort of usage, calls such as |
| 43 // |Waiter::Init()|, |AddAwakable()|, and |RemoveAwakable()| are done in the | 43 // |Waiter::Init()|, |AddAwakable()|, and |RemoveAwakable()| are done in the |
| 44 // main (test) thread, not the waiter thread (as would actually happen in real | 44 // main (test) thread, not the waiter thread (as would actually happen in real |
| 45 // code). (We accept this unrealism for simplicity, since |AwakableList| is | 45 // code). (We accept this unrealism for simplicity, since |AwakableList| is |
| 46 // thread-unsafe so making it more realistic would require adding nontrivial | 46 // thread-unsafe so making it more realistic would require adding nontrivial |
| 47 // synchronization machinery.) | 47 // synchronization machinery.) |
| 48 class SimpleWaiterThread : public test::SimpleTestThread { | 48 class SimpleWaiterThread : public test::SimpleTestThread { |
| 49 public: | 49 public: |
| 50 // For the duration of the lifetime of this object, |*result| belongs to it | 50 // For the duration of the lifetime of this object, |*result| belongs to it |
| 51 // (in the sense that it will write to it whenever it wants). | 51 // (in the sense that it will write to it whenever it wants). |
| 52 SimpleWaiterThread(MojoResult* result, uint32_t* context); | 52 SimpleWaiterThread(MojoResult* result, uint64_t* context); |
| 53 ~SimpleWaiterThread() override; // Joins the thread. | 53 ~SimpleWaiterThread() override; // Joins the thread. |
| 54 | 54 |
| 55 Waiter* waiter() { return &waiter_; } | 55 Waiter* waiter() { return &waiter_; } |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 void Run() override; | 58 void Run() override; |
| 59 | 59 |
| 60 MojoResult* const result_; | 60 MojoResult* const result_; |
| 61 uint32_t* const context_; | 61 uint64_t* const context_; |
| 62 Waiter waiter_; | 62 Waiter waiter_; |
| 63 | 63 |
| 64 MOJO_DISALLOW_COPY_AND_ASSIGN(SimpleWaiterThread); | 64 MOJO_DISALLOW_COPY_AND_ASSIGN(SimpleWaiterThread); |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 // This is a more complex and realistic thread that has a |Waiter|, on which it | 67 // This is a more complex and realistic thread that has a |Waiter|, on which it |
| 68 // waits for the given deadline (with the given flags). Unlike | 68 // waits for the given deadline (with the given flags). Unlike |
| 69 // |SimpleWaiterThread|, it requires the machinery of |Dispatcher|. | 69 // |SimpleWaiterThread|, it requires the machinery of |Dispatcher|. |
| 70 class WaiterThread : public test::SimpleTestThread { | 70 class WaiterThread : public test::SimpleTestThread { |
| 71 public: | 71 public: |
| 72 // Note: |*did_wait_out|, |*result_out|, |*context_out| and | 72 // Note: |*did_wait_out|, |*result_out|, |*context_out| and |
| 73 // |*signals_state_out| "belong" to this object (i.e., may be modified by, on | 73 // |*signals_state_out| "belong" to this object (i.e., may be modified by, on |
| 74 // some other thread) while it's alive. | 74 // some other thread) while it's alive. |
| 75 WaiterThread(util::RefPtr<Dispatcher>&& dispatcher, | 75 WaiterThread(util::RefPtr<Dispatcher>&& dispatcher, |
| 76 MojoHandleSignals handle_signals, | 76 MojoHandleSignals handle_signals, |
| 77 MojoDeadline deadline, | 77 MojoDeadline deadline, |
| 78 uint32_t context, | 78 uint64_t context, |
| 79 bool* did_wait_out, | 79 bool* did_wait_out, |
| 80 MojoResult* result_out, | 80 MojoResult* result_out, |
| 81 uint32_t* context_out, | 81 uint64_t* context_out, |
| 82 HandleSignalsState* signals_state_out); | 82 HandleSignalsState* signals_state_out); |
| 83 ~WaiterThread() override; | 83 ~WaiterThread() override; |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 void Run() override; | 86 void Run() override; |
| 87 | 87 |
| 88 const util::RefPtr<Dispatcher> dispatcher_; | 88 const util::RefPtr<Dispatcher> dispatcher_; |
| 89 const MojoHandleSignals handle_signals_; | 89 const MojoHandleSignals handle_signals_; |
| 90 const MojoDeadline deadline_; | 90 const MojoDeadline deadline_; |
| 91 const uint32_t context_; | 91 const uint64_t context_; |
| 92 bool* const did_wait_out_; | 92 bool* const did_wait_out_; |
| 93 MojoResult* const result_out_; | 93 MojoResult* const result_out_; |
| 94 uint32_t* const context_out_; | 94 uint64_t* const context_out_; |
| 95 HandleSignalsState* const signals_state_out_; | 95 HandleSignalsState* const signals_state_out_; |
| 96 | 96 |
| 97 Waiter waiter_; | 97 Waiter waiter_; |
| 98 | 98 |
| 99 MOJO_DISALLOW_COPY_AND_ASSIGN(WaiterThread); | 99 MOJO_DISALLOW_COPY_AND_ASSIGN(WaiterThread); |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 } // namespace test | 102 } // namespace test |
| 103 } // namespace system | 103 } // namespace system |
| 104 } // namespace mojo | 104 } // namespace mojo |
| 105 | 105 |
| 106 #endif // MOJO_EDK_SYSTEM_WAITER_TEST_UTILS_H_ | 106 #endif // MOJO_EDK_SYSTEM_WAITER_TEST_UTILS_H_ |
| OLD | NEW |