source: trunk/xcache.h @ 991

Last change on this file since 991 was 991, checked in by moo, 21 months ago

refactor: split compatibility

  • Property svn:eol-style set to native
File size: 5.9 KB
Line 
1#ifndef __XCACHE_H
2#define __XCACHE_H
3#define XCACHE_NAME       "XCache"
4#ifndef XCACHE_VERSION
5#   define XCACHE_VERSION "2.1.0"
6#endif
7#define XCACHE_AUTHOR     "mOo"
8#define XCACHE_COPYRIGHT  "Copyright (c) 2005-2012"
9#define XCACHE_URL        "http://xcache.lighttpd.net"
10#define XCACHE_WIKI_URL   XCACHE_URL "/wiki"
11
12#include <php.h>
13#include <zend_compile.h>
14#include <zend_API.h>
15#include <zend.h>
16#include "php_ini.h"
17#include "zend_hash.h"
18
19#ifdef HAVE_CONFIG_H
20#include <config.h>
21#endif
22#include "xcache/xc_shm.h"
23#include "xcache/xc_lock.h"
24#include "xcache/xc_compatibility.h"
25
26#define ECALLOC_N(x, n) ((x) = ecalloc(n, sizeof((x)[0])))
27#define ECALLOC_ONE(x) ECALLOC_N(x, 1)
28
29typedef ulong xc_hash_value_t;
30typedef struct {
31    size_t bits;
32    size_t size;
33    xc_hash_value_t mask;
34} xc_hash_t;
35
36typedef zend_op_array *(zend_compile_file_t)(zend_file_handle *h, int type TSRMLS_DC);
37
38typedef struct _xc_entry_t xc_entry_t;
39typedef struct _xc_entry_data_php_t xc_entry_data_php_t;
40/* {{{ xc_cache_t */
41typedef struct {
42    int cacheid;
43    xc_hash_t  *hcache; /* hash to cacheid */
44
45    time_t     compiling;
46    zend_ulong updates;
47    zend_ulong hits;
48    zend_ulong clogs;
49    zend_ulong ooms;
50    zend_ulong errors;
51    xc_lock_t  *lck;
52    xc_shm_t   *shm; /* which shm contains us */
53    xc_mem_t   *mem; /* which mem contains us */
54
55    xc_entry_t **entries;
56    int entries_count;
57    xc_entry_data_php_t **phps;
58    int phps_count;
59    xc_entry_t *deletes;
60    int deletes_count;
61    xc_hash_t  *hentry; /* hash settings to entry */
62    xc_hash_t  *hphp;   /* hash settings to php */
63
64    time_t     last_gc_deletes;
65    time_t     last_gc_expires;
66
67    time_t     hits_by_hour_cur_time;
68    zend_uint  hits_by_hour_cur_slot;
69    zend_ulong hits_by_hour[24];
70    time_t     hits_by_second_cur_time;
71    zend_uint  hits_by_second_cur_slot;
72    zend_ulong hits_by_second[5];
73} xc_cache_t;
74/* }}} */
75/* {{{ xc_op_array_info_detail_t */
76typedef struct {
77    zend_uint index;
78    zend_uint info;
79} xc_op_array_info_detail_t;
80/* }}} */
81/* {{{ xc_op_array_info_t */
82typedef struct {
83#ifdef ZEND_ENGINE_2_4
84    zend_uint literalinfo_cnt;
85    xc_op_array_info_detail_t *literalinfos;
86#else
87    zend_uint oplineinfo_cnt;
88    xc_op_array_info_detail_t *oplineinfos;
89#endif
90} xc_op_array_info_t;
91/* }}} */
92/* {{{ xc_classinfo_t */
93typedef struct {
94#ifdef IS_UNICODE
95    zend_uchar   type;
96#endif
97    const24_zstr key;
98    zend_uint    key_size;
99    ulong        h;
100    zend_uint  methodinfo_cnt;
101    xc_op_array_info_t *methodinfos;
102    xc_cest_t    cest;
103#ifndef ZEND_COMPILE_DELAYED_BINDING
104    int          oplineno;
105#endif
106} xc_classinfo_t;
107/* }}} */
108#ifdef HAVE_XCACHE_CONSTANT
109/* {{{ xc_constinfo_t */
110typedef struct {
111#ifdef IS_UNICODE
112    zend_uchar    type;
113#endif
114    const24_zstr  key;
115    zend_uint     key_size;
116    ulong         h;
117    zend_constant constant;
118} xc_constinfo_t;
119/* }}} */
120#endif
121/* {{{ xc_funcinfo_t */
122typedef struct {
123#ifdef IS_UNICODE
124    zend_uchar     type;
125#endif
126    const24_zstr   key;
127    zend_uint      key_size;
128    ulong          h;
129    xc_op_array_info_t op_array_info;
130    zend_function func;
131} xc_funcinfo_t;
132/* }}} */
133#ifdef ZEND_ENGINE_2_1
134/* {{{ xc_autoglobal_t */
135typedef struct {
136#ifdef IS_UNICODE
137    zend_uchar   type;
138#endif
139    const24_zstr key;
140    zend_uint    key_len;
141    ulong        h;
142} xc_autoglobal_t;
143/* }}} */
144#endif
145typedef struct {
146    char digest[16];
147} xc_md5sum_t;
148/* {{{ xc_compilererror_t */
149typedef struct {
150    int type;
151    uint lineno;
152    int error_len;
153    char *error;
154} xc_compilererror_t;
155/* }}} */
156/* {{{ xc_entry_data_php_t */
157struct _xc_entry_data_php_t {
158    xc_entry_data_php_t *next;
159    xc_hash_value_t      hvalue;
160
161    xc_md5sum_t md5;        /* md5sum of the source */
162    zend_ulong  refcount;   /* count of entries referencing to this data */
163
164    zend_ulong hits;        /* hits of this php */
165    size_t     size;
166
167    xc_op_array_info_t op_array_info;
168    zend_op_array *op_array;
169
170#ifdef HAVE_XCACHE_CONSTANT
171    zend_uint constinfo_cnt;
172    xc_constinfo_t *constinfos;
173#endif
174
175    zend_uint funcinfo_cnt;
176    xc_funcinfo_t *funcinfos;
177
178    zend_uint classinfo_cnt;
179    xc_classinfo_t *classinfos;
180#ifndef ZEND_COMPILE_DELAYED_BINDING
181    zend_bool have_early_binding;
182#endif
183
184#ifdef ZEND_ENGINE_2_1
185    zend_uint autoglobal_cnt;
186    xc_autoglobal_t *autoglobals;
187#endif
188
189#ifdef E_STRICT
190    zend_uint compilererror_cnt;
191    xc_compilererror_t *compilererrors;
192#endif
193
194    zend_bool  have_references;
195};
196/* }}} */
197typedef zvalue_value xc_entry_name_t;
198/* {{{ xc_entry_t */
199struct _xc_entry_t {
200    xc_entry_t *next;
201
202    size_t     size;
203    time_t     ctime;           /* creation ctime of this entry */
204    time_t     atime;           /*   access atime of this entry */
205    time_t     dtime;           /*  deletion time of this entry */
206    zend_ulong hits;
207    zend_ulong ttl;
208
209    xc_entry_name_t name;
210};
211
212typedef struct {
213    xc_entry_t entry;
214    xc_entry_data_php_t *php;
215
216    zend_ulong refcount;    /* count of php instances holding this entry */
217    time_t file_mtime;
218    size_t file_size;
219    int file_device;
220    int file_inode;
221
222    int    filepath_len;
223    ZEND_24(NOTHING, const) char *filepath;
224    int    dirpath_len;
225    char  *dirpath;
226#ifdef IS_UNICODE
227    int    ufilepath_len;
228    UChar *ufilepath;
229    int    udirpath_len;
230    UChar *udirpath;
231#endif
232} xc_entry_php_t;
233
234typedef struct {
235    xc_entry_t entry;
236#ifdef IS_UNICODE
237    zend_uchar name_type;
238#endif
239    zval      *value;
240    zend_bool  have_references;
241} xc_entry_var_t;
242/* }}} */
243typedef struct xc_entry_hash_t { /* {{{ */
244    xc_hash_value_t cacheid;
245    xc_hash_value_t entryslotid;
246} xc_entry_hash_t;
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/* {{{ xc_gc_op_array_t */
256typedef struct {
257#ifdef ZEND_ENGINE_2
258    zend_uint num_args;
259    zend_arg_info *arg_info;
260#endif
261    zend_op *opcodes;
262} xc_gc_op_array_t;
263/* }}} */
264void xc_gc_add_op_array(xc_gc_op_array_t *gc_op_array TSRMLS_DC);
265void xc_fix_op_array_info(const xc_entry_php_t *xce, const xc_entry_data_php_t *php, zend_op_array *op_array, int shallow_copy, const xc_op_array_info_t *op_array_info TSRMLS_DC);
266
267#endif /* __XCACHE_H */
Note: See TracBrowser for help on using the repository browser.