* Minor improvement in the locking mechanism.
This commit is contained in:
parent
73c3d08de7
commit
bfcb30f795
13
src/fd.c
13
src/fd.c
@ -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 don’t want open() to do any zzuf-related stuff. */
|
||||
static int create_lock;
|
||||
* and we don’t 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)
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user