Mercurial > dwindows
changeset 1609:e4a641036581
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.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 03 Mar 2012 06:15:22 +0000 |
parents | ff844a41193b |
children | 48a61abcd5bb |
files | dwcompat.c |
diffstat | 1 files changed, 21 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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++) {