Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Fix for nodejs/node-v0.x-archive#1506, OSX threaded write()s bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xk authored and ry committed Aug 29, 2011
1 parent df0b483 commit cbbb254
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/eio/eio.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,16 @@ static xmutex_t reslock;
static xmutex_t reqlock;
static xcond_t reqwait;

/* Fix for test-fs-sir-writes-alot */
/* Apple's OSX can't safely write() concurrently from 2 threads */
/* for more info see the thread "fs.write Data Munging" in the nodejs google group */
/* http://groups.google.com/group/nodejs/browse_thread/thread/c11f8b683f37cef/b18ad9e0a15314c5 */
/* And the thread "write()s and pwrite()s from multiple threads in OSX" in libev@lists.schmorp.de */
/* http://lists.schmorp.de/pipermail/libev/2010q4/001185.html */
#if defined (__APPLE__)
static xmutex_t apple_bug_writelock = X_MUTEX_INIT;
#endif

#if !HAVE_PREADWRITE
/*
* make our pread/pwrite emulation safe against themselves, but not against
Expand Down Expand Up @@ -2153,9 +2163,20 @@ eio_execute (etp_worker *self, eio_req *req)
req->result = req->offs >= 0
? pread (req->int1, req->ptr2, req->size, req->offs)
: read (req->int1, req->ptr2, req->size); break;
case EIO_WRITE: req->result = req->offs >= 0

case EIO_WRITE:
#if defined (__APPLE__)
pthread_mutex_lock (&apple_bug_writelock);
#endif

req->result = req->offs >= 0
? pwrite (req->int1, req->ptr2, req->size, req->offs)
: write (req->int1, req->ptr2, req->size); break;
: write (req->int1, req->ptr2, req->size);

#if defined (__APPLE__)
pthread_mutex_unlock (&apple_bug_writelock);
#endif
break;

case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break;
case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size); break;
Expand Down

0 comments on commit cbbb254

Please sign in to comment.