72 lines
2.3 KiB
C

#ifndef EPOCH_CACHE_H
#define EPOCH_CACHE_H
#include <stdint.h>
#include <stddef.h>
/* All functions return an errno number (zero means success), except create. */
#define EPOCH_KEYS 16u
#define EPOCH_READERS 8u
struct epoch_cache;
struct epoch_reader {
uint64_t owner;
uint64_t generation;
unsigned slot;
};
struct epoch_lease {
uint64_t owner;
uint64_t generation;
uint64_t serial;
uint64_t epoch;
unsigned slot;
};
struct epoch_tx {
uint64_t owner;
uint64_t ticket;
};
struct epoch_record {
uint64_t version;
uint64_t tag;
int64_t value;
int present;
};
struct epoch_sample {
uint64_t snapshot_epoch;
struct epoch_record record;
};
struct epoch_reader_info {
uint64_t seen_max;
uint64_t completed;
int busy;
};
struct epoch_state {
uint64_t epoch;
uint64_t next_ticket;
uint64_t serving_ticket;
unsigned registered;
unsigned active_readers;
unsigned queued_writers;
int writer_active;
int closed;
};
struct epoch_cache *epoch_create(uint64_t owner, uint64_t initial_epoch);
int epoch_register(struct epoch_cache *cache, struct epoch_reader *out);
int epoch_unregister(struct epoch_cache *cache, struct epoch_reader reader);
int epoch_reader_status(struct epoch_cache *cache, struct epoch_reader reader,
struct epoch_reader_info *out);
int epoch_read_begin(struct epoch_cache *cache, struct epoch_reader reader,
struct epoch_lease *out);
int epoch_read_value(struct epoch_cache *cache, struct epoch_lease lease,
unsigned key, struct epoch_sample *out);
int epoch_read_end(struct epoch_cache *cache, struct epoch_lease lease);
int epoch_write_begin(struct epoch_cache *cache, struct epoch_tx *out);
int epoch_write_put(struct epoch_cache *cache, struct epoch_tx tx,
unsigned key, int64_t value, uint64_t tag);
int epoch_write_erase(struct epoch_cache *cache, struct epoch_tx tx,
unsigned key);
int epoch_write_commit(struct epoch_cache *cache, struct epoch_tx tx);
int epoch_write_abort(struct epoch_cache *cache, struct epoch_tx tx);
int epoch_inspect(struct epoch_cache *cache, struct epoch_state *out);
int epoch_reseed(struct epoch_cache *cache, uint64_t epoch);
int epoch_close(struct epoch_cache *cache);
int epoch_destroy(struct epoch_cache *cache);
#endif