From 98759c76bb72cdd1fc26b0a0f21014b9dda4301c Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Fri, 17 Aug 2012 16:51:25 +0400 Subject: [PATCH] unix: Don't poll-wait on unix peer to be bound Long time ago the conn jobs were implemented in a bad manner -- they tried to connect to peer until it succeeds sleeping in the middle. Time to stop doing so and switch to proper futex-based waiting for bound event. Signed-off-by: Pavel Emelyanov --- sk-unix.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/sk-unix.c b/sk-unix.c index c19b626cc..951eb10ac 100644 --- a/sk-unix.c +++ b/sk-unix.c @@ -431,6 +431,7 @@ struct unix_sk_info { unsigned flags; struct unix_sk_info *peer; struct file_desc d; + futex_t bound; }; #define USK_PAIR_MASTER 0x1 @@ -511,7 +512,6 @@ int run_unix_connections(void) cj = conn_jobs; while (cj) { - int attempts = 8; struct unix_sk_info *ui = cj->sk; struct unix_sk_info *peer = ui->peer; struct fdinfo_list_entry *fle; @@ -521,19 +521,15 @@ int run_unix_connections(void) fle = file_master(&ui->d); + futex_wait_while(&peer->bound, 0); + memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; memcpy(&addr.sun_path, peer->name, peer->ue->name.len); -try_again: + if (connect(fle->fe->fd, (struct sockaddr *)&addr, sizeof(addr.sun_family) + peer->ue->name.len) < 0) { - if (attempts) { - usleep(1000); - attempts--; - goto try_again; /* FIXME use futex waiters */ - } - pr_perror("Can't connect %#x socket", ui->ue->ino); return -1; } @@ -576,6 +572,8 @@ static int bind_unix_sk(int sk, struct unix_sk_info *ui) pr_perror("Can't bind socket"); return -1; } + + futex_set_and_wake(&ui->bound, 1); done: return 0; } @@ -742,6 +740,7 @@ static int collect_one_unixsk(void *o, ProtobufCMessage *base) } else ui->name = NULL; + futex_init(&ui->bound); ui->peer = NULL; ui->flags = 0; pr_info(" `- Got %#x peer %#x\n", ui->ue->ino, ui->ue->peer);