source: trunk/xcache.h @ 191

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

bump version to 1.2-dev

File size: 5.9 KB
Line 
1#ifndef __XCACHE_H
2#define __XCACHE_H
3#define XCACHE_NAME       "XCache"
4#define XCACHE_VERSION    "1.2-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 "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
29#define NOTHING
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                ))
50#define BUCKET_KEY(b)  (UNISW((b)->arKey, (b)->key.arKey.s))
51#define BUCKET_UKEY(b) (UNISW((b)->arKey, (b)->key.arKey.u))
52#define BUCKET_KEY_TYPE(b) (UNISW(0, (b)->key.type))
53#ifdef IS_UNICODE
54#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey)
55#else
56#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
57#endif
58#define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
59
60#ifndef IS_UNICODE
61typedef char *zstr;
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)
68#else
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)
75#endif
76
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
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
91#   define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
92       zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest)
93
94#   define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
95       zend_hash_find(ht, arKey, nKeyLength, pData)
96
97#   define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
98        add_assoc_zval_ex(arg, key, key_len, value)
99
100#endif
101/* }}} */
102
103
104#define ECALLOC_N(x, n) ((x) = ecalloc(n, sizeof((x)[0])))
105#define ECALLOC_ONE(x) ECALLOC_N(x, 1)
106
107
108
109typedef ulong xc_hash_value_t;
110typedef struct {
111    int bits;
112    int size;
113    int mask;
114} xc_hash_t;
115
116/* the class entry type to be stored in class_table */
117typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
118
119/* xc_cest_t to (zend_class_entry*) */
120#define CestToCePtr(st) (ZESW(\
121            &(st), \
122            st \
123            ) )
124
125/* ZCEP=zend class entry ptr */
126#define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
127            (pce)->refcount, \
128            &((pce)->refcount) \
129            ))
130
131#define ZCE_REFCOUNT_PTR(ce) ZCE_REFCOUNT_PTR(&ce)
132
133typedef zend_op_array *(zend_compile_file_t)(zend_file_handle *h, int type TSRMLS_DC);
134
135/* {{{ xc_cache_t */
136typedef struct _xc_entry_t xc_entry_t;
137typedef struct {
138    int cacheid;
139    xc_hash_t  *hcache; /* hash to cacheid */
140
141    time_t     compiling;
142    zend_ulong misses;
143    zend_ulong hits;
144    zend_ulong clogs;
145    zend_ulong ooms;
146    xc_lock_t  *lck;
147    xc_shm_t   *shm; /* to which shm contains us */
148    xc_mem_t   *mem; /* to which mem contains us */
149
150    xc_entry_t **entries;
151    int entries_count;
152    xc_entry_t *deletes;
153    int deletes_count;
154    xc_hash_t  *hentry; /* hash to entry */
155
156    time_t     last_gc_deletes;
157    time_t     last_gc_expires;
158} xc_cache_t;
159/* }}} */
160/* {{{ xc_classinfo_t */
161typedef struct {
162#ifdef IS_UNICODE
163    zend_uchar type;
164#endif
165    zstr      key;
166    zend_uint key_size;
167    xc_cest_t cest;
168} xc_classinfo_t;
169/* }}} */
170#ifdef HAVE_XCACHE_CONSTANT
171/* {{{ xc_constinfo_t */
172typedef struct {
173#ifdef IS_UNICODE
174    zend_uchar type;
175#endif
176    zstr      key;
177    zend_uint key_size;
178    zend_constant constant;
179} xc_constinfo_t;
180/* }}} */
181#endif
182/* {{{ xc_funcinfo_t */
183typedef struct {
184#ifdef IS_UNICODE
185    zend_uchar type;
186#endif
187    zstr      key;
188    zend_uint key_size;
189    zend_function func;
190} xc_funcinfo_t;
191/* }}} */
192typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
193/* {{{ xc_entry_data_php_t */
194typedef struct {
195    size_t sourcesize;
196#ifdef HAVE_INODE
197    int device;             /* the filesystem device */
198    int inode;              /* the filesystem inode */
199#endif
200    time_t mtime;           /* the mtime of origin source file */
201
202    zend_op_array *op_array;
203
204#ifdef HAVE_XCACHE_CONSTANT
205    zend_uint constinfo_cnt;
206    xc_constinfo_t *constinfos;
207#endif
208
209    zend_uint funcinfo_cnt;
210    xc_funcinfo_t *funcinfos;
211
212    zend_uint classinfo_cnt;
213    xc_classinfo_t *classinfos;
214} xc_entry_data_php_t;
215/* }}} */
216/* {{{ xc_entry_data_var_t */
217typedef struct {
218    zval   *value;
219} xc_entry_data_var_t;
220/* }}} */
221typedef zvalue_value xc_entry_name_t;
222/* {{{ xc_entry_t */
223struct _xc_entry_t {
224    xc_entry_type_t type;
225    xc_hash_value_t hvalue;
226    xc_entry_t *next;
227    xc_cache_t *cache;      /* which cache it's on */
228
229    size_t     size;
230    zend_ulong refcount;
231    zend_ulong hits;
232    time_t     ctime;           /* the ctime of this entry */
233    time_t     atime;           /* the atime of this entry */
234    time_t     dtime;           /* the deletion time of this entry */
235    long       ttl;             /* ttl of time entry, var only */
236
237#ifdef IS_UNICODE
238    zend_uchar name_type;
239#endif
240    xc_entry_name_t name;
241
242    union {
243        xc_entry_data_php_t *php;
244        xc_entry_data_var_t *var;
245    } data;
246};
247/* }}} */
248
249extern zend_module_entry xcache_module_entry;
250#define phpext_xcache_ptr &xcache_module_entry
251
252int xc_is_rw(const void *p);
253int xc_is_ro(const void *p);
254int xc_is_shm(const void *p);
255
256#endif /* __XCACHE_H */
Note: See TracBrowser for help on using the repository browser.