source: trunk/xcache.h @ 114

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

gc expired items, new ini: xcache.ttl xcache.gc_interval xcache.var_ttl xcache.var_maxttl xcache.var_gc_interval

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