Skip to content

Instantly share code, notes, and snippets.

@bnoordhuis
Created October 10, 2012 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bnoordhuis/a05bffbf3b0a19e1dd20 to your computer and use it in GitHub Desktop.
Save bnoordhuis/a05bffbf3b0a19e1dd20 to your computer and use it in GitHub Desktop.
diff --git a/src/unix/fs.c b/src/unix/fs.c
index f0bf81a..97233ab 100644
--- a/src/unix/fs.c
+++ b/src/unix/fs.c
@@ -41,6 +41,7 @@
# include <sys/sendfile.h>
#elif defined(__APPLE__) || defined(__FreeBSD__)
# include <sys/socket.h>
+# include <sys/file.h>
# include <sys/uio.h>
#endif
@@ -436,8 +437,7 @@ static ssize_t uv__fs_write(uv_fs_t* req) {
* a dup().
*/
#if defined(__APPLE__)
- static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
- pthread_mutex_lock(&lock);
+ flock(req->file, LOCK_EX);
#endif
if (req->off < 0)
@@ -446,7 +446,7 @@ static ssize_t uv__fs_write(uv_fs_t* req) {
r = pwrite(req->file, req->buf, req->len, req->off);
#if defined(__APPLE__)
- pthread_mutex_unlock(&lock);
+ flock(req->file, LOCK_UN);
#endif
return r;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment