Add option for unlimited capacity

This commit is contained in:
C-3PO 2018-10-07 19:23:22 +02:00
parent 06a33676dd
commit 82561693ee
Signed by: c3po
GPG key ID: 62993C4BB4D86F24

View file

@ -8,12 +8,12 @@
#include "rateLimiter.h"
#include "utils/min.h"
//How many bytes we can write to disk per second: 30 MB/s
//How many bytes we can write to disk per second: 30 MB/s. Use 0 to specify no limit
#define DISK_SPEED 30UL * 1024UL * 1024UL
/** If we are not writing to disk, how many seconds the capacity can keep increasing before it reaches the limit.
* Increasing this value can result in a spike of data once we are writing to disk again, but then allows the data
* to quickly be written without having to wait for capacity to be available. */
#define MAX_IDLE_TIME 5UL
#define MAX_IDLE_TIME 3UL
//Capacity can be filled up to this maximum amount
#define CAPACITY_MAX DISK_SPEED * MAX_IDLE_TIME
@ -39,6 +39,11 @@ void increaseCapacity() {
/** Pauses execution until the given amount of capacity is available */
void consumeCapacity(unsigned long numBytes) {
//Exit early if there is no capacity limit
if (CAPACITY_MAX == 0UL) {
return;
}
if (numBytes > CAPACITY_MAX) {
fprintf(stderr, "Could not consume %lu bytes in rate limiter; maximum is %lu.\n", numBytes, CAPACITY_MAX);
errorAndExit();