source: trunk/xcache.h @ 95

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

fixed #20, default: --enable-xcache-constant=yes

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