# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1330755322 0 # Node ID e4a641036581a1af8024a8e723ca1903c932a0b6 # Parent ff844a41193ba549a924be0788877f7a0473cd9b Last commit didn't help, seems getmntinfo() isn't thread safe on Mac or FreeBSD... So created a _getmntinfo_r() function protected by a mutex. diff -r ff844a41193b -r e4a641036581 dwcompat.c --- a/dwcompat.c Sat Mar 03 05:21:03 2012 +0000 +++ b/dwcompat.c Sat Mar 03 06:15:22 2012 +0000 @@ -74,6 +74,23 @@ return buf; } +/* Get around getmntinfo() not being thread safe */ +#if defined(__FreeBSD__) || defined(__MAC__) +int _getmntinfo_r(struct statfs **mntbufp, int flags) +{ + static HMTX mutex = 0; + int result; + + if(!mutex) + mutex = dw_mutex_new(); + + dw_mutex_lock(mutex); + result = getmntinfo(mntbufp, flags); + dw_mutex_unlock(mutex); + return result; +} +#endif + long double API drivefree(int drive) { #if defined(__EMX__) || defined(__OS2__) @@ -105,7 +122,7 @@ struct statfs *fsp = NULL; int entries, index = 1; - entries = getmntinfo (&fsp, MNT_NOWAIT); + entries = _getmntinfo_r(&fsp, MNT_NOWAIT); for (; entries-- > 0; fsp++) { @@ -207,7 +224,7 @@ struct statfs *fsp = NULL; int entries, index = 1; - entries = getmntinfo (&fsp, MNT_NOWAIT); + entries = _getmntinfo_r(&fsp, MNT_NOWAIT); for (; entries-- > 0; fsp++) { @@ -306,7 +323,7 @@ struct statfs *fsp = NULL; int entries, index = 1; - entries = getmntinfo (&fsp, MNT_NOWAIT); + entries = _getmntinfo_r(&fsp, MNT_NOWAIT); for (; entries-- > 0; fsp++) { @@ -379,7 +396,7 @@ strncpy(buf, "Unknown", len); - entries = getmntinfo (&fsp, MNT_NOWAIT); + entries = _getmntinfo_r(&fsp, MNT_NOWAIT); for (; entries-- > 0; fsp++) {