diff options
author | dan <dan@noemail.net> | 2020-07-13 18:04:27 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2020-07-13 18:04:27 +0000 |
commit | a7f82d9f47ca75a2f47dc14f8a8deb6730d718d0 (patch) | |
tree | e2000d1d8b1b14297c1a8790c65dd90c4a20e2b9 /tool/showlocks.c | |
parent | 7465787b97a0a09841e343630a07ba80f1399e4a (diff) | |
parent | 5b107654e965973e68c88f90a09a3cc53bac9d8b (diff) | |
download | sqlite-a7f82d9f47ca75a2f47dc14f8a8deb6730d718d0.tar.gz sqlite-a7f82d9f47ca75a2f47dc14f8a8deb6730d718d0.zip |
Merge latest trunk changes with this branch.
FossilOrigin-Name: 5ee3c27e20d12a126fb773b428bb864102b949a5b26a8d5c523753dcedf4be10
Diffstat (limited to 'tool/showlocks.c')
-rw-r--r-- | tool/showlocks.c | 63 |
1 files changed, 49 insertions, 14 deletions
diff --git a/tool/showlocks.c b/tool/showlocks.c index 752c535cc..4159a71f8 100644 --- a/tool/showlocks.c +++ b/tool/showlocks.c @@ -24,23 +24,58 @@ static int showLocksInRange(int fd, off_t lwr, off_t upr){ int cnt = 0; struct flock x; + struct lockRange { + off_t lwr; + off_t upr; + } *aPending = 0; + int nAlloc = 1; + int nPending = 0; + int nDone = 0; - x.l_type = F_WRLCK; - x.l_whence = SEEK_SET; - x.l_start = lwr; - x.l_len = upr-lwr; - fcntl(fd, F_GETLK, &x); - if( x.l_type==F_UNLCK ) return 0; - printf("start: %-12d len: %-5d pid: %-5d type: %s\n", - (int)x.l_start, (int)x.l_len, - x.l_pid, x.l_type==F_WRLCK ? "WRLCK" : "RDLCK"); - cnt++; - if( x.l_start>lwr ){ - cnt += showLocksInRange(fd, lwr, x.l_start-1); + nPending = 1; + aPending = malloc( sizeof(aPending[0]) ); + if( aPending==0 ){ + fprintf(stderr, "out of memory\n"); + exit(1); } - if( x.l_start+x.l_len<upr ){ - cnt += showLocksInRange(fd, x.l_start+x.l_len+1, upr); + aPending[0].lwr = lwr; + aPending[0].upr = upr; + + for(nDone=0; nDone<nPending; nDone++){ + lwr = aPending[nDone].lwr; + upr = aPending[nDone].upr; + if( lwr>=upr ) continue; + x.l_type = F_WRLCK; + x.l_whence = SEEK_SET; + x.l_start = lwr; + x.l_len = upr - lwr; + fcntl(fd, F_GETLK, &x); + if( x.l_type==F_UNLCK ) continue; + printf("start: %-12d len: %-5d pid: %-5d type: %s\n", + (int)x.l_start, (int)x.l_len, + x.l_pid, x.l_type==F_WRLCK ? "WRLCK" : "RDLCK"); + cnt++; + if( nPending+2 > nAlloc ){ + nAlloc = nAlloc*2 + 2; + aPending = realloc(aPending, sizeof(aPending[0])*nAlloc ); + } + if( aPending==0 ){ + fprintf(stderr, "unable to realloc for %d bytes\n", + (int)sizeof(aPending[0])*(nPending+2)); + exit(1); + } + if( lwr<x.l_start ){ + aPending[nPending].lwr = lwr; + aPending[nPending].upr = x.l_start; + nPending++; + } + if( x.l_start+x.l_len<=upr ){ + aPending[nPending].lwr = x.l_start + x.l_len; + aPending[nPending].upr = upr; + nPending++; + } } + free(aPending); return cnt; } |