source: tags/1.3.0-rc1/xcache.h @ 655

Last change on this file since 655 was 655, checked in by moo, 5 years ago

bump version to rc1

  • Property svn:eol-style set to native
File size: 9.0 KB
Line 
1#ifndef __XCACHE_H
2#define __XCACHE_H
3#define XCACHE_NAME       "XCache"
4#define XCACHE_VERSION    "1.3.0-rc1"
5#define XCACHE_AUTHOR     "mOo"
6#define XCACHE_COPYRIGHT  "Copyright (c) 2005-2009"
7#define XCACHE_URL        "http://xcache.lighttpd.net"
8#define XCACHE_WIKI_URL   XCACHE_URL "/wiki"
9
10#include <php.h>
11#include <zend_compile.h>
12#include <zend_API.h>
13#include <zend.h>
14#include "php_ini.h"
15#include "zend_hash.h"
16
17#ifdef HAVE_CONFIG_H
18#include <config.h>
19#endif
20#include "xc_shm.h"
21#include "lock.h"
22
23#define HAVE_INODE
24#if !defined(ZEND_ENGINE_2_1) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1 || PHP_MAJOR_VERSION > 5)
25#   define ZEND_ENGINE_2_1
26#endif
27#if !defined(ZEND_ENGINE_2_2) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2 || PHP_MAJOR_VERSION > 5)
28#   define ZEND_ENGINE_2_2
29#endif
30#if !defined(ZEND_ENGINE_2_3) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3 || PHP_MAJOR_VERSION > 5)
31#   define ZEND_ENGINE_2_3
32#endif
33
34#define NOTHING
35/* ZendEngine code Switcher */
36#ifndef ZEND_ENGINE_2
37#   define ZESW(v1, v2) v1
38#else
39#   define ZESW(v1, v2) v2
40#endif
41
42#ifdef do_alloca_with_limit
43#   define my_do_alloca(size, use_heap) do_alloca_with_limit(size, use_heap)
44#   define my_free_alloca(size, use_heap) free_alloca_with_limit(size, use_heap)
45#elif defined(ALLOCA_FLAG)
46#   define my_do_alloca(size, use_heap) do_alloca(size, use_heap)
47#   define my_free_alloca(size, use_heap) free_alloca(size, use_heap)
48#else
49#   define my_do_alloca(size, use_heap) do_alloca(size)
50#   define my_free_alloca(size, use_heap) free_alloca(size)
51#   define ALLOCA_FLAG(x)
52#endif
53#ifndef Z_SET_ISREF
54#   define Z_SET_ISREF(z) (z).is_ref = 1
55#endif
56#ifndef Z_UNSET_ISREF
57#   define Z_UNSET_ISREF(z) (z).is_ref = 0
58#endif
59#ifndef Z_SET_REFCOUNT
60#   define Z_SET_REFCOUNT(z, rc) (z).refcount = rc
61#endif
62#ifndef IS_CONSTANT_TYPE_MASK
63#   define IS_CONSTANT_TYPE_MASK (~IS_CONSTANT_INDEX)
64#endif
65
66/* {{{ dirty fix for PHP 6 */
67#ifdef add_assoc_long_ex
68static inline void my_add_assoc_long_ex(zval *arg, char *key, uint key_len, long value)
69{
70    add_assoc_long_ex(arg, key, key_len, value);
71}
72#   undef add_assoc_long_ex
73#   define add_assoc_long_ex my_add_assoc_long_ex
74#endif
75#ifdef add_assoc_bool_ex
76static inline void my_add_assoc_bool_ex(zval *arg, char *key, uint key_len, zend_bool value)
77{
78    add_assoc_bool_ex(arg, key, key_len, value);
79}
80#   undef add_assoc_bool_ex
81#   define add_assoc_bool_ex my_add_assoc_bool_ex
82#endif
83#ifdef add_assoc_null_ex
84static inline void my_add_assoc_null_ex(zval *arg, char *key, uint key_len)
85{
86    add_assoc_null_ex(arg, key, key_len);
87}
88#   undef add_assoc_null_ex
89#   define add_assoc_null_ex my_add_assoc_null_ex
90#endif
91/* }}} */
92
93/* unicode */
94#ifdef IS_UNICODE
95#   define UNISW(text, unicode) unicode
96#else
97#   define UNISW(text, unicode) text
98#endif
99#define BUCKET_KEY_SIZE(b) \
100        (UNISW( \
101            (b)->nKeyLength, \
102                ((b)->key.type == IS_UNICODE) \
103                ? UBYTES(b->nKeyLength) \
104                : b->nKeyLength \
105                ))
106#define BUCKET_KEY_S(b)    (UNISW((b)->arKey, (b)->key.arKey.s))
107#define BUCKET_KEY_U(b)    (UNISW((b)->arKey, (b)->key.arKey.u))
108#define BUCKET_KEY_TYPE(b) (UNISW(IS_STRING,  (b)->key.type))
109#ifdef IS_UNICODE
110#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey)
111#else
112#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
113#endif
114#define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
115
116#ifndef IS_UNICODE
117typedef char *zstr;
118#   define ZSTR_S(s)     (s)
119#   define ZSTR_U(s)     (s)
120#   define ZSTR_V(s)     (s)
121#   define ZSTR_PS(s)    (s)
122#   define ZSTR_PU(s)    (s)
123#   define ZSTR_PV(s)    (s)
124#else
125#   define ZSTR_S(zs)    ((zs).s)
126#   define ZSTR_U(zs)    ((zs).u)
127#   define ZSTR_V(zs)    ((zs).v)
128#   define ZSTR_PS(pzs)  ((pzs)->s)
129#   define ZSTR_PU(pzs)  ((pzs)->u)
130#   define ZSTR_PV(pzs)  ((pzs)->v)
131#endif
132
133#ifndef ZSTR
134#   define ZSTR(s)      (s)
135#endif
136
137#ifndef Z_UNIVAL
138#   define Z_UNIVAL(zval) (zval).value.str.val
139#   define Z_UNILEN(zval) (zval).value.str.len
140#endif
141
142/* {{{ u hash wrapper */
143#ifndef IS_UNICODE
144#   define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
145       zend_hash_add(ht, arKey, nKeyLength, pData, nDataSize, pDest)
146
147#   define zend_u_hash_quick_add(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
148       zend_hash_quick_add(ht, arKey, nKeyLength, h, pData, nDataSize, pDest)
149
150#   define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
151       zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest)
152
153#   define zend_u_hash_quick_update(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
154       zend_hash_quick_update(ht, arKey, nKeyLength, h, pData, nDataSize, pDest)
155
156#   define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
157       zend_hash_find(ht, arKey, nKeyLength, pData)
158
159#   define zend_u_hash_quick_find(ht, type, arKey, nKeyLength, h, pData) \
160       zend_hash_quick_find(ht, arKey, nKeyLength, h, pData)
161
162#   define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
163        add_assoc_zval_ex(arg, key, key_len, value)
164
165#   define zend_u_is_auto_global(type, name, name_len) \
166        zend_is_auto_global(name, name_len)
167#endif
168/* }}} */
169
170
171#define ECALLOC_N(x, n) ((x) = ecalloc(n, sizeof((x)[0])))
172#define ECALLOC_ONE(x) ECALLOC_N(x, 1)
173
174
175
176typedef ulong xc_hash_value_t;
177typedef struct {
178    int bits;
179    int size;
180    int mask;
181} xc_hash_t;
182
183/* the class entry type to be stored in class_table */
184typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
185
186/* xc_cest_t to (zend_class_entry*) */
187#define CestToCePtr(st) (ZESW(\
188            &(st), \
189            st \
190            ) )
191
192/* ZCEP=zend class entry ptr */
193#define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
194            (pce)->refcount, \
195            &((pce)->refcount) \
196            ))
197
198#define ZCE_REFCOUNT_PTR(ce) ZCE_REFCOUNT_PTR(&ce)
199
200typedef zend_op_array *(zend_compile_file_t)(zend_file_handle *h, int type TSRMLS_DC);
201
202/* {{{ xc_cache_t */
203typedef struct _xc_entry_t xc_entry_t;
204typedef struct {
205    int cacheid;
206    xc_hash_t  *hcache; /* hash to cacheid */
207
208    time_t     compiling;
209    zend_ulong misses;
210    zend_ulong hits;
211    zend_ulong clogs;
212    zend_ulong ooms;
213    zend_ulong errors;
214    xc_lock_t  *lck;
215    xc_shm_t   *shm; /* to which shm contains us */
216    xc_mem_t   *mem; /* to which mem contains us */
217
218    xc_entry_t **entries;
219    int entries_count;
220    xc_entry_t *deletes;
221    int deletes_count;
222    xc_hash_t  *hentry; /* hash to entry */
223
224    time_t     last_gc_deletes;
225    time_t     last_gc_expires;
226
227    time_t     hits_by_hour_cur_time;
228    zend_uint  hits_by_hour_cur_slot;
229    zend_ulong hits_by_hour[24];
230    time_t     hits_by_second_cur_time;
231    zend_uint  hits_by_second_cur_slot;
232    zend_ulong hits_by_second[5];
233} xc_cache_t;
234/* }}} */
235/* {{{ xc_classinfo_t */
236typedef struct {
237#ifdef IS_UNICODE
238    zend_uchar type;
239#endif
240    zstr      key;
241    zend_uint key_size;
242    ulong     h;
243    xc_cest_t cest;
244#ifndef ZEND_COMPILE_DELAYED_BINDING
245    int       oplineno;
246#endif
247} xc_classinfo_t;
248/* }}} */
249#ifdef HAVE_XCACHE_CONSTANT
250/* {{{ xc_constinfo_t */
251typedef struct {
252#ifdef IS_UNICODE
253    zend_uchar type;
254#endif
255    zstr      key;
256    zend_uint key_size;
257    ulong     h;
258    zend_constant constant;
259} xc_constinfo_t;
260/* }}} */
261#endif
262/* {{{ xc_funcinfo_t */
263typedef struct {
264#ifdef IS_UNICODE
265    zend_uchar type;
266#endif
267    zstr      key;
268    zend_uint key_size;
269    ulong     h;
270    zend_function func;
271} xc_funcinfo_t;
272/* }}} */
273#ifdef ZEND_ENGINE_2_1
274/* {{{ xc_autoglobal_t */
275typedef struct {
276#ifdef IS_UNICODE
277    zend_uchar type;
278#endif
279    zstr       key;
280    zend_uint  key_len;
281    ulong      h;
282} xc_autoglobal_t;
283/* }}} */
284#endif
285typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
286/* {{{ xc_entry_data_php_t */
287typedef struct {
288    size_t sourcesize;
289#ifdef HAVE_INODE
290    int device;             /* the filesystem device */
291    int inode;              /* the filesystem inode */
292#endif
293    time_t mtime;           /* the mtime of origin source file */
294
295    zend_op_array *op_array;
296
297#ifdef HAVE_XCACHE_CONSTANT
298    zend_uint constinfo_cnt;
299    xc_constinfo_t *constinfos;
300#endif
301
302    zend_uint funcinfo_cnt;
303    xc_funcinfo_t *funcinfos;
304
305    zend_uint classinfo_cnt;
306    xc_classinfo_t *classinfos;
307#ifndef ZEND_COMPILE_DELAYED_BINDING
308    zend_bool have_early_binding;
309#endif
310
311#ifdef ZEND_ENGINE_2_1
312    zend_uint autoglobal_cnt;
313    xc_autoglobal_t *autoglobals;
314#endif
315} xc_entry_data_php_t;
316/* }}} */
317/* {{{ xc_entry_data_var_t */
318typedef struct {
319    zval   *value;
320} xc_entry_data_var_t;
321/* }}} */
322typedef zvalue_value xc_entry_name_t;
323/* {{{ xc_entry_t */
324struct _xc_entry_t {
325    xc_entry_type_t type;
326    xc_hash_value_t hvalue;
327    xc_entry_t *next;
328    xc_cache_t *cache;      /* which cache it's on */
329
330    size_t     size;
331    zend_ulong refcount;
332    zend_ulong hits;
333    time_t     ctime;           /* the ctime of this entry */
334    time_t     atime;           /* the atime of this entry */
335    time_t     dtime;           /* the deletion time of this entry */
336    long       ttl;             /* ttl of time entry, var only */
337
338#ifdef IS_UNICODE
339    zend_uchar name_type;
340#endif
341    xc_entry_name_t name;
342
343    union {
344        xc_entry_data_php_t *php;
345        xc_entry_data_var_t *var;
346    } data;
347
348    zend_bool  have_references;
349};
350/* }}} */
351
352extern zend_module_entry xcache_module_entry;
353#define phpext_xcache_ptr &xcache_module_entry
354
355int xc_is_rw(const void *p);
356int xc_is_ro(const void *p);
357int xc_is_shm(const void *p);
358void xc_gc_add_op_array(zend_op_array *op_array TSRMLS_DC);
359
360#endif /* __XCACHE_H */
Note: See TracBrowser for help on using the repository browser.