source: trunk/xcache.h @ 2

Last change on this file since 2 was 2, checked in by moo, 9 years ago

fix the using of XtOffsetOf?

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