15 #include "libsync/locks.h" 18 static struct avl_table *btable = NULL;
19 static tatas_lock_t bt_lock;
24 static int bcmp(
const void *a,
const void *b,
void *p) {
29 if (tst->buf.addr < res->buf.addr) {
33 else if (tst->buf.addr > (res->buf.addr + res->buf.size)) {
37 else if ((tst->buf.addr + tst->buf.size) <= (res->buf.addr + res->buf.size)) {
47 btable = avl_create(bcmp, NULL, NULL);
51 sync_tatas_init(&bt_lock);
56 avl_destroy(btable, NULL);
64 sync_tatas_acquire(&bt_lock);
67 tst.
bint.buf.addr = (uintptr_t)addr;
68 tst.
bint.buf.size = size;
69 void *res = avl_find(btable, &tst);
72 sync_tatas_release(&bt_lock);
76 sync_tatas_release(&bt_lock);
83 log_err(
"buffertable not initialized. Call buffertable_init() first.");
87 sync_tatas_acquire(&bt_lock);
89 void *res = avl_insert(btable, (
void*)buf);
91 log_err(
"Tried to insert duplicate or overlapping buffer entry");
92 sync_tatas_release(&bt_lock);
96 sync_tatas_release(&bt_lock);
104 log_err(
"buffertable not initialized. Call buffertable_init() first.");
108 sync_tatas_acquire(&bt_lock);
110 void *res = avl_delete(btable, (
void*)buf);
112 dbg_warn(
"Tried to delete buffer entry that doesn't exist");
113 sync_tatas_release(&bt_lock);
117 sync_tatas_release(&bt_lock);
int buffertable_remove(photonBufferHandle buf)
struct photon_buffer_handle_t * photonBufferHandle
int buffertable_find_exact(void *addr, uint64_t size, photonBufferHandle *result)
int buffertable_insert(photonBufferHandle buf)
#define PHOTON_ERROR
Error code, general error.
struct photon_buffer_internal_t bint
#define PHOTON_OK
Photon success code.
int buffertable_find_containing(void *addr, uint64_t size, photonBufferHandle *result)
int buffertable_init(int size)
void buffertable_finalize()
struct photon_buffer_internal_t * photonBI