rc-stack.h 1.92 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*
 * Copyright (C) 2014 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
 */

#ifndef RC_STACK_H
#define RC_STACK_H

Jonathan Jenkins's avatar
Jonathan Jenkins committed
10 11 12 13
#ifdef __cplusplus
extern "C" {
#endif

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#include <ross.h>

/* A simple stack data structure that is GVT-aware for cleanup purposes. It's
 * meant to use as an alternative to event-stuffing for allocating data that
 * would be too large to put into the event.
 *
 * It's currently overly simple and will not perform well for workloads that
 * hit the RC stack often. Just currently meant to act as a simple placeholder
 * until we have time to do a high-performance implementation.
 *
 * TODO:
 * - use dedicated memory (pass out mem for data, use singly-linked-list of
 *   large-ish chunks to prevent lots of malloc/free calls)
 * - provide better options for invoking garbage collection (enter collection
 *   loop if more than N entries present, every X events, etc.). Don't want to
 *   enter the loop every event or modify the list every time gvt changes.
 */

struct rc_stack;

void rc_stack_create(struct rc_stack **s);
35
void rc_stack_destroy(struct rc_stack *s);
36

37 38 39
/* push data to the stack with time given by tw_now(lp).
 * a NULL free function will do nothing with the data on GC
 * (useful for debugging) */
40
void rc_stack_push(
41
        tw_lp const *lp,
42
        void *data,
43
        void (*free_fn)(void*),
44 45 46 47 48 49
        struct rc_stack *s);

/* pop data from the stack for rc (tw_error if stack empty) */
void * rc_stack_pop(struct rc_stack *s);

/* get the number of entries on the stack (mostly for debug) */
50
int rc_stack_count(struct rc_stack const *s);
51

52 53 54
/* remove entries from the stack with generation time < GVT (lp->pe->GVT).
 * a NULL lp causes a delete-all */
void rc_stack_gc(tw_lp const *lp, struct rc_stack *s);
55

Jonathan Jenkins's avatar
Jonathan Jenkins committed
56 57 58 59
#ifdef __cplusplus
}
#endif

60 61 62 63 64 65 66 67 68 69
#endif /* end of include guard: RC-STACK_H */

/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 * End:
 *
 * vim: ts=8 sts=4 sw=4 expandtab
 */