mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-22 16:06:30 -05:00
Add os_usleep with bounded sleep loop returning on signal interruption and use it in bandwidth limiter
This commit is contained in:
parent
5926570f29
commit
a8a94bb950
5 changed files with 66 additions and 20 deletions
|
|
@ -42,7 +42,7 @@ void bw_limit(struct snapraid_bw* bw, uint64_t bytes)
|
|||
bw->total += bytes;
|
||||
done = bw->total;
|
||||
|
||||
eta = done * 1000 / bw->limit;
|
||||
eta = (done / bw->limit) * 1000 + (done % bw->limit) * 1000 / bw->limit;
|
||||
|
||||
/*
|
||||
* To prevent accumulating unlimited credit during long pauses
|
||||
|
|
@ -61,10 +61,7 @@ void bw_limit(struct snapraid_bw* bw, uint64_t bytes)
|
|||
#endif
|
||||
|
||||
if (eta > elapsed) {
|
||||
eta -= elapsed;
|
||||
if (eta > 1000)
|
||||
eta = 1000;
|
||||
usleep((unsigned)eta * 1000);
|
||||
os_usleep((eta - elapsed) * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue