Skip to content

Commit ab84ee0

Browse files
committed
Don't lock the socket for the duration of the system call, there
is no real need for it.
1 parent d0d1f8a commit ab84ee0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/asp_sock.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,23 @@ asp_sock_recv(struct asp_sock *asp, void *buf, size_t len)
2626
int update_stats;
2727

2828
update_stats = 0;
29-
pthread_mutex_lock(&asp->mutex);
3029
r.len = recv(asp->fd, buf, len, 0);
3130
if (r.len > 0) {
31+
pthread_mutex_lock(&asp->mutex);
3232
asp->stats.in.nops++;
3333
asp->stats.in.btotal += r.len;
3434
if (asp->on_stats_update != NULL) {
3535
tstats = asp->stats;
3636
update_stats = 1;
37+
} else {
38+
pthread_mutex_unlock(&asp->mutex);
3739
}
3840
} else {
3941
r.errnom = errno;
4042
}
41-
pthread_mutex_unlock(&asp->mutex);
4243
if (update_stats) {
4344
asp->on_stats_update(&tstats);
45+
pthread_mutex_unlock(&asp->mutex);
4446
}
4547
return (r);
4648
}
@@ -50,12 +52,12 @@ asp_sock_send(struct asp_sock *asp, const void *msg, size_t len)
5052
{
5153
ssize_t rlen;
5254

53-
pthread_mutex_lock(&asp->mutex);
5455
rlen = send(asp->fd, msg, len, 0);
5556
if (rlen > 0) {
57+
pthread_mutex_lock(&asp->mutex);
5658
asp->stats.out.nops++;
5759
asp->stats.out.btotal += rlen;
60+
pthread_mutex_unlock(&asp->mutex);
5861
}
59-
pthread_mutex_unlock(&asp->mutex);
6062
return (rlen);
6163
}

0 commit comments

Comments
 (0)