summaryrefslogtreecommitdiff
path: root/src/cache/range.h
blob: c1ede096286cbc6e48e7d46038a218e91877c6b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#pragma once

#include <al/types.h>

#include "backing.h"

// @TODO:
//  - cch_backing_remove_range().
//  - Report overlap, don't unlock in backing_write() and handle fill in handler.

AL_IGNORE_WARNING("-Wunused-function")

static void cch_backing_fill_range(struct cch_backing *backing, off_t index, off_t size)
{
    struct cch_range *range;
    al_array_foreach_ptr(backing->available, i, range) {
        if (index >= range->start && index <= range->end) {
            range->end = MAX(index + size, range->end);
            return;
        }
    }
    al_array_push(backing->available, ((struct cch_range){ index, index + size }));
}

AL_IGNORE_WARNING_END