Fixed some cctest flakiness on mac.

Review URL: http://codereview.chromium.org/242003


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2968 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 4c256c06
......@@ -65,6 +65,7 @@ void DebuggerAgent::Run() {
// Accept connections on the bound port.
while (!terminate_) {
bool ok = server_->Listen(1);
listening_->Signal();
if (ok) {
// Accept the new connection.
Socket* client = server_->Accept();
......@@ -93,6 +94,10 @@ void DebuggerAgent::Shutdown() {
}
void DebuggerAgent::WaitUntilListening() {
listening_->Wait();
}
void DebuggerAgent::CreateSession(Socket* client) {
ScopedLock with(session_access_);
......
......@@ -47,7 +47,8 @@ class DebuggerAgent: public Thread {
: name_(StrDup(name)), port_(port),
server_(OS::CreateSocket()), terminate_(false),
session_access_(OS::CreateMutex()), session_(NULL),
terminate_now_(OS::CreateSemaphore(0)) {
terminate_now_(OS::CreateSemaphore(0)),
listening_(OS::CreateSemaphore(0)) {
ASSERT(instance_ == NULL);
instance_ = this;
}
......@@ -57,6 +58,7 @@ class DebuggerAgent: public Thread {
}
void Shutdown();
void WaitUntilListening();
private:
void Run();
......@@ -72,6 +74,7 @@ class DebuggerAgent: public Thread {
Mutex* session_access_; // Mutex guarging access to session_.
DebuggerAgentSession* session_; // Current active session if any.
Semaphore* terminate_now_; // Semaphore to signal termination.
Semaphore* listening_;
static DebuggerAgent* instance_;
......
......@@ -2498,6 +2498,11 @@ void Debugger::StopAgent() {
}
void Debugger::WaitForAgent() {
if (agent_ != NULL)
agent_->WaitUntilListening();
}
MessageImpl MessageImpl::NewEvent(DebugEvent event,
bool running,
Handle<JSObject> exec_state,
......
......@@ -645,6 +645,9 @@ class Debugger {
// Stop the debugger agent.
static void StopAgent();
// Blocks until the agent has started listening for connections
static void WaitForAgent();
// Unload the debugger if possible. Only called when no debugger is currently
// active.
static void UnloadDebugger();
......
......@@ -4522,6 +4522,7 @@ TEST(DebuggerAgent) {
// with the client connected.
ok = i::Debugger::StartAgent("test", kPort2);
CHECK(ok);
i::Debugger::WaitForAgent();
i::Socket* client = i::OS::CreateSocket();
ok = client->Connect("localhost", port2_str);
CHECK(ok);
......
......@@ -42,6 +42,7 @@ void SocketListenerThread::Run() {
// Create the server socket and bind it to the requested port.
server_ = OS::CreateSocket();
server_->SetReuseAddress(true);
CHECK(server_ != NULL);
ok = server_->Bind(port_);
CHECK(ok);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment