Commit 0bcb0c73 authored by Niels Möller's avatar Niels Möller
Browse files

* src/resource.c, src/resource.h: Use the object_queue struct.

Deleted struct resource_node, and associated allocation and gc

Rev: src/resource.c:1.7
Rev: src/resource.h:1.7
parent 5dfc9315
......@@ -31,16 +31,20 @@
#include "xalloc.h"
/* Prototypes */
#if 0
void do_mark_resources(struct lsh_queue *q,
void (*mark)(struct lsh_object *o));
void do_free_resources(struct lsh_queue *q);
void dont_free_live_resource(int alive);
#include "resource.h.x"
#if 0
void do_mark_resources(struct lsh_queue *q,
void (*mark)(struct lsh_object *o))
......@@ -53,6 +57,7 @@ void do_free_resources(struct lsh_queue *q)
FOR_QUEUE(q, struct resource_node *, n)
void dont_free_live_resource(int alive)
......@@ -61,32 +66,31 @@ void dont_free_live_resource(int alive)
"About to garbage collect a live resource!\n");
static struct resource_node *do_remember_resource(struct resource_list *self,
static void do_remember_resource(struct resource_list *self,
struct resource *r)
struct resource_node *n;
n->resource = r;
lsh_queue_add_head(&self->q, &n->header);
return n;
object_queue_add_head(&self->q, &r->super);
static void do_kill_all(struct resource_list *self)
while (!object_queue_is_empty(&self->q))
CAST(resource, r, object_queue_remove_head(&self->q));
#if 0
/* FIXME: Doesn't deallocate any nodes (but gc should do that
* later). */
FOR_QUEUE(&self->q, struct resource_node *, n)
struct resource_list *empty_resource_list(void)
NEW(resource_list, self);
self->remember = do_remember_resource;
self->kill_all = do_kill_all;
......@@ -62,14 +62,12 @@ struct resource_node
(name resource_list)
(q special-struct "struct lsh_queue"
do_mark_resources do_free_resources)
(q struct object_queue)
;;(q special-struct "struct lsh_queue"
;; do_mark_resources do_free_resources)
; Returns the node.
; NOTE: This pointer should only be stored together with
; the resource list object pointer, as the nodes are not gc:ed
; individually.
(remember method "struct resource_node *" "struct resource *r")
; NOTE: No longer returns the node.
(remember method void "struct resource *r")
; Kills the resource and unlinks and deallocates the node.
;; (kill_resource method void "struct resource_node *n")
......@@ -78,9 +76,9 @@ struct resource_node
/* For now, don't use the value returned from remember. */
#define REMEMBER_RESOURCE(l, r) ((void) ((l)->remember((l), (r))))
#define REMEMBER_RESOURCE(l, r) ((l)->remember((l), (r)))
#define KILL_RESOURCE_NODE(l, n) ((l)->kill_resource((l), (n)))
/* #define KILL_RESOURCE_NODE(l, n) ((l)->kill_resource((l), (n))) */
#define KILL_RESOURCE_LIST(l) ((l)->kill_all((l)))
/* Allocates an empty list. */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment