source: branches/1.3/xcache.h @ 494

Last change on this file since 494 was 494, checked in by moo, 6 years ago

branch 1.3

  • Property svn:eol-style set to native
File size: 7.4 KB
Line 
1#ifndef __XCACHE_H
2#define __XCACHE_H
3#define XCACHE_NAME       "XCache"
4#define XCACHE_VERSION    "1.3.0-dev"
5#define XCACHE_AUTHOR     "mOo"
6#define XCACHE_COPYRIGHT  "Copyright (c) 2005-2007"
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#define HAVE_INODE
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
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
28#if !defined(ZEND_ENGINE_2_3) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3 || PHP_MAJOR_VERSION > 5)
29#   define ZEND_ENGINE_2_3
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/* {{{ dirty fix for PHP 6 */
41#ifdef add_assoc_long_ex
42static inline void my_add_assoc_long_ex(zval *arg, char *key, uint key_len, long value)
43{
44    add_assoc_long_ex(arg, key, key_len, value);
45}
46#   undef add_assoc_long_ex
47#   define add_assoc_long_ex my_add_assoc_long_ex
48#endif
49#ifdef add_assoc_bool_ex
50static inline void my_add_assoc_bool_ex(zval *arg, char *key, uint key_len, zend_bool value)
51{
52    add_assoc_bool_ex(arg, key, key_len, value);
53}
54#   undef add_assoc_bool_ex
55#   define add_assoc_bool_ex my_add_assoc_bool_ex
56#endif
57#ifdef add_assoc_null_ex
58static inline void my_add_assoc_null_ex(zval *arg, char *key, uint key_len)
59{
60    add_assoc_null_ex(arg, key, key_len);
61}
62#   undef add_assoc_null_ex
63#   define add_assoc_null_ex my_add_assoc_null_ex
64#endif
65/* }}} */
66
67/* unicode */
68#ifdef IS_UNICODE
69#   define UNISW(text, unicode) unicode
70#else
71#   define UNISW(text, unicode) text
72#endif
73#define BUCKET_KEY_SIZE(b) \
74        (UNISW( \
75            (b)->nKeyLength, \
76                ((b)->key.type == IS_UNICODE) \
77                ? UBYTES(b->nKeyLength) \
78                : b->nKeyLength \
79                ))
80#define BUCKET_KEY_S(b)    (UNISW((b)->arKey, (b)->key.arKey.s))
81#define BUCKET_KEY_U(b)    (UNISW((b)->arKey, (b)->key.arKey.u))
82#define BUCKET_KEY_TYPE(b) (UNISW(IS_STRING,  (b)->key.type))
83#ifdef IS_UNICODE
84#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey)
85#else
86#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
87#endif
88#define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
89
90#ifndef IS_UNICODE
91typedef char *zstr;
92#   define ZSTR_S(s)     (s)
93#   define ZSTR_U(s)     (s)
94#   define ZSTR_V(s)     (s)
95#   define ZSTR_PS(s)    (s)
96#   define ZSTR_PU(s)    (s)
97#   define ZSTR_PV(s)    (s)
98#else
99#   define ZSTR_S(zs)    ((zs).s)
100#   define ZSTR_U(zs)    ((zs).u)
101#   define ZSTR_V(zs)    ((zs).v)
102#   define ZSTR_PS(pzs)  ((pzs)->s)
103#   define ZSTR_PU(pzs)  ((pzs)->u)
104#   define ZSTR_PV(pzs)  ((pzs)->v)
105#endif
106
107#ifndef ZSTR
108#   define ZSTR(s)      (s)
109#endif
110
111#ifndef Z_UNIVAL
112#   define Z_UNIVAL(zval) (zval).value.str.val
113#   define Z_UNILEN(zval) (zval).value.str.len
114#endif
115
116/* {{{ u hash wrapper */
117#ifndef IS_UNICODE
118#   define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
119       zend_hash_add(ht, arKey, nKeyLength, pData, nDataSize, pDest)
120
121#   define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
122       zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest)
123
124#   define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
125       zend_hash_find(ht, arKey, nKeyLength, pData)
126
127#   define zend_u_hash_quick_find(ht, type, arKey, nKeyLength, h, pData) \
128       zend_hash_quick_find(ht, arKey, nKeyLength, h, pData)
129
130#   define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
131        add_assoc_zval_ex(arg, key, key_len, value)
132
133#   define zend_u_is_auto_global(type, name, name_len) \
134        zend_is_auto_global(name, name_len)
135#endif
136/* }}} */
137
138
139#define ECALLOC_N(x, n) ((x) = ecalloc(n, sizeof((x)[0])))
140#define ECALLOC_ONE(x) ECALLOC_N(x, 1)
141
142
143
144typedef ulong xc_hash_value_t;
145typedef struct {
146    int bits;
147    int size;
148    int mask;
149} xc_hash_t;
150
151/* the class entry type to be stored in class_table */
152typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
153
154/* xc_cest_t to (zend_class_entry*) */
155#define CestToCePtr(st) (ZESW(\
156            &(st), \
157            st \
158            ) )
159
160/* ZCEP=zend class entry ptr */
161#define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
162            (pce)->refcount, \
163            &((pce)->refcount) \
164            ))
165
166#define ZCE_REFCOUNT_PTR(ce) ZCE_REFCOUNT_PTR(&ce)
167
168typedef zend_op_array *(zend_compile_file_t)(zend_file_handle *h, int type TSRMLS_DC);
169
170/* {{{ xc_cache_t */
171typedef struct _xc_entry_t xc_entry_t;
172typedef struct {
173    int cacheid;
174    xc_hash_t  *hcache; /* hash to cacheid */
175
176    time_t     compiling;
177    zend_ulong misses;
178    zend_ulong hits;
179    zend_ulong clogs;
180    zend_ulong ooms;
181    zend_ulong errors;
182    xc_lock_t  *lck;
183    xc_shm_t   *shm; /* to which shm contains us */
184    xc_mem_t   *mem; /* to which mem contains us */
185
186    xc_entry_t **entries;
187    int entries_count;
188    xc_entry_t *deletes;
189    int deletes_count;
190    xc_hash_t  *hentry; /* hash to entry */
191
192    time_t     last_gc_deletes;
193    time_t     last_gc_expires;
194} xc_cache_t;
195/* }}} */
196/* {{{ xc_classinfo_t */
197typedef struct {
198#ifdef IS_UNICODE
199    zend_uchar type;
200#endif
201    zstr      key;
202    zend_uint key_size;
203    xc_cest_t cest;
204    int       oplineno;
205} xc_classinfo_t;
206/* }}} */
207#ifdef HAVE_XCACHE_CONSTANT
208/* {{{ xc_constinfo_t */
209typedef struct {
210#ifdef IS_UNICODE
211    zend_uchar type;
212#endif
213    zstr      key;
214    zend_uint key_size;
215    zend_constant constant;
216} xc_constinfo_t;
217/* }}} */
218#endif
219/* {{{ xc_funcinfo_t */
220typedef struct {
221#ifdef IS_UNICODE
222    zend_uchar type;
223#endif
224    zstr      key;
225    zend_uint key_size;
226    zend_function func;
227} xc_funcinfo_t;
228/* }}} */
229#ifdef ZEND_ENGINE_2_1
230/* {{{ xc_autoglobal_t */
231typedef struct {
232#ifdef IS_UNICODE
233    zend_uchar type;
234#endif
235    zstr       key;
236    zend_uint  key_len;
237} xc_autoglobal_t;
238/* }}} */
239#endif
240typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
241/* {{{ xc_entry_data_php_t */
242typedef struct {
243    size_t sourcesize;
244#ifdef HAVE_INODE
245    int device;             /* the filesystem device */
246    int inode;              /* the filesystem inode */
247#endif
248    time_t mtime;           /* the mtime of origin source file */
249
250    zend_op_array *op_array;
251
252#ifdef HAVE_XCACHE_CONSTANT
253    zend_uint constinfo_cnt;
254    xc_constinfo_t *constinfos;
255#endif
256
257    zend_uint funcinfo_cnt;
258    xc_funcinfo_t *funcinfos;
259
260    zend_uint classinfo_cnt;
261    xc_classinfo_t *classinfos;
262    zend_bool have_early_binding;
263
264#ifdef ZEND_ENGINE_2_1
265    zend_uint autoglobal_cnt;
266    xc_autoglobal_t *autoglobals;
267#endif
268} xc_entry_data_php_t;
269/* }}} */
270/* {{{ xc_entry_data_var_t */
271typedef struct {
272    zval   *value;
273} xc_entry_data_var_t;
274/* }}} */
275typedef zvalue_value xc_entry_name_t;
276/* {{{ xc_entry_t */
277struct _xc_entry_t {
278    xc_entry_type_t type;
279    xc_hash_value_t hvalue;
280    xc_entry_t *next;
281    xc_cache_t *cache;      /* which cache it's on */
282
283    size_t     size;
284    zend_ulong refcount;
285    zend_ulong hits;
286    time_t     ctime;           /* the ctime of this entry */
287    time_t     atime;           /* the atime of this entry */
288    time_t     dtime;           /* the deletion time of this entry */
289    long       ttl;             /* ttl of time entry, var only */
290
291#ifdef IS_UNICODE
292    zend_uchar name_type;
293#endif
294    xc_entry_name_t name;
295
296    union {
297        xc_entry_data_php_t *php;
298        xc_entry_data_var_t *var;
299    } data;
300
301    zend_bool  have_references;
302};
303/* }}} */
304
305extern zend_module_entry xcache_module_entry;
306#define phpext_xcache_ptr &xcache_module_entry
307
308int xc_is_rw(const void *p);
309int xc_is_ro(const void *p);
310int xc_is_shm(const void *p);
311
312#endif /* __XCACHE_H */
Note: See TracBrowser for help on using the repository browser.