source: trunk/xcache.h @ 14

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

kill some warning for vc6

File size: 4.9 KB
Line 
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))
53#ifdef IS_UNICODE
54#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key)
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#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 struct {
120    int cacheid;
121    xc_hash_t  *hcache; /* hash to cacheid */
122
123    time_t     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#ifdef IS_UNICODE
140    zend_uchar type;
141#endif
142    char *key;
143    zend_uint key_size;
144    xc_cest_t cest;
145} xc_classinfo_t;
146/* }}} */
147/* {{{ xc_funcinfo_t */
148typedef struct {
149#ifdef IS_UNICODE
150    zend_uchar type;
151#endif
152    char *key;
153    zend_uint key_size;
154    zend_function func;
155} xc_funcinfo_t;
156/* }}} */
157typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
158/* {{{ xc_entry_data_php_t */
159typedef struct {
160    size_t sourcesize;
161#ifdef HAVE_INODE
162    int device;             /* the filesystem device */
163    int inode;              /* the filesystem inode */
164#endif
165    time_t mtime;           /* the mtime of origin source file */
166
167    zend_op_array *op_array;
168
169    zend_uint funcinfo_cnt;
170    xc_funcinfo_t *funcinfos;
171
172    zend_uint classinfo_cnt;
173    xc_classinfo_t *classinfos;
174} xc_entry_data_php_t;
175/* }}} */
176/* {{{ xc_entry_data_var_t */
177typedef struct {
178    zval   *value;
179    time_t etime;
180} xc_entry_data_var_t;
181/* }}} */
182typedef zvalue_value xc_entry_name_t;
183/* {{{ xc_entry_t */
184struct _xc_entry_t {
185    xc_entry_type_t type;
186    xc_hash_value_t hvalue;
187    xc_entry_t *next;
188    xc_cache_t *cache;      /* which cache it's on */
189
190    size_t     size;
191    zend_ulong refcount;
192    zend_ulong hits;
193    time_t     ctime;           /* the ctime of this entry */
194    time_t     atime;           /* the atime of this entry */
195    time_t     dtime;           /* the deletion time of this entry */
196
197#ifdef IS_UNICODE
198    zend_uchar name_type;
199#endif
200    xc_entry_name_t name;
201
202    union {
203        xc_entry_data_php_t *php;
204        xc_entry_data_var_t *var;
205    } data;
206};
207/* }}} */
208
209extern zend_module_entry xcache_module_entry;
210#define phpext_xcache_ptr &xcache_module_entry
211
212int xc_is_rw(const void *p);
213int xc_is_ro(const void *p);
214int xc_is_shm(const void *p);
215
216#endif /* __XCACHE_H */
Note: See TracBrowser for help on using the repository browser.