forked from ldmud/ldmud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlwobject.h
84 lines (69 loc) · 2.47 KB
/
lwobject.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*---------------------------------------------------------------------------
* Lightweight objects
*
*---------------------------------------------------------------------------
* These is the runtime implementation of lightweight objects.
*/
#ifndef LWOBJECT_H__
#define LWOBJECT_H__
#include "driver.h"
#include "typedefs.h"
#include "svalue.h"
/* --- Lightweight object ---
*
* A lightweight object tries to have a minimal memory footprint.
*/
struct lwobject_s
{
p_int ref; /* Reference count. */
program_t *prog; /* Program code. */
wiz_list_t *user; /* UID. */
wiz_list_t *eff_user; /* EUID. */
svalue_t variables[]; /* The variables */
};
extern long num_lwobjects;
/* Number of lwobject_s. */
extern long total_lwobject_size;
/* Size of all lwobject_s. */
extern void _free_lwobject(lwobject_t *lwob);
extern lwobject_t *create_lwobject(object_t *blueprint);
extern lwobject_t *copy_lwobject(lwobject_t *orig, bool copy_variables);
extern void reset_lwobject(lwobject_t *lwob, int hook, int num_arg);
extern svalue_t *v_new_lwobject(svalue_t *sp, int num_arg);
extern svalue_t *f_lwobject_info(svalue_t *sp);
extern svalue_t *f_configure_lwobject(svalue_t *sp);
/* lwobject_t *ref_lwobject(lwobject_t *lwob)
* Add another ref to <lwob> and return the lwobject_t <lwob>.
*/
static INLINE lwobject_t *ref_lwobject(lwobject_t *lwob)
{
if (lwob && lwob->ref)
lwob->ref++;
return lwob;
}
/* void free_lwobject(lwobject_t *lwob)
* Remove one ref from <lwob>, and free the lwobject fully if
* the refcount reaches zero.
*/
static INLINE void free_lwobject(lwobject_t *lwob)
{
if (lwob && lwob->ref && !--(lwob->ref))
_free_lwobject(lwob);
}
static INLINE void put_ref_lwobject(svalue_t * const dest, lwobject_t * const lwobj)
__attribute__((nonnull(1,2)));
static INLINE void put_ref_lwobject(svalue_t * const dest, lwobject_t * const lwobj)
/* Put the lightweight object <lwobj> into <dest>, which is considered empty,
* and increment the refcount of <obj>.
*/
{
*dest = svalue_lwobject(ref_lwobject(lwobj));
}
#define push_ref_lwobject(sp,val) put_ref_lwobject(++(sp),val)
#ifdef GC_SUPPORT
extern lwobject_t* new_sample_lwobject();
extern void free_sample_lwobject(lwobject_t* lwob);
extern void clear_lwobject_ref(lwobject_t *lwob);
extern void count_lwobject_ref(lwobject_t *lwob);
#endif /* GC_SUPPORT */
#endif /* LWOBJECT_H__ */