11 struct objectlist
* v_objectlist
;
12 /* Object list head. */
13 struct object
* v_object_list
;
14 /* Message queue head. */
15 struct message_queue
* v_msg_queue
;
16 /* Greatest locals count for any class. */
18 /* Message queue lock. */
19 struct lock v_msgq_lock
;
22 /*****************************************************************************/
23 void vat_grab_queue_lock(struct vat
* vat
)
25 mutex_lock(&vat
->v_msgq_lock
);
28 /*****************************************************************************/
29 void vat_ungrab_queue_lock(struct vat
* vat
)
31 mutex_unlock(&vat
->v_msgq_lock
);
34 /*****************************************************************************/
35 void vat_queue_message(struct vat
* vat
, struct message
* message
)
37 message_queue_queue(vat
->v_msg_queue
, message
);
40 /*****************************************************************************/
41 static void mark_message_live(struct message
* msg
)
43 object_add_anchor(message_target(msg
));
44 for(size_t i
= 0; i
< message_parameters(msg
); i
++)
45 object_add_anchor(message_read_slot(msg
, i
));
48 /*****************************************************************************/
49 unsigned vat_perform_gc(struct vat
* vat
)
51 objectlist_set_gcmark_all(vat
->v_objectlist
);
52 message_queue_forall(vat
->v_msg_queue
, mark_message_live
);
53 return objectlist_kill_marked(vat
->v_objectlist
);
56 /*****************************************************************************/
57 size_t vat_maxlocals(struct vat
* vat
)
59 return vat
->v_max_locals
;
62 /*****************************************************************************/
63 struct vat
* vat_create(size_t maxlocals
)
66 vat
= malloc(sizeof(struct vat
));
68 fprintf(stderr
, "Out of memory!\n");
71 vat
->v_objectlist
= objectlist_create();
72 vat
->v_msg_queue
= message_queue_create();
73 vat
->v_max_locals
= maxlocals
;
77 /*****************************************************************************/
78 void vat_destroy(struct vat
* vat
)
80 message_queue_destroy(vat
->v_msg_queue
);
81 objectlist_destroy(vat
->v_objectlist
);
85 /*****************************************************************************/
86 void vat_add_object(struct vat
* vat
, struct object
* object
)
88 objectlist_add(vat
->v_objectlist
, object
);
91 /*****************************************************************************/
92 struct message
* vat_deque_message(struct vat
* vat
)
94 return message_queue_deque(vat
->v_msg_queue
);