* Minor improvement in the locking mechanism.

This commit is contained in:
Sam Hocevar 2007-01-18 18:45:58 +00:00 committed by sam
parent 73c3d08de7
commit bfcb30f795
2 changed files with 8 additions and 9 deletions

View File

@ -60,8 +60,9 @@ static int maxfd, nfiles;
/* Create lock. This lock variable is used to disable file descriptor
* creation wrappers. For instance on Mac OS X, fopen() calls open()
* and we dont want open() to do any zzuf-related stuff. */
static int create_lock;
* and we dont want open() to do any zzuf-related stuff, fopen() takes
* care of everything. */
static int create_lock = 0;
static int32_t seed = DEFAULT_SEED;
static double minratio = DEFAULT_RATIO;
@ -275,9 +276,9 @@ void _zz_lock(int fd)
return;
if(fd == -1)
create_lock = 1;
create_lock++;
else
files[fds[fd]].locked = 1;
files[fds[fd]].locked++;
}
void _zz_unlock(int fd)
@ -286,9 +287,9 @@ void _zz_unlock(int fd)
return;
if(fd == -1)
create_lock = 0;
create_lock--;
else
files[fds[fd]].locked = 0;
files[fds[fd]].locked--;
}
int _zz_islocked(int fd)

View File

@ -554,12 +554,10 @@ int __srefill(FILE *fp)
if(!_zz_ready || !_zz_iswatched(fd))
return __srefill_orig(fp);
tmp = _zz_islocked(fd);
_zz_lock(fd);
ret = __srefill_orig(fp);
newpos = lseek(fd, 0, SEEK_CUR);
if(!tmp)
_zz_unlock(fd);
_zz_unlock(fd);
if(ret != EOF)
{
if(newpos != -1)