darwin: remove workaround for data corruption bug

XNU kernels anno ~2010 had a data corrruption bug where concurrent
write and pwrite calls sometimes resulted in blocks of zeroes being
written instead of the actual data.

Libuv works around that by serializing all writes with a process-wide
mutex, meaning oncurrent writes (for all files, not just single files)
have a concurrency of 1. Obviously that's not great for performance.

Modern day macOS no longer has this bug, so remove the workaround.
This commit is contained in:
Ben Noordhuis 2023-10-03 12:52:47 +02:00
parent fef619608b
commit 737f4f953f

View File

@ -41,7 +41,6 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>
@ -1089,17 +1088,6 @@ static ssize_t uv__fs_write_do(int fd,
int64_t off) {
ssize_t r;
/* Serialize writes on OS X, concurrent write() and pwrite() calls result in
* data loss. We can't use a per-file descriptor lock, the descriptor may be
* a dup().
*/
#if defined(__APPLE__)
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
if (pthread_mutex_lock(&lock))
abort();
#endif
if (off < 0) {
if (nbufs == 1)
r = write(fd, bufs->iov_base, bufs->iov_len);
@ -1112,11 +1100,6 @@ static ssize_t uv__fs_write_do(int fd,
r = pwritev(fd, bufs, nbufs, off);
}
#if defined(__APPLE__)
if (pthread_mutex_unlock(&lock))
abort();
#endif
return r;
}