source: trunk/xcache.h @ 1

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

initial import to online

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