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

Side by Side Diff: net/tools/quic/test_tools/server_thread.h

Issue 132073002: Fix end_to_end_test performance regression caused by using mutexes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | « net/tools/quic/end_to_end_test.cc ('k') | net/tools/quic/test_tools/server_thread.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 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 NET_TOOLS_QUIC_SERVER_THREAD_H_ 5 #ifndef NET_TOOLS_QUIC_SERVER_THREAD_H_
6 #define NET_TOOLS_QUIC_SERVER_THREAD_H_ 6 #define NET_TOOLS_QUIC_SERVER_THREAD_H_
7 7
8 #include "base/threading/simple_thread.h" 8 #include "base/threading/simple_thread.h"
9 #include "net/base/ip_endpoint.h" 9 #include "net/base/ip_endpoint.h"
10 #include "net/quic/quic_config.h" 10 #include "net/quic/quic_config.h"
11 #include "net/tools/quic/quic_server.h" 11 #include "net/tools/quic/quic_server.h"
12 12
13 namespace net { 13 namespace net {
14 namespace tools { 14 namespace tools {
15 namespace test { 15 namespace test {
16 16
17 // Simple wrapper class to run server in a thread. 17 // Simple wrapper class to run server in a thread.
18 class ServerThread : public base::SimpleThread { 18 class ServerThread : public base::SimpleThread {
19 public: 19 public:
20 ServerThread(IPEndPoint address, 20 ServerThread(IPEndPoint address,
21 const QuicConfig& config, 21 const QuicConfig& config,
22 const QuicVersionVector& supported_versions, 22 const QuicVersionVector& supported_versions,
23 bool strike_register_no_startup_period); 23 bool strike_register_no_startup_period);
24 24
25 virtual ~ServerThread(); 25 virtual ~ServerThread();
26 26
27 // SimpleThread implementation. 27 // Prepares the server, but does not start accepting connections. Useful for
28 // injecting mocks.
29 void Initialize();
30
31 // Runs the event loop. Will initialize if necessary.
28 virtual void Run() OVERRIDE; 32 virtual void Run() OVERRIDE;
29 33
30 // Waits until the server has started and is listening for requests.
31 void WaitForServerStartup();
32
33 // Waits for the handshake to be confirmed for the first session created. 34 // Waits for the handshake to be confirmed for the first session created.
34 void WaitForCryptoHandshakeConfirmed(); 35 void WaitForCryptoHandshakeConfirmed();
35 36
36 // Pauses execution of the server until Resume() is called. 37 // Pauses execution of the server until Resume() is called. May only be
38 // called once.
37 void Pause(); 39 void Pause();
38 40
39 // Resumes execution of the server after Pause() has been called. 41 // Resumes execution of the server after Pause() has been called. May only
42 // be called once.
40 void Resume(); 43 void Resume();
41 44
42 // Stops the server from executing and shuts it down, destroying all 45 // Stops the server from executing and shuts it down, destroying all
43 // server objects. 46 // server objects.
44 void Quit(); 47 void Quit();
45 48
46 // Returns the underlying server. Care must be taken to avoid data races 49 // Returns the underlying server. Care must be taken to avoid data races
47 // when accessing the server. It is always safe to access the server 50 // when accessing the server. It is always safe to access the server
48 // after calling Pause() and before calling Resume(). 51 // after calling Pause() and before calling Resume().
49 QuicServer* server() { return &server_; } 52 QuicServer* server() { return &server_; }
50 53
51 // Returns the port that the server is listening on. 54 // Returns the port that the server is listening on.
52 int GetPort(); 55 int GetPort();
53 56
54 private: 57 private:
55 void MaybeNotifyOfHandshakeConfirmation(); 58 void MaybeNotifyOfHandshakeConfirmation();
56 59
57 base::Lock event_loop_mu_; // Held when the server is processing events.
58 base::WaitableEvent listening_; // Notified when the server is listening.
59 base::WaitableEvent confirmed_; // Notified when the first handshake is 60 base::WaitableEvent confirmed_; // Notified when the first handshake is
60 // confirmed. 61 // confirmed.
62 base::WaitableEvent pause_; // Notified when the server should pause.
63 base::WaitableEvent paused_; // Notitied when the server has paused
64 base::WaitableEvent resume_; // Notified when the server should resume.
61 base::WaitableEvent quit_; // Notified when the server should quit. 65 base::WaitableEvent quit_; // Notified when the server should quit.
62 66
63 tools::QuicServer server_; 67 tools::QuicServer server_;
64 IPEndPoint address_; 68 IPEndPoint address_;
65 base::Lock port_lock_; 69 base::Lock port_lock_;
66 int port_; 70 int port_;
67 71
72 bool initialized_;
73
68 DISALLOW_COPY_AND_ASSIGN(ServerThread); 74 DISALLOW_COPY_AND_ASSIGN(ServerThread);
69 }; 75 };
70 76
71 } // namespace test 77 } // namespace test
72 } // namespace tools 78 } // namespace tools
73 } // namespace net 79 } // namespace net
74 80
75 #endif // NET_TOOLS_QUIC_SERVER_THREAD_H_ 81 #endif // NET_TOOLS_QUIC_SERVER_THREAD_H_
OLDNEW
« no previous file with comments | « net/tools/quic/end_to_end_test.cc ('k') | net/tools/quic/test_tools/server_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698