source: tags/1.1/xcache.h @ 245

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

bump version

File size: 6.0 KB
Line 
1#ifndef __XCACHE_H
2#define __XCACHE_H
3#define XCACHE_NAME       "XCache"
4#define XCACHE_VERSION    "1.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
18#include "xc_shm.h"
19#include "lock.h"
20
21#ifndef ZEND_WIN32
22/* UnDefine if your filesystem doesn't support inodes */
23#   define HAVE_INODE
24#endif
25#if !defined(ZEND_ENGINE_2_1) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1 || PHP_MAJOR_VERSION > 5)
26#   define ZEND_ENGINE_2_1
27#endif
28#if !defined(ZEND_ENGINE_2_2) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2 || PHP_MAJOR_VERSION > 5)
29#   define ZEND_ENGINE_2_2
30#endif
31
32#define NOTHING
33/* ZendEngine code Switcher */
34#ifndef ZEND_ENGINE_2
35#   define ZESW(v1, v2) v1
36#else
37#   define ZESW(v1, v2) v2
38#endif
39
40/* unicode */
41#ifdef IS_UNICODE
42#   define UNISW(text, unicode) unicode
43#else
44#   define UNISW(text, unicode) text
45#endif
46#define BUCKET_KEY_SIZE(b) \
47        (UNISW( \
48            (b)->nKeyLength, \
49                ((b)->key.type == IS_UNICODE) \
50                ? UBYTES(b->nKeyLength) \
51                : b->nKeyLength \
52                ))
53#define BUCKET_KEY(b)  (UNISW((b)->arKey, (b)->key.arKey.s))
54#define BUCKET_UKEY(b) (UNISW((b)->arKey, (b)->key.arKey.u))
55#define BUCKET_KEY_TYPE(b) (UNISW(0, (b)->key.type))
56#ifdef IS_UNICODE
57#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey)
58#else
59#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
60#endif
61#define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
62
63#ifndef IS_UNICODE
64typedef char *zstr;
65#   define ZSTR_S(s)     (s)
66#   define ZSTR_U(s)     (s)
67#   define ZSTR_V(s)     (s)
68#   define ZSTR_PS(s)    (s)
69#   define ZSTR_PU(s)    (s)
70#   define ZSTR_PV(s)    (s)
71#else
72#   define ZSTR_S(zs)    ((zs).s)
73#   define ZSTR_U(zs)    ((zs).u)
74#   define ZSTR_V(zs)    ((zs).v)
75#   define ZSTR_PS(pzs)  ((pzs)->s)
76#   define ZSTR_PU(pzs)  ((pzs)->u)
77#   define ZSTR_PV(pzs)  ((pzs)->v)
78#endif
79
80#ifndef ZSTR
81#   define ZSTR(s)      (s)
82#endif
83
84#ifndef Z_UNIVAL
85#   define Z_UNIVAL(zval) (zval).value.str.val
86#   define Z_UNILEN(zval) (zval).value.str.len
87#endif
88
89/* {{{ u hash wrapper */
90#ifndef IS_UNICODE
91#   define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
92       zend_hash_add(ht, arKey, nKeyLength, pData, nDataSize, pDest)
93
94#   define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
95       zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest)
96
97#   define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
98       zend_hash_find(ht, arKey, nKeyLength, pData)
99
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;
140typedef struct {
141    int cacheid;
142    xc_hash_t  *hcache; /* hash to cacheid */
143
144    time_t     compiling;
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;
154    int entries_count;
155    xc_entry_t *deletes;
156    int deletes_count;
157    xc_hash_t  *hentry; /* hash to entry */
158
159    time_t     last_gc_deletes;
160    time_t     last_gc_expires;
161} xc_cache_t;
162/* }}} */
163/* {{{ xc_classinfo_t */
164typedef struct {
165#ifdef IS_UNICODE
166    zend_uchar type;
167#endif
168    zstr      key;
169    zend_uint key_size;
170    xc_cest_t cest;
171} xc_classinfo_t;
172/* }}} */
173#ifdef HAVE_XCACHE_CONSTANT
174/* {{{ xc_constinfo_t */
175typedef struct {
176#ifdef IS_UNICODE
177    zend_uchar type;
178#endif
179    zstr      key;
180    zend_uint key_size;
181    zend_constant constant;
182} xc_constinfo_t;
183/* }}} */
184#endif
185/* {{{ xc_funcinfo_t */
186typedef struct {
187#ifdef IS_UNICODE
188    zend_uchar type;
189#endif
190    zstr      key;
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
207#ifdef HAVE_XCACHE_CONSTANT
208    zend_uint constinfo_cnt;
209    xc_constinfo_t *constinfos;
210#endif
211
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 */
238    long       ttl;             /* ttl of time entry, var only */
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.