source: trunk/xcache.h @ 200

Last change on this file since 200 was 200, checked in by moo, 8 years ago

BUCKET_KEY readability and PHP_6 build fix

File size: 6.0 KB
RevLine 
[1]1#ifndef __XCACHE_H
2#define __XCACHE_H
3#define XCACHE_NAME       "XCache"
[191]4#define XCACHE_VERSION    "1.2-dev"
[1]5#define XCACHE_AUTHOR     "mOo"
6#define XCACHE_COPYRIGHT  "Copyright (c) 2005-2006"
7#define XCACHE_URL        "http://xcache.lighttpd.net"
8
9#include <php.h>
10#include <zend_compile.h>
11#include <zend_API.h>
12#include "php_ini.h"
13#include "zend_hash.h"
14
15#ifdef HAVE_CONFIG_H
16#include <config.h>
17#endif
[148]18#include "xc_shm.h"
[1]19#include "lock.h"
20
[165]21#define HAVE_INODE
[1]22#if !defined(ZEND_ENGINE_2_1) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1 || PHP_MAJOR_VERSION > 5)
23#   define ZEND_ENGINE_2_1
24#endif
[78]25#if !defined(ZEND_ENGINE_2_2) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2 || PHP_MAJOR_VERSION > 5)
26#   define ZEND_ENGINE_2_2
27#endif
[1]28
[19]29#define NOTHING
[1]30/* ZendEngine code Switcher */
31#ifndef ZEND_ENGINE_2
32#   define ZESW(v1, v2) v1
33#else
34#   define ZESW(v1, v2) v2
35#endif
36
37/* unicode */
38#ifdef IS_UNICODE
39#   define UNISW(text, unicode) unicode
40#else
41#   define UNISW(text, unicode) text
42#endif
43#define BUCKET_KEY_SIZE(b) \
44        (UNISW( \
45            (b)->nKeyLength, \
46                ((b)->key.type == IS_UNICODE) \
47                ? UBYTES(b->nKeyLength) \
48                : b->nKeyLength \
49                ))
[200]50#define BUCKET_KEY_S(b)    (UNISW((b)->arKey, (b)->key.arKey.s))
51#define BUCKET_KEY_U(b)    (UNISW((b)->arKey, (b)->key.arKey.u))
52#define BUCKET_KEY_TYPE(b) (UNISW(IS_STRING,  (b)->key.type))
[2]53#ifdef IS_UNICODE
[104]54#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey)
[2]55#else
[11]56#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
[2]57#endif
[1]58#define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
59
60#ifndef IS_UNICODE
61typedef char *zstr;
[103]62#   define ZSTR_S(s)     (s)
63#   define ZSTR_U(s)     (s)
64#   define ZSTR_V(s)     (s)
65#   define ZSTR_PS(s)    (s)
66#   define ZSTR_PU(s)    (s)
67#   define ZSTR_PV(s)    (s)
[1]68#else
[103]69#   define ZSTR_S(zs)    ((zs).s)
70#   define ZSTR_U(zs)    ((zs).u)
71#   define ZSTR_V(zs)    ((zs).v)
72#   define ZSTR_PS(pzs)  ((pzs)->s)
73#   define ZSTR_PU(pzs)  ((pzs)->u)
74#   define ZSTR_PV(pzs)  ((pzs)->v)
[1]75#endif
76
[103]77#ifndef ZSTR
78#   define ZSTR(s)      (s)
79#endif
80
81#ifndef Z_UNIVAL
82#   define Z_UNIVAL(zval) (zval).value.str.val
83#   define Z_UNILEN(zval) (zval).value.str.len
84#endif
85
[1]86/* {{{ u hash wrapper */
87#ifndef IS_UNICODE
88#   define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
89       zend_hash_add(ht, arKey, nKeyLength, pData, nDataSize, pDest)
90
[88]91#   define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
92       zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest)
93
[1]94#   define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
95       zend_hash_find(ht, arKey, nKeyLength, pData)
96
[200]97#   define zend_u_hash_quick_find(ht, type, arKey, nKeyLength, h, pData) \
98       zend_hash_quick_find(ht, arKey, nKeyLength, h, pData)
99
[1]100#   define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
101        add_assoc_zval_ex(arg, key, key_len, value)
102
103#endif
104/* }}} */
105
106
107#define ECALLOC_N(x, n) ((x) = ecalloc(n, sizeof((x)[0])))
108#define ECALLOC_ONE(x) ECALLOC_N(x, 1)
109
110
111
112typedef ulong xc_hash_value_t;
113typedef struct {
114    int bits;
115    int size;
116    int mask;
117} xc_hash_t;
118
119/* the class entry type to be stored in class_table */
120typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
121
122/* xc_cest_t to (zend_class_entry*) */
123#define CestToCePtr(st) (ZESW(\
124            &(st), \
125            st \
126            ) )
127
128/* ZCEP=zend class entry ptr */
129#define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
130            (pce)->refcount, \
131            &((pce)->refcount) \
132            ))
133
134#define ZCE_REFCOUNT_PTR(ce) ZCE_REFCOUNT_PTR(&ce)
135
136typedef zend_op_array *(zend_compile_file_t)(zend_file_handle *h, int type TSRMLS_DC);
137
138/* {{{ xc_cache_t */
139typedef struct _xc_entry_t xc_entry_t;
[11]140typedef struct {
[1]141    int cacheid;
142    xc_hash_t  *hcache; /* hash to cacheid */
143
[11]144    time_t     compiling;
[1]145    zend_ulong misses;
146    zend_ulong hits;
147    zend_ulong clogs;
148    zend_ulong ooms;
149    xc_lock_t  *lck;
150    xc_shm_t   *shm; /* to which shm contains us */
151    xc_mem_t   *mem; /* to which mem contains us */
152
153    xc_entry_t **entries;
[32]154    int entries_count;
[1]155    xc_entry_t *deletes;
[32]156    int deletes_count;
[1]157    xc_hash_t  *hentry; /* hash to entry */
[114]158
159    time_t     last_gc_deletes;
160    time_t     last_gc_expires;
[1]161} xc_cache_t;
162/* }}} */
163/* {{{ xc_classinfo_t */
164typedef struct {
[14]165#ifdef IS_UNICODE
166    zend_uchar type;
167#endif
[103]168    zstr      key;
[1]169    zend_uint key_size;
170    xc_cest_t cest;
171} xc_classinfo_t;
172/* }}} */
[95]173#ifdef HAVE_XCACHE_CONSTANT
174/* {{{ xc_constinfo_t */
175typedef struct {
176#ifdef IS_UNICODE
177    zend_uchar type;
178#endif
[103]179    zstr      key;
[95]180    zend_uint key_size;
181    zend_constant constant;
182} xc_constinfo_t;
183/* }}} */
184#endif
[1]185/* {{{ xc_funcinfo_t */
186typedef struct {
[14]187#ifdef IS_UNICODE
188    zend_uchar type;
189#endif
[103]190    zstr      key;
[1]191    zend_uint key_size;
192    zend_function func;
193} xc_funcinfo_t;
194/* }}} */
195typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
196/* {{{ xc_entry_data_php_t */
197typedef struct {
198    size_t sourcesize;
199#ifdef HAVE_INODE
200    int device;             /* the filesystem device */
201    int inode;              /* the filesystem inode */
202#endif
203    time_t mtime;           /* the mtime of origin source file */
204
205    zend_op_array *op_array;
206
[95]207#ifdef HAVE_XCACHE_CONSTANT
208    zend_uint constinfo_cnt;
209    xc_constinfo_t *constinfos;
210#endif
211
[1]212    zend_uint funcinfo_cnt;
213    xc_funcinfo_t *funcinfos;
214
215    zend_uint classinfo_cnt;
216    xc_classinfo_t *classinfos;
217} xc_entry_data_php_t;
218/* }}} */
219/* {{{ xc_entry_data_var_t */
220typedef struct {
221    zval   *value;
222} xc_entry_data_var_t;
223/* }}} */
224typedef zvalue_value xc_entry_name_t;
225/* {{{ xc_entry_t */
226struct _xc_entry_t {
227    xc_entry_type_t type;
228    xc_hash_value_t hvalue;
229    xc_entry_t *next;
230    xc_cache_t *cache;      /* which cache it's on */
231
232    size_t     size;
233    zend_ulong refcount;
234    zend_ulong hits;
235    time_t     ctime;           /* the ctime of this entry */
236    time_t     atime;           /* the atime of this entry */
237    time_t     dtime;           /* the deletion time of this entry */
[114]238    long       ttl;             /* ttl of time entry, var only */
[1]239
240#ifdef IS_UNICODE
241    zend_uchar name_type;
242#endif
243    xc_entry_name_t name;
244
245    union {
246        xc_entry_data_php_t *php;
247        xc_entry_data_var_t *var;
248    } data;
249};
250/* }}} */
251
252extern zend_module_entry xcache_module_entry;
253#define phpext_xcache_ptr &xcache_module_entry
254
255int xc_is_rw(const void *p);
256int xc_is_ro(const void *p);
257int xc_is_shm(const void *p);
258
259#endif /* __XCACHE_H */
Note: See TracBrowser for help on using the repository browser.