1 | /* solaris */ |
1 | #include <sys/user.h> |
2 | #define _POSIX_PTHREAD_SEMANTICS 1 |
2 | #include <sys/ptrace.h> |
3 | |
3 | |
4 | #if __linux && !defined(_GNU_SOURCE) |
4 | #define X_STACKSIZE 1024 * 128 + sizeof (long) * 64 * 1024 / 4 |
5 | # define _GNU_SOURCE |
|
|
6 | #endif |
|
|
7 | |
5 | |
8 | /* just in case */ |
6 | #include "xthread.h" |
9 | #define _REENTRANT 1 |
|
|
10 | |
7 | |
11 | #include <errno.h> |
8 | #include <errno.h> |
12 | |
9 | |
13 | #include "EXTERN.h" |
10 | #include "EXTERN.h" |
14 | #include "perl.h" |
11 | #include "perl.h" |
15 | #include "XSUB.h" |
12 | #include "XSUB.h" |
16 | |
13 | |
17 | #include <pthread.h> |
14 | // perl stupidly defines these as macros, breaking |
|
|
15 | // lots and lots of code. |
|
|
16 | #undef open |
|
|
17 | #undef close |
|
|
18 | #undef abort |
|
|
19 | #undef malloc |
|
|
20 | #undef free |
|
|
21 | #undef send |
18 | |
22 | |
19 | #include <stddef.h> |
23 | #include <stddef.h> |
20 | #include <stdlib.h> |
24 | #include <stdlib.h> |
21 | #include <errno.h> |
25 | #include <errno.h> |
22 | #include <sys/time.h> |
|
|
23 | #include <sys/types.h> |
26 | #include <sys/types.h> |
24 | #include <limits.h> |
27 | #include <limits.h> |
25 | #include <unistd.h> |
|
|
26 | #include <fcntl.h> |
28 | #include <fcntl.h> |
27 | |
29 | |
|
|
30 | #ifndef _WIN32 |
|
|
31 | # include <sys/time.h> |
|
|
32 | # include <unistd.h> |
|
|
33 | #endif |
|
|
34 | |
28 | #include <db.h> |
35 | #include <db.h> |
|
|
36 | |
|
|
37 | #if DB_VERSION_MAJOR != 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 3) |
|
|
38 | # error you need Berkeley DB 4.3 or a newer 4.x version installed |
|
|
39 | #endif |
29 | |
40 | |
30 | /* number of seconds after which idle threads exit */ |
41 | /* number of seconds after which idle threads exit */ |
31 | #define IDLE_TIMEOUT 10 |
42 | #define IDLE_TIMEOUT 10 |
32 | |
43 | |
33 | /* wether word reads are potentially non-atomic. |
44 | typedef DB_ENV DB_ENV_ornull; |
34 | * this is conservatice, likely most arches this runs |
45 | typedef DB_TXN DB_TXN_ornull; |
35 | * on have atomic word read/writes. |
46 | typedef DBC DBC_ornull; |
36 | */ |
47 | typedef DB DB_ornull; |
37 | #ifndef WORDACCESS_UNSAFE |
48 | |
38 | # if __i386 || __x86_64 |
49 | typedef DB_ENV DB_ENV_ornuked; |
39 | # define WORDACCESS_UNSAFE 0 |
50 | typedef DB_TXN DB_TXN_ornuked; |
40 | # else |
51 | typedef DBC DBC_ornuked; |
41 | # define WORDACCESS_UNSAFE 1 |
52 | typedef DB DB_ornuked; |
|
|
53 | |
|
|
54 | #if DB_VERSION_MINOR >= 3 |
|
|
55 | typedef DB_SEQUENCE DB_SEQUENCE_ornull; |
|
|
56 | typedef DB_SEQUENCE DB_SEQUENCE_ornuked; |
42 | # endif |
57 | #endif |
43 | #endif |
|
|
44 | |
|
|
45 | typedef DB_ENV DB_ENV_ornull; |
|
|
46 | typedef DB_TXN DB_TXN_ornull; |
|
|
47 | typedef DBC DBC_ornull; |
|
|
48 | typedef DB DB_ornull; |
|
|
49 | |
58 | |
50 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
59 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
51 | typedef char *octetstring; |
60 | typedef char *bdb_filename; |
52 | |
61 | |
53 | static SV *prepare_cb; |
62 | static SV *prepare_cb; |
54 | |
63 | |
|
|
64 | #if DB_VERSION_MINOR >= 6 |
|
|
65 | # define c_close close |
|
|
66 | # define c_count count |
|
|
67 | # define c_del del |
|
|
68 | # define c_dup dup |
|
|
69 | # define c_get get |
|
|
70 | # define c_pget pget |
|
|
71 | # define c_put put |
|
|
72 | #endif |
|
|
73 | |
55 | static inline char * |
74 | static char * |
|
|
75 | get_bdb_filename (SV *sv) |
|
|
76 | { |
|
|
77 | if (!SvOK (sv)) |
|
|
78 | return 0; |
|
|
79 | |
|
|
80 | #if _WIN32 |
|
|
81 | /* win32 madness + win32 perl absolutely brokenness make for horrible hacks */ |
|
|
82 | { |
|
|
83 | STRLEN len; |
|
|
84 | char *src = SvPVbyte (sv, len); |
|
|
85 | SV *t1 = sv_newmortal (); |
|
|
86 | SV *t2 = sv_newmortal (); |
|
|
87 | |
|
|
88 | sv_upgrade (t1, SVt_PV); SvPOK_only (t1); SvGROW (t1, len * 16 + 1); |
|
|
89 | sv_upgrade (t2, SVt_PV); SvPOK_only (t2); SvGROW (t2, len * 16 + 1); |
|
|
90 | |
|
|
91 | len = MultiByteToWideChar (CP_ACP, 0, src, len, (WCHAR *)SvPVX (t1), SvLEN (t1) / sizeof (WCHAR)); |
|
|
92 | len = WideCharToMultiByte (CP_UTF8, 0, (WCHAR *)SvPVX (t1), len, SvPVX (t2), SvLEN (t2), 0, 0); |
|
|
93 | SvPOK_only (t2); |
|
|
94 | SvPVX (t2)[len] = 0; |
|
|
95 | SvCUR_set (t2, len); |
|
|
96 | |
|
|
97 | return SvPVX (t2); |
|
|
98 | } |
|
|
99 | #else |
|
|
100 | return SvPVbyte_nolen (sv); |
|
|
101 | #endif |
|
|
102 | } |
|
|
103 | |
|
|
104 | static void |
|
|
105 | debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg) |
|
|
106 | { |
|
|
107 | printf ("err[%s]\n", msg); |
|
|
108 | } |
|
|
109 | |
|
|
110 | static void |
|
|
111 | debug_msgcall (const DB_ENV *dbenv, const char *msg) |
|
|
112 | { |
|
|
113 | printf ("msg[%s]\n", msg); |
|
|
114 | } |
|
|
115 | |
|
|
116 | static char * |
56 | strdup_ornull (const char *s) |
117 | strdup_ornull (const char *s) |
57 | { |
118 | { |
58 | return s ? strdup (s) : 0; |
119 | return s ? strdup (s) : 0; |
59 | } |
120 | } |
60 | |
121 | |
61 | inline void |
122 | static void |
62 | sv_to_dbt (DBT *dbt, SV *sv) |
123 | sv_to_dbt (DBT *dbt, SV *sv) |
63 | { |
124 | { |
64 | STRLEN len; |
125 | STRLEN len; |
65 | char *data = SvPVbyte (sv, len); |
126 | char *data = SvPVbyte (sv, len); |
66 | |
127 | |
67 | dbt->data = malloc (len); |
128 | dbt->data = malloc (len); |
68 | memcpy (dbt->data, data, len); |
129 | memcpy (dbt->data, data, len); |
69 | dbt->size = len; |
130 | dbt->size = len; |
|
|
131 | dbt->flags = DB_DBT_REALLOC; |
70 | } |
132 | } |
71 | |
133 | |
72 | inline void |
134 | static void |
73 | dbt_to_sv (SV *sv, DBT *dbt) |
135 | dbt_to_sv (SV *sv, DBT *dbt) |
74 | { |
136 | { |
|
|
137 | if (sv) |
|
|
138 | { |
75 | SvREADONLY_off (sv); |
139 | SvREADONLY_off (sv); |
76 | sv_setpvn_mg (sv, dbt->data, dbt->size); |
140 | sv_setsv_mg (sv, dbt->data ? newSVpvn (dbt->data, dbt->size) : &PL_sv_undef); |
|
|
141 | SvREFCNT_dec (sv); |
|
|
142 | } |
77 | |
143 | |
|
|
144 | //assert (dbt->flags & DBT_MALLOC || !dbt->data); |
78 | free (dbt->data); |
145 | free (dbt->data); |
79 | } |
146 | } |
80 | |
147 | |
81 | enum { |
148 | enum { |
82 | REQ_QUIT, |
149 | REQ_QUIT, |
83 | REQ_ENV_OPEN, REQ_ENV_CLOSE, |
150 | REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, |
|
|
151 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME, |
84 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_PUT, REQ_DB_GET, REQ_DB_PGET, |
152 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE, |
|
|
153 | REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, |
85 | REQ_TXN_COMMIT, REQ_TXN_ABORT, |
154 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
|
|
155 | REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, |
|
|
156 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
86 | }; |
157 | }; |
87 | |
158 | |
88 | typedef struct aio_cb |
159 | typedef struct bdb_cb |
89 | { |
160 | { |
90 | struct aio_cb *volatile next; |
161 | struct bdb_cb *volatile next; |
91 | SV *callback; |
162 | SV *callback; |
92 | int type, pri, result; |
163 | int type, pri, result; |
93 | |
164 | |
94 | DB_ENV *env; |
165 | DB_ENV *env; |
95 | DB *db; |
166 | DB *db; |
96 | DB_TXN *txn; |
167 | DB_TXN *txn; |
97 | DBC *cursor; |
168 | DBC *dbc; |
|
|
169 | |
|
|
170 | UV uv1; |
98 | int int1, int2; |
171 | int int1, int2; |
99 | U32 uint1, uint2; |
172 | U32 uint1, uint2; |
100 | char *buf1, *buf2; |
173 | char *buf1, *buf2, *buf3; |
101 | SV *sv1, *sv2; |
174 | SV *sv1, *sv2, *sv3; |
102 | |
175 | |
103 | DBT dbt1, dbt2, dbt3; |
176 | DBT dbt1, dbt2, dbt3; |
104 | } aio_cb; |
177 | DB_KEY_RANGE key_range; |
|
|
178 | #if DB_VERSION_MINOR >= 3 |
|
|
179 | DB_SEQUENCE *seq; |
|
|
180 | db_seq_t seq_t; |
|
|
181 | #endif |
105 | |
182 | |
|
|
183 | SV *rsv1, *rsv2; // keep some request objects alive |
|
|
184 | } bdb_cb; |
|
|
185 | |
106 | typedef aio_cb *aio_req; |
186 | typedef bdb_cb *bdb_req; |
107 | |
187 | |
108 | enum { |
188 | enum { |
109 | PRI_MIN = -4, |
189 | PRI_MIN = -4, |
110 | PRI_MAX = 4, |
190 | PRI_MAX = 4, |
111 | |
191 | |
… | |
… | |
114 | NUM_PRI = PRI_MAX + PRI_BIAS + 1, |
194 | NUM_PRI = PRI_MAX + PRI_BIAS + 1, |
115 | }; |
195 | }; |
116 | |
196 | |
117 | #define AIO_TICKS ((1000000 + 1023) >> 10) |
197 | #define AIO_TICKS ((1000000 + 1023) >> 10) |
118 | |
198 | |
|
|
199 | static SV *on_next_submit; |
|
|
200 | |
119 | static unsigned int max_poll_time = 0; |
201 | static unsigned int max_poll_time = 0; |
120 | static unsigned int max_poll_reqs = 0; |
202 | static unsigned int max_poll_reqs = 0; |
121 | |
203 | |
122 | /* calculcate time difference in ~1/AIO_TICKS of a second */ |
204 | /* calculcate time difference in ~1/AIO_TICKS of a second */ |
123 | static int tvdiff (struct timeval *tv1, struct timeval *tv2) |
205 | static int tvdiff (struct timeval *tv1, struct timeval *tv2) |
… | |
… | |
128 | |
210 | |
129 | static int next_pri = DEFAULT_PRI + PRI_BIAS; |
211 | static int next_pri = DEFAULT_PRI + PRI_BIAS; |
130 | |
212 | |
131 | static unsigned int started, idle, wanted; |
213 | static unsigned int started, idle, wanted; |
132 | |
214 | |
133 | #if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) |
|
|
134 | # define AIO_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP |
|
|
135 | #else |
|
|
136 | # define AIO_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER |
|
|
137 | #endif |
|
|
138 | |
|
|
139 | #define LOCK(mutex) pthread_mutex_lock (&(mutex)) |
|
|
140 | #define UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) |
|
|
141 | |
|
|
142 | /* worker threads management */ |
215 | /* worker threads management */ |
143 | static pthread_mutex_t wrklock = AIO_MUTEX_INIT; |
216 | static mutex_t wrklock = X_MUTEX_INIT; |
144 | |
217 | |
145 | typedef struct worker { |
218 | typedef struct worker { |
146 | /* locked by wrklock */ |
219 | /* locked by wrklock */ |
147 | struct worker *prev, *next; |
220 | struct worker *prev, *next; |
148 | |
221 | |
149 | pthread_t tid; |
222 | thread_t tid; |
150 | |
223 | |
151 | /* locked by reslock, reqlock or wrklock */ |
224 | /* locked by reslock, reqlock or wrklock */ |
152 | aio_req req; /* currently processed request */ |
225 | bdb_req req; /* currently processed request */ |
153 | void *dbuf; |
226 | void *dbuf; |
154 | DIR *dirp; |
227 | DIR *dirp; |
155 | } worker; |
228 | } worker; |
156 | |
229 | |
157 | static worker wrk_first = { &wrk_first, &wrk_first, 0 }; |
230 | static worker wrk_first = { &wrk_first, &wrk_first, 0 }; |
… | |
… | |
169 | } |
242 | } |
170 | |
243 | |
171 | static volatile unsigned int nreqs, nready, npending; |
244 | static volatile unsigned int nreqs, nready, npending; |
172 | static volatile unsigned int max_idle = 4; |
245 | static volatile unsigned int max_idle = 4; |
173 | static volatile unsigned int max_outstanding = 0xffffffff; |
246 | static volatile unsigned int max_outstanding = 0xffffffff; |
174 | static int respipe [2]; |
247 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
175 | |
248 | |
176 | static pthread_mutex_t reslock = AIO_MUTEX_INIT; |
249 | static mutex_t reslock = X_MUTEX_INIT; |
177 | static pthread_mutex_t reqlock = AIO_MUTEX_INIT; |
250 | static mutex_t reqlock = X_MUTEX_INIT; |
178 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
251 | static cond_t reqwait = X_COND_INIT; |
179 | |
252 | |
180 | #if WORDACCESS_UNSAFE |
253 | #if WORDACCESS_UNSAFE |
181 | |
254 | |
182 | static unsigned int get_nready () |
255 | static unsigned int get_nready (void) |
183 | { |
256 | { |
184 | unsigned int retval; |
257 | unsigned int retval; |
185 | |
258 | |
186 | LOCK (reqlock); |
259 | X_LOCK (reqlock); |
187 | retval = nready; |
260 | retval = nready; |
188 | UNLOCK (reqlock); |
261 | X_UNLOCK (reqlock); |
189 | |
262 | |
190 | return retval; |
263 | return retval; |
191 | } |
264 | } |
192 | |
265 | |
193 | static unsigned int get_npending () |
266 | static unsigned int get_npending (void) |
194 | { |
267 | { |
195 | unsigned int retval; |
268 | unsigned int retval; |
196 | |
269 | |
197 | LOCK (reslock); |
270 | X_LOCK (reslock); |
198 | retval = npending; |
271 | retval = npending; |
199 | UNLOCK (reslock); |
272 | X_UNLOCK (reslock); |
200 | |
273 | |
201 | return retval; |
274 | return retval; |
202 | } |
275 | } |
203 | |
276 | |
204 | static unsigned int get_nthreads () |
277 | static unsigned int get_nthreads (void) |
205 | { |
278 | { |
206 | unsigned int retval; |
279 | unsigned int retval; |
207 | |
280 | |
208 | LOCK (wrklock); |
281 | X_LOCK (wrklock); |
209 | retval = started; |
282 | retval = started; |
210 | UNLOCK (wrklock); |
283 | X_UNLOCK (wrklock); |
211 | |
284 | |
212 | return retval; |
285 | return retval; |
213 | } |
286 | } |
214 | |
287 | |
215 | #else |
288 | #else |
… | |
… | |
224 | * a somewhat faster data structure might be nice, but |
297 | * a somewhat faster data structure might be nice, but |
225 | * with 8 priorities this actually needs <20 insns |
298 | * with 8 priorities this actually needs <20 insns |
226 | * per shift, the most expensive operation. |
299 | * per shift, the most expensive operation. |
227 | */ |
300 | */ |
228 | typedef struct { |
301 | typedef struct { |
229 | aio_req qs[NUM_PRI], qe[NUM_PRI]; /* qstart, qend */ |
302 | bdb_req qs[NUM_PRI], qe[NUM_PRI]; /* qstart, qend */ |
230 | int size; |
303 | int size; |
231 | } reqq; |
304 | } reqq; |
232 | |
305 | |
233 | static reqq req_queue; |
306 | static reqq req_queue; |
234 | static reqq res_queue; |
307 | static reqq res_queue; |
235 | |
308 | |
236 | int reqq_push (reqq *q, aio_req req) |
309 | int reqq_push (reqq *q, bdb_req req) |
237 | { |
310 | { |
238 | int pri = req->pri; |
311 | int pri = req->pri; |
239 | req->next = 0; |
312 | req->next = 0; |
240 | |
313 | |
241 | if (q->qe[pri]) |
314 | if (q->qe[pri]) |
… | |
… | |
247 | q->qe[pri] = q->qs[pri] = req; |
320 | q->qe[pri] = q->qs[pri] = req; |
248 | |
321 | |
249 | return q->size++; |
322 | return q->size++; |
250 | } |
323 | } |
251 | |
324 | |
252 | aio_req reqq_shift (reqq *q) |
325 | bdb_req reqq_shift (reqq *q) |
253 | { |
326 | { |
254 | int pri; |
327 | int pri; |
255 | |
328 | |
256 | if (!q->size) |
329 | if (!q->size) |
257 | return 0; |
330 | return 0; |
258 | |
331 | |
259 | --q->size; |
332 | --q->size; |
260 | |
333 | |
261 | for (pri = NUM_PRI; pri--; ) |
334 | for (pri = NUM_PRI; pri--; ) |
262 | { |
335 | { |
263 | aio_req req = q->qs[pri]; |
336 | bdb_req req = q->qs[pri]; |
264 | |
337 | |
265 | if (req) |
338 | if (req) |
266 | { |
339 | { |
267 | if (!(q->qs[pri] = req->next)) |
340 | if (!(q->qs[pri] = req->next)) |
268 | q->qe[pri] = 0; |
341 | q->qe[pri] = 0; |
… | |
… | |
272 | } |
345 | } |
273 | |
346 | |
274 | abort (); |
347 | abort (); |
275 | } |
348 | } |
276 | |
349 | |
277 | static int poll_cb (); |
350 | static int poll_cb (void); |
278 | static void req_free (aio_req req); |
351 | static void req_free (bdb_req req); |
279 | static void req_cancel (aio_req req); |
352 | static void req_cancel (bdb_req req); |
280 | |
353 | |
281 | static int req_invoke (aio_req req) |
354 | static int req_invoke (bdb_req req) |
282 | { |
355 | { |
283 | dSP; |
356 | dSP; |
284 | |
357 | |
285 | if (SvOK (req->callback)) |
358 | if (req->callback) |
286 | { |
359 | { |
287 | ENTER; |
360 | ENTER; |
288 | SAVETMPS; |
361 | SAVETMPS; |
289 | PUSHMARK (SP); |
362 | PUSHMARK (SP); |
290 | EXTEND (SP, 1); |
|
|
291 | |
363 | |
292 | switch (req->type) |
364 | switch (req->type) |
293 | { |
365 | { |
294 | case REQ_DB_GET: |
|
|
295 | case REQ_DB_PGET: |
|
|
296 | dbt_to_sv (req->sv1, &req->dbt3); |
|
|
297 | SvREFCNT_dec (req->sv1); |
|
|
298 | break; |
|
|
299 | |
|
|
300 | case REQ_DB_CLOSE: |
366 | case REQ_DB_CLOSE: |
301 | SvREFCNT_dec (req->sv1); |
367 | SvREFCNT_dec (req->sv1); |
302 | break; |
368 | break; |
|
|
369 | |
|
|
370 | case REQ_DB_GET: |
|
|
371 | case REQ_DB_PGET: |
|
|
372 | dbt_to_sv (req->sv3, &req->dbt3); |
|
|
373 | break; |
|
|
374 | |
|
|
375 | case REQ_C_GET: |
|
|
376 | case REQ_C_PGET: |
|
|
377 | dbt_to_sv (req->sv1, &req->dbt1); |
|
|
378 | dbt_to_sv (req->sv2, &req->dbt2); |
|
|
379 | dbt_to_sv (req->sv3, &req->dbt3); |
|
|
380 | break; |
|
|
381 | |
|
|
382 | case REQ_DB_PUT: |
|
|
383 | case REQ_C_PUT: |
|
|
384 | dbt_to_sv (0, &req->dbt1); |
|
|
385 | dbt_to_sv (0, &req->dbt2); |
|
|
386 | break; |
|
|
387 | |
|
|
388 | case REQ_DB_KEY_RANGE: |
|
|
389 | { |
|
|
390 | AV *av = newAV (); |
|
|
391 | |
|
|
392 | av_push (av, newSVnv (req->key_range.less)); |
|
|
393 | av_push (av, newSVnv (req->key_range.equal)); |
|
|
394 | av_push (av, newSVnv (req->key_range.greater)); |
|
|
395 | |
|
|
396 | SvREADONLY_off (req->sv1); |
|
|
397 | sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); |
|
|
398 | SvREFCNT_dec (req->sv1); |
|
|
399 | } |
|
|
400 | break; |
|
|
401 | |
|
|
402 | #if DB_VERSION_MINOR >= 3 |
|
|
403 | case REQ_SEQ_GET: |
|
|
404 | SvREADONLY_off (req->sv1); |
|
|
405 | |
|
|
406 | if (sizeof (IV) > 4) |
|
|
407 | sv_setiv_mg (req->sv1, (IV)req->seq_t); |
|
|
408 | else |
|
|
409 | sv_setnv_mg (req->sv1, (NV)req->seq_t); |
|
|
410 | |
|
|
411 | SvREFCNT_dec (req->sv1); |
|
|
412 | break; |
|
|
413 | #endif |
303 | } |
414 | } |
304 | |
415 | |
305 | errno = req->result; |
416 | errno = req->result; |
306 | |
417 | |
307 | PUTBACK; |
418 | PUTBACK; |
… | |
… | |
313 | } |
424 | } |
314 | |
425 | |
315 | return !SvTRUE (ERRSV); |
426 | return !SvTRUE (ERRSV); |
316 | } |
427 | } |
317 | |
428 | |
318 | static void req_free (aio_req req) |
429 | static void req_free (bdb_req req) |
319 | { |
430 | { |
|
|
431 | SvREFCNT_dec (req->callback); |
|
|
432 | |
|
|
433 | SvREFCNT_dec (req->rsv1); |
|
|
434 | SvREFCNT_dec (req->rsv2); |
|
|
435 | |
320 | free (req->buf1); |
436 | free (req->buf1); |
321 | free (req->buf2); |
437 | free (req->buf2); |
|
|
438 | free (req->buf3); |
|
|
439 | |
322 | Safefree (req); |
440 | Safefree (req); |
323 | } |
441 | } |
324 | |
442 | |
325 | static void *aio_proc (void *arg); |
443 | #ifdef USE_SOCKETS_AS_HANDLES |
|
|
444 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
|
|
445 | #else |
|
|
446 | # define TO_SOCKET(x) (x) |
|
|
447 | #endif |
|
|
448 | |
|
|
449 | static void |
|
|
450 | create_respipe (void) |
|
|
451 | { |
|
|
452 | #ifdef _WIN32 |
|
|
453 | int arg; /* argg */ |
|
|
454 | #endif |
|
|
455 | int old_readfd = respipe [0]; |
|
|
456 | |
|
|
457 | if (respipe [1] >= 0) |
|
|
458 | respipe_close (TO_SOCKET (respipe [1])); |
|
|
459 | |
|
|
460 | #ifdef _WIN32 |
|
|
461 | if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe)) |
|
|
462 | #else |
|
|
463 | if (pipe (respipe)) |
|
|
464 | #endif |
|
|
465 | croak ("unable to initialize result pipe"); |
|
|
466 | |
|
|
467 | if (old_readfd >= 0) |
|
|
468 | { |
|
|
469 | if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) |
|
|
470 | croak ("unable to initialize result pipe(2)"); |
|
|
471 | |
|
|
472 | respipe_close (respipe [0]); |
|
|
473 | respipe [0] = old_readfd; |
|
|
474 | } |
|
|
475 | |
|
|
476 | #ifdef _WIN32 |
|
|
477 | arg = 1; |
|
|
478 | if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) |
|
|
479 | || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) |
|
|
480 | #else |
|
|
481 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) |
|
|
482 | || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
483 | #endif |
|
|
484 | croak ("unable to initialize result pipe(3)"); |
|
|
485 | |
|
|
486 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
|
|
487 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
|
|
488 | } |
|
|
489 | |
|
|
490 | X_THREAD_PROC (bdb_proc); |
326 | |
491 | |
327 | static void start_thread (void) |
492 | static void start_thread (void) |
328 | { |
493 | { |
329 | sigset_t fullsigset, oldsigset; |
|
|
330 | pthread_attr_t attr; |
|
|
331 | |
|
|
332 | worker *wrk = calloc (1, sizeof (worker)); |
494 | worker *wrk = calloc (1, sizeof (worker)); |
333 | |
495 | |
334 | if (!wrk) |
496 | if (!wrk) |
335 | croak ("unable to allocate worker thread data"); |
497 | croak ("unable to allocate worker thread data"); |
336 | |
498 | |
337 | pthread_attr_init (&attr); |
|
|
338 | pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); |
|
|
339 | #ifdef PTHREAD_SCOPE_PROCESS |
|
|
340 | pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); |
|
|
341 | #endif |
|
|
342 | |
|
|
343 | sigfillset (&fullsigset); |
|
|
344 | |
|
|
345 | LOCK (wrklock); |
499 | X_LOCK (wrklock); |
346 | pthread_sigmask (SIG_SETMASK, &fullsigset, &oldsigset); |
|
|
347 | |
|
|
348 | if (pthread_create (&wrk->tid, &attr, aio_proc, (void *)wrk) == 0) |
500 | if (thread_create (&wrk->tid, bdb_proc, (void *)wrk)) |
349 | { |
501 | { |
350 | wrk->prev = &wrk_first; |
502 | wrk->prev = &wrk_first; |
351 | wrk->next = wrk_first.next; |
503 | wrk->next = wrk_first.next; |
352 | wrk_first.next->prev = wrk; |
504 | wrk_first.next->prev = wrk; |
353 | wrk_first.next = wrk; |
505 | wrk_first.next = wrk; |
354 | ++started; |
506 | ++started; |
355 | } |
507 | } |
356 | else |
508 | else |
357 | free (wrk); |
509 | free (wrk); |
358 | |
510 | |
359 | pthread_sigmask (SIG_SETMASK, &oldsigset, 0); |
|
|
360 | UNLOCK (wrklock); |
511 | X_UNLOCK (wrklock); |
361 | } |
512 | } |
362 | |
513 | |
363 | static void maybe_start_thread () |
514 | static void maybe_start_thread (void) |
364 | { |
515 | { |
365 | if (get_nthreads () >= wanted) |
516 | if (get_nthreads () >= wanted) |
366 | return; |
517 | return; |
367 | |
518 | |
368 | /* todo: maybe use idle here, but might be less exact */ |
519 | /* todo: maybe use idle here, but might be less exact */ |
… | |
… | |
370 | return; |
521 | return; |
371 | |
522 | |
372 | start_thread (); |
523 | start_thread (); |
373 | } |
524 | } |
374 | |
525 | |
375 | static void req_send (aio_req req) |
526 | static void req_send (bdb_req req) |
376 | { |
527 | { |
377 | SV *wait_callback = 0; |
528 | SV *wait_callback = 0; |
378 | |
529 | |
|
|
530 | if (on_next_submit) |
|
|
531 | { |
|
|
532 | dSP; |
|
|
533 | SV *cb = sv_2mortal (on_next_submit); |
|
|
534 | |
|
|
535 | on_next_submit = 0; |
|
|
536 | |
|
|
537 | PUSHMARK (SP); |
|
|
538 | PUTBACK; |
|
|
539 | call_sv (cb, G_DISCARD | G_EVAL); |
|
|
540 | SPAGAIN; |
|
|
541 | } |
|
|
542 | |
379 | // synthesize callback if none given |
543 | // synthesize callback if none given |
380 | if (!SvOK (req->callback)) |
544 | if (!req->callback) |
381 | { |
545 | { |
|
|
546 | int count; |
|
|
547 | |
382 | dSP; |
548 | dSP; |
383 | PUSHMARK (SP); |
549 | PUSHMARK (SP); |
384 | PUTBACK; |
550 | PUTBACK; |
385 | int count = call_sv (prepare_cb, G_ARRAY); |
551 | count = call_sv (prepare_cb, G_ARRAY); |
386 | SPAGAIN; |
552 | SPAGAIN; |
387 | |
553 | |
388 | if (count != 2) |
554 | if (count != 2) |
389 | croak ("prepare callback must return exactly two values\n"); |
555 | croak ("prepare callback must return exactly two values\n"); |
390 | |
556 | |
391 | wait_callback = SvREFCNT_inc (POPs); |
557 | wait_callback = POPs; |
392 | SvREFCNT_dec (req->callback); |
|
|
393 | req->callback = SvREFCNT_inc (POPs); |
558 | req->callback = SvREFCNT_inc (POPs); |
394 | } |
559 | } |
395 | |
560 | |
396 | ++nreqs; |
561 | ++nreqs; |
397 | |
562 | |
398 | LOCK (reqlock); |
563 | X_LOCK (reqlock); |
399 | ++nready; |
564 | ++nready; |
400 | reqq_push (&req_queue, req); |
565 | reqq_push (&req_queue, req); |
401 | pthread_cond_signal (&reqwait); |
566 | X_COND_SIGNAL (reqwait); |
402 | UNLOCK (reqlock); |
567 | X_UNLOCK (reqlock); |
403 | |
568 | |
404 | maybe_start_thread (); |
569 | maybe_start_thread (); |
405 | |
570 | |
406 | if (wait_callback) |
571 | if (wait_callback) |
407 | { |
572 | { |
408 | dSP; |
573 | dSP; |
409 | PUSHMARK (SP); |
574 | PUSHMARK (SP); |
410 | PUTBACK; |
575 | PUTBACK; |
411 | call_sv (wait_callback, G_DISCARD); |
576 | call_sv (wait_callback, G_DISCARD); |
412 | SvREFCNT_dec (wait_callback); |
|
|
413 | } |
577 | } |
414 | } |
578 | } |
415 | |
579 | |
416 | static void end_thread (void) |
580 | static void end_thread (void) |
417 | { |
581 | { |
418 | aio_req req; |
582 | bdb_req req; |
419 | |
583 | |
420 | Newz (0, req, 1, aio_cb); |
584 | Newz (0, req, 1, bdb_cb); |
421 | |
585 | |
422 | req->type = REQ_QUIT; |
586 | req->type = REQ_QUIT; |
423 | req->pri = PRI_MAX + PRI_BIAS; |
587 | req->pri = PRI_MAX + PRI_BIAS; |
424 | |
588 | |
425 | LOCK (reqlock); |
589 | X_LOCK (reqlock); |
426 | reqq_push (&req_queue, req); |
590 | reqq_push (&req_queue, req); |
427 | pthread_cond_signal (&reqwait); |
591 | X_COND_SIGNAL (reqwait); |
428 | UNLOCK (reqlock); |
592 | X_UNLOCK (reqlock); |
429 | |
593 | |
430 | LOCK (wrklock); |
594 | X_LOCK (wrklock); |
431 | --started; |
595 | --started; |
432 | UNLOCK (wrklock); |
596 | X_UNLOCK (wrklock); |
433 | } |
597 | } |
434 | |
598 | |
435 | static void set_max_idle (int nthreads) |
599 | static void set_max_idle (int nthreads) |
436 | { |
600 | { |
437 | if (WORDACCESS_UNSAFE) LOCK (reqlock); |
601 | if (WORDACCESS_UNSAFE) X_LOCK (reqlock); |
438 | max_idle = nthreads <= 0 ? 1 : nthreads; |
602 | max_idle = nthreads <= 0 ? 1 : nthreads; |
439 | if (WORDACCESS_UNSAFE) UNLOCK (reqlock); |
603 | if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); |
440 | } |
604 | } |
441 | |
605 | |
442 | static void min_parallel (int nthreads) |
606 | static void min_parallel (int nthreads) |
443 | { |
607 | { |
444 | if (wanted < nthreads) |
608 | if (wanted < nthreads) |
… | |
… | |
452 | |
616 | |
453 | while (started > wanted) |
617 | while (started > wanted) |
454 | end_thread (); |
618 | end_thread (); |
455 | } |
619 | } |
456 | |
620 | |
457 | static void poll_wait () |
621 | static void poll_wait (void) |
458 | { |
622 | { |
459 | fd_set rfd; |
623 | fd_set rfd; |
460 | |
624 | |
461 | while (nreqs) |
625 | while (nreqs) |
462 | { |
626 | { |
463 | int size; |
627 | int size; |
464 | if (WORDACCESS_UNSAFE) LOCK (reslock); |
628 | if (WORDACCESS_UNSAFE) X_LOCK (reslock); |
465 | size = res_queue.size; |
629 | size = res_queue.size; |
466 | if (WORDACCESS_UNSAFE) UNLOCK (reslock); |
630 | if (WORDACCESS_UNSAFE) X_UNLOCK (reslock); |
467 | |
631 | |
468 | if (size) |
632 | if (size) |
469 | return; |
633 | return; |
470 | |
634 | |
471 | maybe_start_thread (); |
635 | maybe_start_thread (); |
472 | |
636 | |
473 | FD_ZERO(&rfd); |
637 | FD_ZERO (&rfd); |
474 | FD_SET(respipe [0], &rfd); |
638 | FD_SET (respipe [0], &rfd); |
475 | |
639 | |
476 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
640 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
477 | } |
641 | } |
478 | } |
642 | } |
479 | |
643 | |
480 | static int poll_cb () |
644 | static int poll_cb (void) |
481 | { |
645 | { |
482 | dSP; |
646 | dSP; |
483 | int count = 0; |
647 | int count = 0; |
484 | int maxreqs = max_poll_reqs; |
648 | int maxreqs = max_poll_reqs; |
485 | int do_croak = 0; |
649 | int do_croak = 0; |
486 | struct timeval tv_start, tv_now; |
650 | struct timeval tv_start, tv_now; |
487 | aio_req req; |
651 | bdb_req req; |
488 | |
652 | |
489 | if (max_poll_time) |
653 | if (max_poll_time) |
490 | gettimeofday (&tv_start, 0); |
654 | gettimeofday (&tv_start, 0); |
491 | |
655 | |
492 | for (;;) |
656 | for (;;) |
493 | { |
657 | { |
494 | for (;;) |
658 | for (;;) |
495 | { |
659 | { |
496 | maybe_start_thread (); |
660 | maybe_start_thread (); |
497 | |
661 | |
498 | LOCK (reslock); |
662 | X_LOCK (reslock); |
499 | req = reqq_shift (&res_queue); |
663 | req = reqq_shift (&res_queue); |
500 | |
664 | |
501 | if (req) |
665 | if (req) |
502 | { |
666 | { |
503 | --npending; |
667 | --npending; |
504 | |
668 | |
505 | if (!res_queue.size) |
669 | if (!res_queue.size) |
506 | { |
670 | { |
507 | /* read any signals sent by the worker threads */ |
671 | /* read any signals sent by the worker threads */ |
508 | char buf [4]; |
672 | char buf [4]; |
509 | while (read (respipe [0], buf, 4) == 4) |
673 | while (respipe_read (respipe [0], buf, 4) == 4) |
510 | ; |
674 | ; |
511 | } |
675 | } |
512 | } |
676 | } |
513 | |
677 | |
514 | UNLOCK (reslock); |
678 | X_UNLOCK (reslock); |
515 | |
679 | |
516 | if (!req) |
680 | if (!req) |
517 | break; |
681 | break; |
518 | |
682 | |
519 | --nreqs; |
683 | --nreqs; |
… | |
… | |
549 | } |
713 | } |
550 | |
714 | |
551 | return count; |
715 | return count; |
552 | } |
716 | } |
553 | |
717 | |
554 | static void create_pipe () |
|
|
555 | { |
|
|
556 | if (pipe (respipe)) |
|
|
557 | croak ("unable to initialize result pipe"); |
|
|
558 | |
|
|
559 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)) |
|
|
560 | croak ("cannot set result pipe to nonblocking mode"); |
|
|
561 | |
|
|
562 | if (fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
563 | croak ("cannot set result pipe to nonblocking mode"); |
|
|
564 | } |
|
|
565 | |
|
|
566 | /*****************************************************************************/ |
718 | /*****************************************************************************/ |
567 | |
719 | |
568 | static void *aio_proc (void *thr_arg) |
720 | static void |
|
|
721 | bdb_request (bdb_req req) |
569 | { |
722 | { |
|
|
723 | switch (req->type) |
|
|
724 | { |
|
|
725 | case REQ_ENV_OPEN: |
|
|
726 | req->result = req->env->open (req->env, req->buf1, req->uint1, req->int1); |
|
|
727 | break; |
|
|
728 | |
|
|
729 | case REQ_ENV_CLOSE: |
|
|
730 | req->result = req->env->close (req->env, req->uint1); |
|
|
731 | break; |
|
|
732 | |
|
|
733 | case REQ_ENV_TXN_CHECKPOINT: |
|
|
734 | req->result = req->env->txn_checkpoint (req->env, req->uint1, req->int1, req->uint2); |
|
|
735 | break; |
|
|
736 | |
|
|
737 | case REQ_ENV_LOCK_DETECT: |
|
|
738 | req->result = req->env->lock_detect (req->env, req->uint1, req->uint2, &req->int1); |
|
|
739 | break; |
|
|
740 | |
|
|
741 | case REQ_ENV_MEMP_SYNC: |
|
|
742 | req->result = req->env->memp_sync (req->env, 0); |
|
|
743 | break; |
|
|
744 | |
|
|
745 | case REQ_ENV_MEMP_TRICKLE: |
|
|
746 | req->result = req->env->memp_trickle (req->env, req->int1, &req->int2); |
|
|
747 | break; |
|
|
748 | |
|
|
749 | case REQ_ENV_DBREMOVE: |
|
|
750 | req->result = req->env->dbremove (req->env, req->txn, req->buf1, req->buf2, req->uint1); |
|
|
751 | break; |
|
|
752 | |
|
|
753 | case REQ_ENV_DBRENAME: |
|
|
754 | req->result = req->env->dbrename (req->env, req->txn, req->buf1, req->buf2, req->buf3, req->uint1); |
|
|
755 | break; |
|
|
756 | |
|
|
757 | case REQ_DB_OPEN: |
|
|
758 | req->result = req->db->open (req->db, req->txn, req->buf1, req->buf2, req->int1, req->uint1, req->int2); |
|
|
759 | break; |
|
|
760 | |
|
|
761 | case REQ_DB_CLOSE: |
|
|
762 | req->result = req->db->close (req->db, req->uint1); |
|
|
763 | break; |
|
|
764 | |
|
|
765 | #if DB_VERSION_MINOR >= 4 |
|
|
766 | case REQ_DB_COMPACT: |
|
|
767 | req->result = req->db->compact (req->db, req->txn, &req->dbt1, &req->dbt2, 0, req->uint1, 0); |
|
|
768 | break; |
|
|
769 | #endif |
|
|
770 | |
|
|
771 | case REQ_DB_SYNC: |
|
|
772 | req->result = req->db->sync (req->db, req->uint1); |
|
|
773 | break; |
|
|
774 | |
|
|
775 | case REQ_DB_UPGRADE: |
|
|
776 | req->result = req->db->upgrade (req->db, req->buf1, req->uint1); |
|
|
777 | break; |
|
|
778 | |
|
|
779 | case REQ_DB_PUT: |
|
|
780 | req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1); |
|
|
781 | break; |
|
|
782 | |
|
|
783 | #if DB_VERSION_MINOR >= 6 |
|
|
784 | case REQ_DB_EXISTS: |
|
|
785 | req->result = req->db->exists (req->db, req->txn, &req->dbt1, req->uint1); |
|
|
786 | break; |
|
|
787 | #endif |
|
|
788 | case REQ_DB_GET: |
|
|
789 | req->result = req->db->get (req->db, req->txn, &req->dbt1, &req->dbt3, req->uint1); |
|
|
790 | break; |
|
|
791 | |
|
|
792 | case REQ_DB_PGET: |
|
|
793 | req->result = req->db->pget (req->db, req->txn, &req->dbt1, &req->dbt2, &req->dbt3, req->uint1); |
|
|
794 | break; |
|
|
795 | |
|
|
796 | case REQ_DB_DEL: |
|
|
797 | req->result = req->db->del (req->db, req->txn, &req->dbt1, req->uint1); |
|
|
798 | break; |
|
|
799 | |
|
|
800 | case REQ_DB_KEY_RANGE: |
|
|
801 | req->result = req->db->key_range (req->db, req->txn, &req->dbt1, &req->key_range, req->uint1); |
|
|
802 | break; |
|
|
803 | |
|
|
804 | case REQ_TXN_COMMIT: |
|
|
805 | req->result = req->txn->commit (req->txn, req->uint1); |
|
|
806 | break; |
|
|
807 | |
|
|
808 | case REQ_TXN_ABORT: |
|
|
809 | req->result = req->txn->abort (req->txn); |
|
|
810 | break; |
|
|
811 | |
|
|
812 | case REQ_TXN_FINISH: |
|
|
813 | if (req->txn->flags & TXN_DEADLOCK) |
|
|
814 | { |
|
|
815 | req->result = req->txn->abort (req->txn); |
|
|
816 | if (!req->result) |
|
|
817 | req->result = DB_LOCK_DEADLOCK; |
|
|
818 | } |
|
|
819 | else |
|
|
820 | req->result = req->txn->commit (req->txn, req->uint1); |
|
|
821 | break; |
|
|
822 | |
|
|
823 | case REQ_C_CLOSE: |
|
|
824 | req->result = req->dbc->c_close (req->dbc); |
|
|
825 | break; |
|
|
826 | |
|
|
827 | case REQ_C_COUNT: |
|
|
828 | { |
|
|
829 | db_recno_t recno; |
|
|
830 | req->result = req->dbc->c_count (req->dbc, &recno, req->uint1); |
|
|
831 | req->uv1 = recno; |
|
|
832 | } |
|
|
833 | break; |
|
|
834 | |
|
|
835 | case REQ_C_PUT: |
|
|
836 | req->result = req->dbc->c_put (req->dbc, &req->dbt1, &req->dbt2, req->uint1); |
|
|
837 | break; |
|
|
838 | |
|
|
839 | case REQ_C_GET: |
|
|
840 | req->result = req->dbc->c_get (req->dbc, &req->dbt1, &req->dbt3, req->uint1); |
|
|
841 | break; |
|
|
842 | |
|
|
843 | case REQ_C_PGET: |
|
|
844 | req->result = req->dbc->c_pget (req->dbc, &req->dbt1, &req->dbt2, &req->dbt3, req->uint1); |
|
|
845 | break; |
|
|
846 | |
|
|
847 | case REQ_C_DEL: |
|
|
848 | req->result = req->dbc->c_del (req->dbc, req->uint1); |
|
|
849 | break; |
|
|
850 | |
|
|
851 | #if DB_VERSION_MINOR >= 3 |
|
|
852 | case REQ_SEQ_OPEN: |
|
|
853 | req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1); |
|
|
854 | break; |
|
|
855 | |
|
|
856 | case REQ_SEQ_CLOSE: |
|
|
857 | req->result = req->seq->close (req->seq, req->uint1); |
|
|
858 | break; |
|
|
859 | |
|
|
860 | case REQ_SEQ_GET: |
|
|
861 | req->result = req->seq->get (req->seq, req->txn, req->int1, &req->seq_t, req->uint1); |
|
|
862 | break; |
|
|
863 | |
|
|
864 | case REQ_SEQ_REMOVE: |
|
|
865 | req->result = req->seq->remove (req->seq, req->txn, req->uint1); |
|
|
866 | break; |
|
|
867 | #endif |
|
|
868 | |
|
|
869 | default: |
|
|
870 | req->result = ENOSYS; |
|
|
871 | break; |
|
|
872 | } |
|
|
873 | |
|
|
874 | if (req->txn && (req->result > 0 || req->result == DB_LOCK_NOTGRANTED)) |
|
|
875 | req->txn->flags |= TXN_DEADLOCK; |
|
|
876 | } |
|
|
877 | |
|
|
878 | X_THREAD_PROC (bdb_proc) |
|
|
879 | { |
570 | aio_req req; |
880 | bdb_req req; |
571 | struct timespec ts; |
881 | struct timespec ts; |
572 | worker *self = (worker *)thr_arg; |
882 | worker *self = (worker *)thr_arg; |
573 | |
883 | |
574 | /* try to distribute timeouts somewhat evenly */ |
884 | /* try to distribute timeouts somewhat evenly */ |
575 | ts.tv_nsec = (((unsigned long)self + (unsigned long)ts.tv_sec) & 1023UL) |
885 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
576 | * (1000000000UL / 1024UL); |
|
|
577 | |
886 | |
578 | for (;;) |
887 | for (;;) |
579 | { |
888 | { |
580 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
889 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
581 | |
890 | |
582 | LOCK (reqlock); |
891 | X_LOCK (reqlock); |
583 | |
892 | |
584 | for (;;) |
893 | for (;;) |
585 | { |
894 | { |
586 | self->req = req = reqq_shift (&req_queue); |
895 | self->req = req = reqq_shift (&req_queue); |
587 | |
896 | |
588 | if (req) |
897 | if (req) |
589 | break; |
898 | break; |
590 | |
899 | |
591 | ++idle; |
900 | ++idle; |
592 | |
901 | |
593 | if (pthread_cond_timedwait (&reqwait, &reqlock, &ts) |
902 | if (X_COND_TIMEDWAIT (reqwait, reqlock, ts) |
594 | == ETIMEDOUT) |
903 | == ETIMEDOUT) |
595 | { |
904 | { |
596 | if (idle > max_idle) |
905 | if (idle > max_idle) |
597 | { |
906 | { |
598 | --idle; |
907 | --idle; |
599 | UNLOCK (reqlock); |
908 | X_UNLOCK (reqlock); |
600 | LOCK (wrklock); |
909 | X_LOCK (wrklock); |
601 | --started; |
910 | --started; |
602 | UNLOCK (wrklock); |
911 | X_UNLOCK (wrklock); |
603 | goto quit; |
912 | goto quit; |
604 | } |
913 | } |
605 | |
914 | |
606 | /* we are allowed to idle, so do so without any timeout */ |
915 | /* we are allowed to idle, so do so without any timeout */ |
607 | pthread_cond_wait (&reqwait, &reqlock); |
916 | X_COND_WAIT (reqwait, reqlock); |
608 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
917 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
609 | } |
918 | } |
610 | |
919 | |
611 | --idle; |
920 | --idle; |
612 | } |
921 | } |
613 | |
922 | |
614 | --nready; |
923 | --nready; |
615 | |
924 | |
616 | UNLOCK (reqlock); |
925 | X_UNLOCK (reqlock); |
617 | |
926 | |
618 | switch (req->type) |
927 | if (req->type == REQ_QUIT) |
619 | { |
|
|
620 | case REQ_QUIT: |
|
|
621 | goto quit; |
928 | goto quit; |
622 | |
929 | |
623 | case REQ_ENV_OPEN: |
930 | bdb_request (req); |
624 | req->result = req->env->open (req->env, req->buf1, req->uint1, req->int1); |
|
|
625 | break; |
|
|
626 | |
931 | |
627 | case REQ_ENV_CLOSE: |
|
|
628 | req->result = req->env->close (req->env, req->uint1); |
|
|
629 | break; |
|
|
630 | |
|
|
631 | case REQ_DB_OPEN: |
|
|
632 | req->result = req->db->open (req->db, req->txn, req->buf1, req->buf2, req->int1, req->uint1, req->int2); |
|
|
633 | break; |
|
|
634 | |
|
|
635 | case REQ_DB_CLOSE: |
|
|
636 | req->result = req->db->close (req->db, req->uint1); |
|
|
637 | break; |
|
|
638 | |
|
|
639 | case REQ_DB_COMPACT: |
|
|
640 | req->result = req->db->compact (req->db, req->txn, &req->dbt1, &req->dbt2, 0, req->uint1, 0); |
|
|
641 | break; |
|
|
642 | |
|
|
643 | case REQ_DB_SYNC: |
|
|
644 | req->result = req->db->sync (req->db, req->uint1); |
|
|
645 | break; |
|
|
646 | |
|
|
647 | case REQ_DB_PUT: |
|
|
648 | req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1); |
|
|
649 | break; |
|
|
650 | |
|
|
651 | case REQ_DB_GET: |
|
|
652 | req->result = req->db->get (req->db, req->txn, &req->dbt1, &req->dbt3, req->uint1); |
|
|
653 | break; |
|
|
654 | |
|
|
655 | case REQ_DB_PGET: |
|
|
656 | req->result = req->db->pget (req->db, req->txn, &req->dbt1, &req->dbt2, &req->dbt3, req->uint1); |
|
|
657 | break; |
|
|
658 | |
|
|
659 | case REQ_TXN_COMMIT: |
|
|
660 | req->result = req->txn->commit (req->txn, req->uint1); |
|
|
661 | break; |
|
|
662 | |
|
|
663 | case REQ_TXN_ABORT: |
|
|
664 | req->result = req->txn->abort (req->txn); |
|
|
665 | break; |
|
|
666 | |
|
|
667 | default: |
|
|
668 | req->result = ENOSYS; |
|
|
669 | break; |
|
|
670 | } |
|
|
671 | |
|
|
672 | LOCK (reslock); |
932 | X_LOCK (reslock); |
673 | |
933 | |
674 | ++npending; |
934 | ++npending; |
675 | |
935 | |
676 | if (!reqq_push (&res_queue, req)) |
936 | if (!reqq_push (&res_queue, req)) |
677 | /* write a dummy byte to the pipe so fh becomes ready */ |
937 | /* write a dummy byte to the pipe so fh becomes ready */ |
678 | write (respipe [1], &respipe, 1); |
938 | respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); |
679 | |
939 | |
680 | self->req = 0; |
940 | self->req = 0; |
681 | worker_clear (self); |
941 | worker_clear (self); |
682 | |
942 | |
683 | UNLOCK (reslock); |
943 | X_UNLOCK (reslock); |
684 | } |
944 | } |
685 | |
945 | |
686 | quit: |
946 | quit: |
687 | LOCK (wrklock); |
947 | X_LOCK (wrklock); |
688 | worker_free (self); |
948 | worker_free (self); |
689 | UNLOCK (wrklock); |
949 | X_UNLOCK (wrklock); |
690 | |
950 | |
691 | return 0; |
951 | return 0; |
692 | } |
952 | } |
693 | |
953 | |
694 | /*****************************************************************************/ |
954 | /*****************************************************************************/ |
695 | |
955 | |
696 | static void atfork_prepare (void) |
956 | static void atfork_prepare (void) |
697 | { |
957 | { |
698 | LOCK (wrklock); |
958 | X_LOCK (wrklock); |
699 | LOCK (reqlock); |
959 | X_LOCK (reqlock); |
700 | LOCK (reslock); |
960 | X_LOCK (reslock); |
701 | } |
961 | } |
702 | |
962 | |
703 | static void atfork_parent (void) |
963 | static void atfork_parent (void) |
704 | { |
964 | { |
705 | UNLOCK (reslock); |
965 | X_UNLOCK (reslock); |
706 | UNLOCK (reqlock); |
966 | X_UNLOCK (reqlock); |
707 | UNLOCK (wrklock); |
967 | X_UNLOCK (wrklock); |
708 | } |
968 | } |
709 | |
969 | |
710 | static void atfork_child (void) |
970 | static void atfork_child (void) |
711 | { |
971 | { |
712 | aio_req prv; |
972 | bdb_req prv; |
713 | |
973 | |
714 | while (prv = reqq_shift (&req_queue)) |
974 | while (prv = reqq_shift (&req_queue)) |
715 | req_free (prv); |
975 | req_free (prv); |
716 | |
976 | |
717 | while (prv = reqq_shift (&res_queue)) |
977 | while (prv = reqq_shift (&res_queue)) |
… | |
… | |
732 | idle = 0; |
992 | idle = 0; |
733 | nreqs = 0; |
993 | nreqs = 0; |
734 | nready = 0; |
994 | nready = 0; |
735 | npending = 0; |
995 | npending = 0; |
736 | |
996 | |
737 | close (respipe [0]); |
|
|
738 | close (respipe [1]); |
|
|
739 | create_pipe (); |
997 | create_respipe (); |
740 | |
998 | |
741 | atfork_parent (); |
999 | atfork_parent (); |
742 | } |
1000 | } |
743 | |
1001 | |
744 | #define dREQ(reqtype) \ |
1002 | #define dREQ(reqtype,rsvcnt) \ |
745 | aio_req req; \ |
1003 | bdb_req req; \ |
746 | int req_pri = next_pri; \ |
1004 | int req_pri = next_pri; \ |
747 | next_pri = DEFAULT_PRI + PRI_BIAS; \ |
1005 | next_pri = DEFAULT_PRI + PRI_BIAS; \ |
748 | \ |
1006 | \ |
749 | if (SvOK (callback) && !SvROK (callback)) \ |
1007 | if (callback && SvOK (callback)) \ |
750 | croak ("callback must be undef or of reference type"); \ |
1008 | croak ("callback has illegal type or extra arguments"); \ |
751 | \ |
1009 | \ |
752 | Newz (0, req, 1, aio_cb); \ |
1010 | Newz (0, req, 1, bdb_cb); \ |
753 | if (!req) \ |
1011 | if (!req) \ |
754 | croak ("out of memory during aio_req allocation"); \ |
1012 | croak ("out of memory during bdb_req allocation"); \ |
755 | \ |
1013 | \ |
756 | req->callback = newSVsv (callback); \ |
1014 | req->callback = SvREFCNT_inc (cb); \ |
757 | req->type = (reqtype); \ |
1015 | req->type = (reqtype); \ |
758 | req->pri = req_pri |
1016 | req->pri = req_pri; \ |
|
|
1017 | if (rsvcnt >= 1) req->rsv1 = SvREFCNT_inc (ST (0)); \ |
|
|
1018 | if (rsvcnt >= 2) req->rsv2 = SvREFCNT_inc (ST (1)); \ |
|
|
1019 | (void)0; |
759 | |
1020 | |
760 | #define REQ_SEND \ |
1021 | #define REQ_SEND \ |
761 | req_send (req) |
1022 | req_send (req) |
762 | |
1023 | |
763 | #define SvPTR(var, arg, type, class, nullok) \ |
1024 | #define SvPTR(var, arg, type, class, nullok) \ |
764 | if (!SvOK (arg)) \ |
1025 | if (!SvOK (arg)) \ |
765 | { \ |
1026 | { \ |
766 | if (!nullok) \ |
1027 | if (nullok != 1) \ |
767 | Perl_croak (# var " must be a " # class " object, not undef"); \ |
1028 | croak (# var " must be a " # class " object, not undef"); \ |
768 | \ |
1029 | \ |
769 | (var) = 0; \ |
1030 | (var) = 0; \ |
770 | } \ |
1031 | } \ |
771 | else if (sv_derived_from ((arg), # class)) \ |
1032 | else if (sv_derived_from ((arg), # class)) \ |
772 | { \ |
1033 | { \ |
773 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
1034 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
774 | (var) = INT2PTR (type, tmp); \ |
1035 | (var) = INT2PTR (type, tmp); \ |
775 | if (!var) \ |
1036 | if (!var && nullok != 2) \ |
776 | Perl_croak (# var " is not a valid " # class " object anymore"); \ |
1037 | croak (# var " is not a valid " # class " object anymore"); \ |
777 | } \ |
1038 | } \ |
778 | else \ |
1039 | else \ |
779 | Perl_croak (# var " is not of type " # class); \ |
1040 | croak (# var " is not of type " # class); |
780 | \ |
|
|
781 | |
1041 | |
782 | static void |
1042 | static void |
783 | ptr_nuke (SV *sv) |
1043 | ptr_nuke (SV *sv) |
784 | { |
1044 | { |
785 | assert (SvROK (sv)); |
1045 | assert (SvROK (sv)); |
786 | sv_setiv (SvRV (sv), 0); |
1046 | sv_setiv (SvRV (sv), 0); |
787 | } |
1047 | } |
|
|
1048 | |
|
|
1049 | static int |
|
|
1050 | errno_get (pTHX_ SV *sv, MAGIC *mg) |
|
|
1051 | { |
|
|
1052 | if (*mg->mg_ptr == '!') // should always be the case |
|
|
1053 | if (-30999 <= errno && errno <= -30800) |
|
|
1054 | { |
|
|
1055 | sv_setnv (sv, (NV)errno); |
|
|
1056 | sv_setpv (sv, db_strerror (errno)); |
|
|
1057 | SvNOK_on (sv); /* what a wonderful hack! */ |
|
|
1058 | // ^^^ copied from perl sources |
|
|
1059 | return 0; |
|
|
1060 | } |
|
|
1061 | |
|
|
1062 | return PL_vtbl_sv.svt_get (aTHX_ sv, mg); |
|
|
1063 | } |
|
|
1064 | |
|
|
1065 | static MGVTBL vtbl_errno; |
|
|
1066 | |
|
|
1067 | // this wonderful hack :( patches perl's $! variable to support our errno values |
|
|
1068 | static void |
|
|
1069 | patch_errno (void) |
|
|
1070 | { |
|
|
1071 | SV *sv; |
|
|
1072 | MAGIC *mg; |
|
|
1073 | |
|
|
1074 | if (!(sv = get_sv ("!", 1))) |
|
|
1075 | return; |
|
|
1076 | |
|
|
1077 | if (!(mg = mg_find (sv, PERL_MAGIC_sv))) |
|
|
1078 | return; |
|
|
1079 | |
|
|
1080 | if (mg->mg_virtual != &PL_vtbl_sv) |
|
|
1081 | return; |
|
|
1082 | |
|
|
1083 | vtbl_errno = PL_vtbl_sv; |
|
|
1084 | vtbl_errno.svt_get = errno_get; |
|
|
1085 | mg->mg_virtual = &vtbl_errno; |
|
|
1086 | } |
|
|
1087 | |
|
|
1088 | #if __GNUC__ >= 4 |
|
|
1089 | # define noinline __attribute__ ((noinline)) |
|
|
1090 | #else |
|
|
1091 | # define noinline |
|
|
1092 | #endif |
|
|
1093 | |
|
|
1094 | static noinline SV * |
|
|
1095 | pop_callback (I32 *ritems, SV *sv) |
|
|
1096 | { |
|
|
1097 | if (SvROK (sv)) |
|
|
1098 | { |
|
|
1099 | HV *st; |
|
|
1100 | GV *gvp; |
|
|
1101 | CV *cv; |
|
|
1102 | const char *name; |
|
|
1103 | |
|
|
1104 | /* forgive me */ |
|
|
1105 | if (SvTYPE (SvRV (sv)) == SVt_PVMG |
|
|
1106 | && (st = SvSTASH (SvRV (sv))) |
|
|
1107 | && (name = HvNAME_get (st)) |
|
|
1108 | && (name [0] == 'B' && name [1] == 'D' && name [2] == 'B' && name [3] == ':')) |
|
|
1109 | return 0; |
|
|
1110 | |
|
|
1111 | if ((cv = sv_2cv (sv, &st, &gvp, 0))) |
|
|
1112 | { |
|
|
1113 | --*ritems; |
|
|
1114 | return (SV *)cv; |
|
|
1115 | } |
|
|
1116 | } |
|
|
1117 | |
|
|
1118 | return 0; |
|
|
1119 | } |
|
|
1120 | |
|
|
1121 | /* stupid windoes defined CALLBACK as well */ |
|
|
1122 | #undef CALLBACK |
|
|
1123 | #define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); |
788 | |
1124 | |
789 | MODULE = BDB PACKAGE = BDB |
1125 | MODULE = BDB PACKAGE = BDB |
790 | |
1126 | |
791 | PROTOTYPES: ENABLE |
1127 | PROTOTYPES: ENABLE |
792 | |
1128 | |
… | |
… | |
808 | const_iv (INIT_TXN) |
1144 | const_iv (INIT_TXN) |
809 | const_iv (RECOVER) |
1145 | const_iv (RECOVER) |
810 | const_iv (INIT_TXN) |
1146 | const_iv (INIT_TXN) |
811 | const_iv (RECOVER_FATAL) |
1147 | const_iv (RECOVER_FATAL) |
812 | const_iv (CREATE) |
1148 | const_iv (CREATE) |
|
|
1149 | const_iv (RDONLY) |
813 | const_iv (USE_ENVIRON) |
1150 | const_iv (USE_ENVIRON) |
814 | const_iv (USE_ENVIRON_ROOT) |
1151 | const_iv (USE_ENVIRON_ROOT) |
815 | const_iv (LOCKDOWN) |
1152 | const_iv (LOCKDOWN) |
816 | const_iv (PRIVATE) |
1153 | const_iv (PRIVATE) |
817 | const_iv (REGISTER) |
|
|
818 | const_iv (SYSTEM_MEM) |
1154 | const_iv (SYSTEM_MEM) |
819 | const_iv (AUTO_COMMIT) |
1155 | const_iv (AUTO_COMMIT) |
820 | const_iv (CDB_ALLDB) |
1156 | const_iv (CDB_ALLDB) |
821 | const_iv (DIRECT_DB) |
1157 | const_iv (DIRECT_DB) |
822 | const_iv (DIRECT_LOG) |
|
|
823 | const_iv (DSYNC_DB) |
|
|
824 | const_iv (DSYNC_LOG) |
|
|
825 | const_iv (LOG_AUTOREMOVE) |
|
|
826 | const_iv (LOG_INMEMORY) |
|
|
827 | const_iv (NOLOCKING) |
1158 | const_iv (NOLOCKING) |
828 | const_iv (MULTIVERSION) |
|
|
829 | const_iv (NOMMAP) |
1159 | const_iv (NOMMAP) |
830 | const_iv (NOPANIC) |
1160 | const_iv (NOPANIC) |
831 | const_iv (OVERWRITE) |
1161 | const_iv (OVERWRITE) |
832 | const_iv (PANIC_ENVIRONMENT) |
1162 | const_iv (PANIC_ENVIRONMENT) |
833 | const_iv (REGION_INIT) |
1163 | const_iv (REGION_INIT) |
834 | const_iv (TIME_NOTGRANTED) |
1164 | const_iv (TIME_NOTGRANTED) |
835 | const_iv (TXN_NOSYNC) |
1165 | const_iv (TXN_NOSYNC) |
836 | const_iv (TXN_SNAPSHOT) |
1166 | const_iv (TXN_NOT_DURABLE) |
837 | const_iv (TXN_WRITE_NOSYNC) |
1167 | const_iv (TXN_WRITE_NOSYNC) |
838 | const_iv (WRITECURSOR) |
1168 | const_iv (WRITECURSOR) |
839 | const_iv (YIELDCPU) |
1169 | const_iv (YIELDCPU) |
840 | const_iv (ENCRYPT_AES) |
1170 | const_iv (ENCRYPT_AES) |
841 | const_iv (XA_CREATE) |
1171 | const_iv (XA_CREATE) |
… | |
… | |
843 | const_iv (HASH) |
1173 | const_iv (HASH) |
844 | const_iv (QUEUE) |
1174 | const_iv (QUEUE) |
845 | const_iv (RECNO) |
1175 | const_iv (RECNO) |
846 | const_iv (UNKNOWN) |
1176 | const_iv (UNKNOWN) |
847 | const_iv (EXCL) |
1177 | const_iv (EXCL) |
848 | const_iv (READ_COMMITTED) |
|
|
849 | const_iv (READ_UNCOMMITTED) |
|
|
850 | const_iv (TRUNCATE) |
1178 | const_iv (TRUNCATE) |
851 | const_iv (NOSYNC) |
1179 | const_iv (NOSYNC) |
852 | const_iv (CHKSUM) |
1180 | const_iv (CHKSUM) |
853 | const_iv (ENCRYPT) |
1181 | const_iv (ENCRYPT) |
854 | const_iv (TXN_NOT_DURABLE) |
|
|
855 | const_iv (DUP) |
1182 | const_iv (DUP) |
856 | const_iv (DUPSORT) |
1183 | const_iv (DUPSORT) |
857 | const_iv (RECNUM) |
1184 | const_iv (RECNUM) |
858 | const_iv (RENUMBER) |
1185 | const_iv (RENUMBER) |
859 | const_iv (REVSPLITOFF) |
1186 | const_iv (REVSPLITOFF) |
860 | const_iv (INORDER) |
|
|
861 | const_iv (CONSUME) |
1187 | const_iv (CONSUME) |
862 | const_iv (CONSUME_WAIT) |
1188 | const_iv (CONSUME_WAIT) |
863 | const_iv (GET_BOTH) |
1189 | const_iv (GET_BOTH) |
|
|
1190 | const_iv (GET_BOTH_RANGE) |
864 | //const_iv (SET_RECNO) |
1191 | //const_iv (SET_RECNO) |
865 | //const_iv (MULTIPLE) |
1192 | //const_iv (MULTIPLE) |
866 | const_iv (SNAPSHOT) |
1193 | const_iv (SNAPSHOT) |
867 | const_iv (JOIN_ITEM) |
1194 | const_iv (JOIN_ITEM) |
|
|
1195 | const_iv (JOIN_NOSORT) |
868 | const_iv (RMW) |
1196 | const_iv (RMW) |
869 | |
1197 | |
870 | const_iv (NOTFOUND) |
1198 | const_iv (NOTFOUND) |
871 | const_iv (KEYEMPTY) |
1199 | const_iv (KEYEMPTY) |
872 | const_iv (LOCK_DEADLOCK) |
1200 | const_iv (LOCK_DEADLOCK) |
873 | const_iv (LOCK_NOTGRANTED) |
1201 | const_iv (LOCK_NOTGRANTED) |
874 | const_iv (RUNRECOVERY) |
1202 | const_iv (RUNRECOVERY) |
875 | const_iv (OLD_VERSION) |
1203 | const_iv (OLD_VERSION) |
876 | const_iv (REP_HANDLE_DEAD) |
1204 | const_iv (REP_HANDLE_DEAD) |
877 | const_iv (REP_LOCKOUT) |
1205 | const_iv (SECONDARY_BAD) |
878 | |
|
|
879 | const_iv (FREE_SPACE) |
|
|
880 | const_iv (FREELIST_ONLY) |
|
|
881 | |
1206 | |
882 | const_iv (APPEND) |
1207 | const_iv (APPEND) |
883 | const_iv (NODUPDATA) |
1208 | const_iv (NODUPDATA) |
884 | const_iv (NOOVERWRITE) |
1209 | const_iv (NOOVERWRITE) |
885 | |
1210 | |
886 | const_iv (TXN_NOWAIT) |
1211 | const_iv (TXN_NOWAIT) |
887 | const_iv (TXN_SNAPSHOT) |
|
|
888 | const_iv (TXN_SYNC) |
1212 | const_iv (TXN_SYNC) |
889 | |
1213 | |
890 | const_iv (SET_LOCK_TIMEOUT) |
1214 | const_iv (SET_LOCK_TIMEOUT) |
891 | const_iv (SET_TXN_TIMEOUT) |
1215 | const_iv (SET_TXN_TIMEOUT) |
|
|
1216 | |
|
|
1217 | const_iv (FIRST) |
|
|
1218 | const_iv (NEXT) |
|
|
1219 | const_iv (NEXT_DUP) |
|
|
1220 | const_iv (NEXT_NODUP) |
|
|
1221 | const_iv (PREV) |
|
|
1222 | const_iv (PREV_NODUP) |
|
|
1223 | const_iv (SET) |
|
|
1224 | const_iv (SET_RANGE) |
|
|
1225 | const_iv (LAST) |
|
|
1226 | const_iv (BEFORE) |
|
|
1227 | const_iv (AFTER) |
|
|
1228 | const_iv (CURRENT) |
|
|
1229 | const_iv (KEYFIRST) |
|
|
1230 | const_iv (KEYLAST) |
|
|
1231 | const_iv (NODUPDATA) |
|
|
1232 | |
|
|
1233 | const_iv (FORCE) |
|
|
1234 | |
|
|
1235 | const_iv (LOCK_DEFAULT) |
|
|
1236 | const_iv (LOCK_EXPIRE) |
|
|
1237 | const_iv (LOCK_MAXLOCKS) |
|
|
1238 | const_iv (LOCK_MINLOCKS) |
|
|
1239 | const_iv (LOCK_MINWRITE) |
|
|
1240 | const_iv (LOCK_OLDEST) |
|
|
1241 | const_iv (LOCK_RANDOM) |
|
|
1242 | const_iv (LOCK_YOUNGEST) |
|
|
1243 | |
|
|
1244 | const_iv (DONOTINDEX) |
|
|
1245 | const_iv (KEYEMPTY ) |
|
|
1246 | const_iv (KEYEXIST ) |
|
|
1247 | const_iv (LOCK_DEADLOCK) |
|
|
1248 | const_iv (LOCK_NOTGRANTED) |
|
|
1249 | const_iv (NOSERVER) |
|
|
1250 | const_iv (NOSERVER_HOME) |
|
|
1251 | const_iv (NOSERVER_ID) |
|
|
1252 | const_iv (NOTFOUND) |
|
|
1253 | const_iv (PAGE_NOTFOUND) |
|
|
1254 | const_iv (REP_DUPMASTER) |
|
|
1255 | const_iv (REP_HANDLE_DEAD) |
|
|
1256 | const_iv (REP_HOLDELECTION) |
|
|
1257 | const_iv (REP_ISPERM) |
|
|
1258 | const_iv (REP_NEWMASTER) |
|
|
1259 | const_iv (REP_NEWSITE) |
|
|
1260 | const_iv (REP_NOTPERM) |
|
|
1261 | const_iv (REP_UNAVAIL) |
|
|
1262 | const_iv (RUNRECOVERY) |
|
|
1263 | const_iv (SECONDARY_BAD) |
|
|
1264 | const_iv (VERIFY_BAD) |
|
|
1265 | |
|
|
1266 | const_iv (VERB_DEADLOCK) |
|
|
1267 | const_iv (VERB_RECOVERY) |
|
|
1268 | const_iv (VERB_REPLICATION) |
|
|
1269 | const_iv (VERB_WAITSFOR) |
|
|
1270 | |
|
|
1271 | const_iv (VERSION_MAJOR) |
|
|
1272 | const_iv (VERSION_MINOR) |
|
|
1273 | const_iv (VERSION_PATCH) |
|
|
1274 | #if DB_VERSION_MINOR >= 3 |
|
|
1275 | const_iv (INORDER) |
|
|
1276 | const_iv (LOCK_MAXWRITE) |
|
|
1277 | const_iv (SEQ_DEC) |
|
|
1278 | const_iv (SEQ_INC) |
|
|
1279 | const_iv (SEQ_WRAP) |
|
|
1280 | const_iv (BUFFER_SMALL) |
|
|
1281 | const_iv (LOG_BUFFER_FULL) |
|
|
1282 | const_iv (VERSION_MISMATCH) |
|
|
1283 | #endif |
|
|
1284 | #if DB_VERSION_MINOR >= 4 |
|
|
1285 | const_iv (REGISTER) |
|
|
1286 | const_iv (DSYNC_DB) |
|
|
1287 | const_iv (READ_COMMITTED) |
|
|
1288 | const_iv (READ_UNCOMMITTED) |
|
|
1289 | const_iv (REP_IGNORE) |
|
|
1290 | const_iv (REP_LOCKOUT) |
|
|
1291 | const_iv (REP_JOIN_FAILURE) |
|
|
1292 | const_iv (FREE_SPACE) |
|
|
1293 | const_iv (FREELIST_ONLY) |
|
|
1294 | const_iv (VERB_REGISTER) |
|
|
1295 | #endif |
|
|
1296 | #if DB_VERSION_MINOR >= 5 |
|
|
1297 | const_iv (MULTIVERSION) |
|
|
1298 | const_iv (TXN_SNAPSHOT) |
|
|
1299 | #endif |
|
|
1300 | #if DB_VERSION_MINOR >= 6 |
|
|
1301 | const_iv (PREV_DUP) |
|
|
1302 | const_iv (PRIORITY_UNCHANGED) |
|
|
1303 | const_iv (PRIORITY_VERY_LOW) |
|
|
1304 | const_iv (PRIORITY_LOW) |
|
|
1305 | const_iv (PRIORITY_DEFAULT) |
|
|
1306 | const_iv (PRIORITY_HIGH) |
|
|
1307 | const_iv (PRIORITY_VERY_HIGH) |
|
|
1308 | #endif |
|
|
1309 | #if DB_VERSION_MINOR >= 7 |
|
|
1310 | const_iv (LOG_DIRECT) |
|
|
1311 | const_iv (LOG_DSYNC) |
|
|
1312 | const_iv (LOG_AUTO_REMOVE) |
|
|
1313 | const_iv (LOG_IN_MEMORY) |
|
|
1314 | const_iv (LOG_ZERO) |
|
|
1315 | #else |
|
|
1316 | const_iv (DIRECT_LOG) |
|
|
1317 | const_iv (LOG_AUTOREMOVE) |
|
|
1318 | # if DB_VERSION_MINOR >= 3 |
|
|
1319 | const_iv (DSYNC_LOG) |
|
|
1320 | const_iv (LOG_INMEMORY) |
|
|
1321 | # endif |
|
|
1322 | #endif |
892 | }; |
1323 | }; |
893 | |
1324 | |
894 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1325 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
895 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1326 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
896 | |
1327 | |
897 | create_pipe (); |
1328 | { |
|
|
1329 | /* we currently only allow version, minor-version and patchlevel to go up to 255 */ |
|
|
1330 | char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; |
|
|
1331 | |
|
|
1332 | newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); |
|
|
1333 | } |
|
|
1334 | |
|
|
1335 | newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
|
|
1336 | |
|
|
1337 | create_respipe (); |
|
|
1338 | |
898 | pthread_atfork (atfork_prepare, atfork_parent, atfork_child); |
1339 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
|
|
1340 | patch_errno (); |
899 | } |
1341 | } |
900 | |
1342 | |
901 | void |
1343 | void |
902 | max_poll_reqs (int nreqs) |
1344 | max_poll_reqs (int nreqs) |
903 | PROTOTYPE: $ |
1345 | PROTOTYPE: $ |
… | |
… | |
1022 | |
1464 | |
1023 | int |
1465 | int |
1024 | nthreads () |
1466 | nthreads () |
1025 | PROTOTYPE: |
1467 | PROTOTYPE: |
1026 | CODE: |
1468 | CODE: |
1027 | if (WORDACCESS_UNSAFE) LOCK (wrklock); |
1469 | if (WORDACCESS_UNSAFE) X_LOCK (wrklock); |
1028 | RETVAL = started; |
1470 | RETVAL = started; |
1029 | if (WORDACCESS_UNSAFE) UNLOCK (wrklock); |
1471 | if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock); |
1030 | OUTPUT: |
1472 | OUTPUT: |
1031 | RETVAL |
1473 | RETVAL |
1032 | |
1474 | |
1033 | void |
1475 | void |
1034 | set_sync_prepare (SV *cb) |
1476 | set_sync_prepare (SV *cb) |
1035 | PROTOTYPE: & |
1477 | PROTOTYPE: & |
1036 | CODE: |
1478 | CODE: |
1037 | SvREFCNT_dec (prepare_cb); |
1479 | SvREFCNT_dec (prepare_cb); |
1038 | prepare_cb = newSVsv (cb); |
1480 | prepare_cb = newSVsv (cb); |
|
|
1481 | |
|
|
1482 | char * |
|
|
1483 | strerror (int errorno = errno) |
|
|
1484 | PROTOTYPE: ;$ |
|
|
1485 | CODE: |
|
|
1486 | RETVAL = db_strerror (errorno); |
|
|
1487 | OUTPUT: |
|
|
1488 | RETVAL |
|
|
1489 | |
|
|
1490 | void _on_next_submit (SV *cb) |
|
|
1491 | CODE: |
|
|
1492 | SvREFCNT_dec (on_next_submit); |
|
|
1493 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1039 | |
1494 | |
1040 | DB_ENV * |
1495 | DB_ENV * |
1041 | db_env_create (U32 env_flags = 0) |
1496 | db_env_create (U32 env_flags = 0) |
1042 | CODE: |
1497 | CODE: |
1043 | { |
1498 | { |
1044 | errno = db_env_create (&RETVAL, env_flags); |
1499 | errno = db_env_create (&RETVAL, env_flags); |
1045 | if (errno) |
1500 | if (errno) |
1046 | croak ("db_env_create: %s", db_strerror (errno)); |
1501 | croak ("db_env_create: %s", db_strerror (errno)); |
|
|
1502 | |
|
|
1503 | if (0) |
|
|
1504 | { |
|
|
1505 | RETVAL->set_errcall (RETVAL, debug_errcall); |
|
|
1506 | RETVAL->set_msgcall (RETVAL, debug_msgcall); |
|
|
1507 | } |
1047 | } |
1508 | } |
1048 | OUTPUT: |
1509 | OUTPUT: |
1049 | RETVAL |
1510 | RETVAL |
1050 | |
1511 | |
1051 | void |
1512 | void |
1052 | db_env_open (DB_ENV *env, octetstring db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef) |
1513 | db_env_open (DB_ENV *env, bdb_filename db_home, U32 open_flags, int mode, SV *callback = 0) |
|
|
1514 | PREINIT: |
|
|
1515 | CALLBACK |
1053 | CODE: |
1516 | CODE: |
1054 | { |
1517 | { |
1055 | dREQ (REQ_ENV_OPEN); |
1518 | dREQ (REQ_ENV_OPEN, 1); |
1056 | req->env = env; |
1519 | req->env = env; |
1057 | req->uint1 = open_flags | DB_THREAD; |
1520 | req->uint1 = open_flags | DB_THREAD; |
1058 | req->int1 = mode; |
1521 | req->int1 = mode; |
1059 | req->buf1 = strdup_ornull (db_home); |
1522 | req->buf1 = strdup_ornull (db_home); |
1060 | REQ_SEND; |
1523 | REQ_SEND; |
1061 | } |
1524 | } |
1062 | |
1525 | |
1063 | void |
1526 | void |
1064 | db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = &PL_sv_undef) |
1527 | db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0) |
|
|
1528 | PREINIT: |
|
|
1529 | CALLBACK |
1065 | CODE: |
1530 | CODE: |
1066 | { |
1531 | { |
1067 | dREQ (REQ_ENV_CLOSE); |
1532 | dREQ (REQ_ENV_CLOSE, 1); |
1068 | req->env = env; |
1533 | req->env = env; |
1069 | req->uint1 = flags; |
1534 | req->uint1 = flags; |
1070 | REQ_SEND; |
1535 | REQ_SEND; |
1071 | ptr_nuke (ST (0)); |
1536 | ptr_nuke (ST (0)); |
1072 | } |
1537 | } |
1073 | |
1538 | |
|
|
1539 | void |
|
|
1540 | db_env_txn_checkpoint (DB_ENV *env, U32 kbyte = 0, U32 min = 0, U32 flags = 0, SV *callback = 0) |
|
|
1541 | PREINIT: |
|
|
1542 | CALLBACK |
|
|
1543 | CODE: |
|
|
1544 | { |
|
|
1545 | dREQ (REQ_ENV_TXN_CHECKPOINT, 1); |
|
|
1546 | req->env = env; |
|
|
1547 | req->uint1 = kbyte; |
|
|
1548 | req->int1 = min; |
|
|
1549 | req->uint2 = flags; |
|
|
1550 | REQ_SEND; |
|
|
1551 | } |
|
|
1552 | |
|
|
1553 | void |
|
|
1554 | db_env_lock_detect (DB_ENV *env, U32 flags = 0, U32 atype = DB_LOCK_DEFAULT, SV *dummy = 0, SV *callback = 0) |
|
|
1555 | PREINIT: |
|
|
1556 | CALLBACK |
|
|
1557 | CODE: |
|
|
1558 | { |
|
|
1559 | dREQ (REQ_ENV_LOCK_DETECT, 1); |
|
|
1560 | req->env = env; |
|
|
1561 | req->uint1 = flags; |
|
|
1562 | req->uint2 = atype; |
|
|
1563 | /* req->int2 = 0; dummy */ |
|
|
1564 | REQ_SEND; |
|
|
1565 | } |
|
|
1566 | |
|
|
1567 | void |
|
|
1568 | db_env_memp_sync (DB_ENV *env, SV *dummy = 0, SV *callback = 0) |
|
|
1569 | PREINIT: |
|
|
1570 | CALLBACK |
|
|
1571 | CODE: |
|
|
1572 | { |
|
|
1573 | dREQ (REQ_ENV_MEMP_SYNC, 1); |
|
|
1574 | req->env = env; |
|
|
1575 | REQ_SEND; |
|
|
1576 | } |
|
|
1577 | |
|
|
1578 | void |
|
|
1579 | db_env_memp_trickle (DB_ENV *env, int percent, SV *dummy = 0, SV *callback = 0) |
|
|
1580 | PREINIT: |
|
|
1581 | CALLBACK |
|
|
1582 | CODE: |
|
|
1583 | { |
|
|
1584 | dREQ (REQ_ENV_MEMP_TRICKLE, 1); |
|
|
1585 | req->env = env; |
|
|
1586 | req->int1 = percent; |
|
|
1587 | REQ_SEND; |
|
|
1588 | } |
|
|
1589 | |
|
|
1590 | void |
|
|
1591 | db_env_dbremove (DB_ENV *env, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, U32 flags = 0, SV *callback = 0) |
|
|
1592 | PREINIT: |
|
|
1593 | CALLBACK |
|
|
1594 | CODE: |
|
|
1595 | { |
|
|
1596 | dREQ (REQ_ENV_DBREMOVE, 2); |
|
|
1597 | req->env = env; |
|
|
1598 | req->buf1 = strdup_ornull (file); |
|
|
1599 | req->buf2 = strdup_ornull (database); |
|
|
1600 | req->uint1 = flags; |
|
|
1601 | REQ_SEND; |
|
|
1602 | } |
|
|
1603 | |
|
|
1604 | void |
|
|
1605 | db_env_dbrename (DB_ENV *env, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, bdb_filename newname, U32 flags = 0, SV *callback = 0) |
|
|
1606 | PREINIT: |
|
|
1607 | CALLBACK |
|
|
1608 | CODE: |
|
|
1609 | { |
|
|
1610 | dREQ (REQ_ENV_DBRENAME, 2); |
|
|
1611 | req->env = env; |
|
|
1612 | req->buf1 = strdup_ornull (file); |
|
|
1613 | req->buf2 = strdup_ornull (database); |
|
|
1614 | req->buf3 = strdup_ornull (newname); |
|
|
1615 | req->uint1 = flags; |
|
|
1616 | REQ_SEND; |
|
|
1617 | } |
|
|
1618 | |
1074 | DB * |
1619 | DB * |
1075 | db_create (DB_ENV *env = 0, U32 flags = 0) |
1620 | db_create (DB_ENV *env = 0, U32 flags = 0) |
1076 | CODE: |
1621 | CODE: |
1077 | { |
1622 | { |
1078 | errno = db_create (&RETVAL, env, flags); |
1623 | errno = db_create (&RETVAL, env, flags); |
1079 | if (errno) |
1624 | if (errno) |
1080 | croak ("db_env_create: %s", db_strerror (errno)); |
1625 | croak ("db_create: %s", db_strerror (errno)); |
1081 | |
1626 | |
1082 | if (RETVAL) |
1627 | if (RETVAL) |
1083 | RETVAL->app_private = (void *)newSVsv (ST (0)); |
1628 | RETVAL->app_private = (void *)newSVsv (ST (0)); |
1084 | } |
1629 | } |
1085 | OUTPUT: |
1630 | OUTPUT: |
1086 | RETVAL |
1631 | RETVAL |
1087 | |
1632 | |
1088 | void |
1633 | void |
1089 | db_open (DB *db, DB_TXN_ornull *txnid, octetstring file, octetstring database, int type, U32 flags, int mode, SV *callback = &PL_sv_undef) |
1634 | db_open (DB *db, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, int type, U32 flags, int mode, SV *callback = 0) |
|
|
1635 | PREINIT: |
|
|
1636 | CALLBACK |
1090 | CODE: |
1637 | CODE: |
1091 | { |
1638 | { |
1092 | dREQ (REQ_DB_OPEN); |
1639 | dREQ (REQ_DB_OPEN, 2); |
1093 | req->db = db; |
1640 | req->db = db; |
1094 | req->txn = txnid; |
1641 | req->txn = txnid; |
1095 | req->buf1 = strdup_ornull (file); |
1642 | req->buf1 = strdup_ornull (file); |
1096 | req->buf2 = strdup_ornull (database); |
1643 | req->buf2 = strdup_ornull (database); |
1097 | req->int1 = type; |
1644 | req->int1 = type; |
… | |
… | |
1099 | req->int2 = mode; |
1646 | req->int2 = mode; |
1100 | REQ_SEND; |
1647 | REQ_SEND; |
1101 | } |
1648 | } |
1102 | |
1649 | |
1103 | void |
1650 | void |
1104 | db_close (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) |
1651 | db_close (DB *db, U32 flags = 0, SV *callback = 0) |
|
|
1652 | PREINIT: |
|
|
1653 | CALLBACK |
1105 | CODE: |
1654 | CODE: |
1106 | { |
1655 | { |
1107 | dREQ (REQ_DB_CLOSE); |
1656 | dREQ (REQ_DB_CLOSE, 1); |
1108 | req->db = db; |
1657 | req->db = db; |
1109 | req->uint1 = flags; |
1658 | req->uint1 = flags; |
1110 | req->sv1 = (SV *)db->app_private; |
1659 | req->sv1 = (SV *)db->app_private; |
1111 | REQ_SEND; |
1660 | REQ_SEND; |
1112 | ptr_nuke (ST (0)); |
1661 | ptr_nuke (ST (0)); |
1113 | } |
1662 | } |
1114 | |
1663 | |
|
|
1664 | #if DB_VERSION_MINOR >= 4 |
|
|
1665 | |
1115 | void |
1666 | void |
1116 | db_compact (DB *db, DB_TXN_ornull *txn = 0, SV *start = 0, SV *stop = 0, SV *unused1 = 0, U32 flags = DB_FREE_SPACE, SV *unused2 = 0, SV *callback = &PL_sv_undef) |
1667 | db_compact (DB *db, DB_TXN_ornull *txn = 0, SV *start = 0, SV *stop = 0, SV *unused1 = 0, U32 flags = DB_FREE_SPACE, SV *unused2 = 0, SV *callback = 0) |
|
|
1668 | PREINIT: |
|
|
1669 | CALLBACK |
1117 | CODE: |
1670 | CODE: |
1118 | { |
1671 | { |
1119 | dREQ (REQ_DB_COMPACT); |
1672 | dREQ (REQ_DB_COMPACT, 2); |
1120 | req->db = db; |
1673 | req->db = db; |
1121 | req->txn = txn; |
1674 | req->txn = txn; |
1122 | sv_to_dbt (&req->dbt1, start); |
1675 | sv_to_dbt (&req->dbt1, start); |
1123 | sv_to_dbt (&req->dbt2, stop); |
1676 | sv_to_dbt (&req->dbt2, stop); |
1124 | req->uint1 = flags; |
1677 | req->uint1 = flags; |
1125 | REQ_SEND; |
1678 | REQ_SEND; |
1126 | } |
1679 | } |
1127 | |
1680 | |
|
|
1681 | #endif |
|
|
1682 | |
1128 | void |
1683 | void |
1129 | db_sync (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) |
1684 | db_sync (DB *db, U32 flags = 0, SV *callback = 0) |
|
|
1685 | PREINIT: |
|
|
1686 | CALLBACK |
1130 | CODE: |
1687 | CODE: |
1131 | { |
1688 | { |
1132 | dREQ (REQ_DB_SYNC); |
1689 | dREQ (REQ_DB_SYNC, 1); |
1133 | req->db = db; |
1690 | req->db = db; |
1134 | req->uint1 = flags; |
1691 | req->uint1 = flags; |
1135 | REQ_SEND; |
1692 | REQ_SEND; |
1136 | } |
1693 | } |
1137 | |
1694 | |
1138 | void |
1695 | void |
|
|
1696 | db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) |
|
|
1697 | PREINIT: |
|
|
1698 | CALLBACK |
|
|
1699 | CODE: |
|
|
1700 | { |
|
|
1701 | dREQ (REQ_DB_SYNC, 1); |
|
|
1702 | req->db = db; |
|
|
1703 | req->buf1 = strdup (file); |
|
|
1704 | req->uint1 = flags; |
|
|
1705 | REQ_SEND; |
|
|
1706 | } |
|
|
1707 | |
|
|
1708 | void |
|
|
1709 | db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = 0) |
|
|
1710 | PREINIT: |
|
|
1711 | CALLBACK |
|
|
1712 | CODE: |
|
|
1713 | { |
|
|
1714 | dREQ (REQ_DB_KEY_RANGE, 2); |
|
|
1715 | req->db = db; |
|
|
1716 | req->txn = txn; |
|
|
1717 | sv_to_dbt (&req->dbt1, key); |
|
|
1718 | req->uint1 = flags; |
|
|
1719 | req->sv1 = SvREFCNT_inc (key_range); SvREADONLY_on (key_range); |
|
|
1720 | REQ_SEND; |
|
|
1721 | } |
|
|
1722 | |
|
|
1723 | void |
1139 | db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1724 | db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = 0) |
|
|
1725 | PREINIT: |
|
|
1726 | CALLBACK |
1140 | CODE: |
1727 | CODE: |
1141 | { |
1728 | { |
1142 | dREQ (REQ_DB_PUT); |
1729 | dREQ (REQ_DB_PUT, 2); |
1143 | req->db = db; |
1730 | req->db = db; |
1144 | req->txn = txn; |
1731 | req->txn = txn; |
1145 | sv_to_dbt (&req->dbt1, key); |
1732 | sv_to_dbt (&req->dbt1, key); |
1146 | sv_to_dbt (&req->dbt2, data); |
1733 | sv_to_dbt (&req->dbt2, data); |
1147 | req->uint1 = flags; |
1734 | req->uint1 = flags; |
1148 | REQ_SEND; |
1735 | REQ_SEND; |
1149 | } |
1736 | } |
1150 | |
1737 | |
|
|
1738 | #if DB_VERSION_MINOR >= 6 |
|
|
1739 | |
1151 | void |
1740 | void |
1152 | db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1741 | db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) |
|
|
1742 | PREINIT: |
|
|
1743 | CALLBACK |
1153 | CODE: |
1744 | CODE: |
1154 | { |
1745 | { |
1155 | dREQ (REQ_DB_GET); |
1746 | dREQ (REQ_DB_EXISTS, 2); |
1156 | req->db = db; |
1747 | req->db = db; |
1157 | req->txn = txn; |
1748 | req->txn = txn; |
|
|
1749 | req->uint1 = flags; |
|
|
1750 | sv_to_dbt (&req->dbt1, key); |
|
|
1751 | REQ_SEND; |
|
|
1752 | } |
|
|
1753 | |
|
|
1754 | #endif |
|
|
1755 | |
|
|
1756 | void |
|
|
1757 | db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = 0) |
|
|
1758 | PREINIT: |
|
|
1759 | CALLBACK |
|
|
1760 | CODE: |
|
|
1761 | if (SvREADONLY (data)) |
|
|
1762 | croak ("can't modify read-only data scalar in db_get"); |
|
|
1763 | { |
|
|
1764 | dREQ (REQ_DB_GET, 2); |
|
|
1765 | req->db = db; |
|
|
1766 | req->txn = txn; |
|
|
1767 | req->uint1 = flags; |
1158 | sv_to_dbt (&req->dbt1, key); |
1768 | sv_to_dbt (&req->dbt1, key); |
1159 | req->dbt3.flags = DB_DBT_MALLOC; |
1769 | req->dbt3.flags = DB_DBT_MALLOC; |
1160 | req->uint1 = flags; |
|
|
1161 | req->sv1 = SvREFCNT_inc (data); |
1770 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1162 | SvREADONLY_on (data); |
|
|
1163 | REQ_SEND; |
1771 | REQ_SEND; |
1164 | } |
1772 | } |
1165 | |
1773 | |
1166 | void |
1774 | void |
1167 | db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1775 | db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = 0) |
|
|
1776 | PREINIT: |
|
|
1777 | CALLBACK |
1168 | CODE: |
1778 | CODE: |
|
|
1779 | if (SvREADONLY (data)) |
|
|
1780 | croak ("can't modify read-only data scalar in db_pget"); |
1169 | { |
1781 | { |
1170 | dREQ (REQ_DB_PGET); |
1782 | dREQ (REQ_DB_PGET, 2); |
1171 | req->db = db; |
1783 | req->db = db; |
1172 | req->txn = txn; |
1784 | req->txn = txn; |
|
|
1785 | req->uint1 = flags; |
1173 | sv_to_dbt (&req->dbt1, key); |
1786 | sv_to_dbt (&req->dbt1, key); |
1174 | sv_to_dbt (&req->dbt2, pkey); |
1787 | sv_to_dbt (&req->dbt2, pkey); |
1175 | req->dbt3.flags = DB_DBT_MALLOC; |
1788 | req->dbt3.flags = DB_DBT_MALLOC; |
1176 | req->uint1 = flags; |
|
|
1177 | req->sv1 = SvREFCNT_inc (data); |
1789 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1178 | SvREADONLY_on (data); |
|
|
1179 | REQ_SEND; |
1790 | REQ_SEND; |
1180 | } |
1791 | } |
1181 | |
1792 | |
1182 | void |
1793 | void |
1183 | db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = &PL_sv_undef) |
1794 | db_del (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) |
|
|
1795 | PREINIT: |
|
|
1796 | CALLBACK |
1184 | CODE: |
1797 | CODE: |
1185 | { |
1798 | { |
1186 | dREQ (REQ_TXN_COMMIT); |
1799 | dREQ (REQ_DB_DEL, 2); |
|
|
1800 | req->db = db; |
1187 | req->txn = txn; |
1801 | req->txn = txn; |
1188 | req->uint1 = flags; |
1802 | req->uint1 = flags; |
|
|
1803 | sv_to_dbt (&req->dbt1, key); |
|
|
1804 | REQ_SEND; |
|
|
1805 | } |
|
|
1806 | |
|
|
1807 | void |
|
|
1808 | db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0) |
|
|
1809 | PREINIT: |
|
|
1810 | CALLBACK |
|
|
1811 | CODE: |
|
|
1812 | { |
|
|
1813 | dREQ (REQ_TXN_COMMIT, 1); |
|
|
1814 | req->txn = txn; |
|
|
1815 | req->uint1 = flags; |
1189 | REQ_SEND; |
1816 | REQ_SEND; |
1190 | ptr_nuke (ST (0)); |
1817 | ptr_nuke (ST (0)); |
1191 | } |
1818 | } |
1192 | |
1819 | |
1193 | void |
1820 | void |
1194 | db_txn_abort (DB_TXN *txn, SV *callback = &PL_sv_undef) |
1821 | db_txn_abort (DB_TXN *txn, SV *callback = 0) |
|
|
1822 | PREINIT: |
|
|
1823 | CALLBACK |
1195 | CODE: |
1824 | CODE: |
1196 | { |
1825 | { |
1197 | dREQ (REQ_TXN_ABORT); |
1826 | dREQ (REQ_TXN_ABORT, 1); |
1198 | req->txn = txn; |
1827 | req->txn = txn; |
1199 | REQ_SEND; |
1828 | REQ_SEND; |
1200 | ptr_nuke (ST (0)); |
1829 | ptr_nuke (ST (0)); |
1201 | } |
1830 | } |
1202 | |
1831 | |
|
|
1832 | void |
|
|
1833 | db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0) |
|
|
1834 | PREINIT: |
|
|
1835 | CALLBACK |
|
|
1836 | CODE: |
|
|
1837 | { |
|
|
1838 | dREQ (REQ_TXN_FINISH, 1); |
|
|
1839 | req->txn = txn; |
|
|
1840 | req->uint1 = flags; |
|
|
1841 | REQ_SEND; |
|
|
1842 | ptr_nuke (ST (0)); |
|
|
1843 | } |
|
|
1844 | |
|
|
1845 | void |
|
|
1846 | db_c_close (DBC *dbc, SV *callback = 0) |
|
|
1847 | PREINIT: |
|
|
1848 | CALLBACK |
|
|
1849 | CODE: |
|
|
1850 | { |
|
|
1851 | dREQ (REQ_C_CLOSE, 1); |
|
|
1852 | req->dbc = dbc; |
|
|
1853 | REQ_SEND; |
|
|
1854 | ptr_nuke (ST (0)); |
|
|
1855 | } |
|
|
1856 | |
|
|
1857 | void |
|
|
1858 | db_c_count (DBC *dbc, SV *count, U32 flags = 0, SV *callback = 0) |
|
|
1859 | PREINIT: |
|
|
1860 | CALLBACK |
|
|
1861 | CODE: |
|
|
1862 | { |
|
|
1863 | dREQ (REQ_C_COUNT, 1); |
|
|
1864 | req->dbc = dbc; |
|
|
1865 | req->sv1 = SvREFCNT_inc (count); |
|
|
1866 | REQ_SEND; |
|
|
1867 | } |
|
|
1868 | |
|
|
1869 | void |
|
|
1870 | db_c_put (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = 0) |
|
|
1871 | PREINIT: |
|
|
1872 | CALLBACK |
|
|
1873 | CODE: |
|
|
1874 | { |
|
|
1875 | dREQ (REQ_C_PUT, 1); |
|
|
1876 | req->dbc = dbc; |
|
|
1877 | sv_to_dbt (&req->dbt1, key); |
|
|
1878 | sv_to_dbt (&req->dbt2, data); |
|
|
1879 | req->uint1 = flags; |
|
|
1880 | REQ_SEND; |
|
|
1881 | } |
|
|
1882 | |
|
|
1883 | void |
|
|
1884 | db_c_get (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = 0) |
|
|
1885 | PREINIT: |
|
|
1886 | CALLBACK |
|
|
1887 | CODE: |
|
|
1888 | { |
|
|
1889 | dREQ (REQ_C_GET, 1); |
|
|
1890 | req->dbc = dbc; |
|
|
1891 | req->uint1 = flags; |
|
|
1892 | if ((flags & DB_SET) == DB_SET |
|
|
1893 | || (flags & DB_SET_RANGE) == DB_SET_RANGE) |
|
|
1894 | sv_to_dbt (&req->dbt1, key); |
|
|
1895 | else |
|
|
1896 | req->dbt1.flags = DB_DBT_MALLOC; |
|
|
1897 | |
|
|
1898 | req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); |
|
|
1899 | |
|
|
1900 | if ((flags & DB_GET_BOTH) == DB_GET_BOTH |
|
|
1901 | || (flags & DB_GET_BOTH_RANGE) == DB_GET_BOTH_RANGE) |
|
|
1902 | sv_to_dbt (&req->dbt3, data); |
|
|
1903 | else |
|
|
1904 | req->dbt3.flags = DB_DBT_MALLOC; |
|
|
1905 | |
|
|
1906 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
|
|
1907 | REQ_SEND; |
|
|
1908 | } |
|
|
1909 | |
|
|
1910 | void |
|
|
1911 | db_c_pget (DBC *dbc, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = 0) |
|
|
1912 | PREINIT: |
|
|
1913 | CALLBACK |
|
|
1914 | CODE: |
|
|
1915 | { |
|
|
1916 | dREQ (REQ_C_PGET, 1); |
|
|
1917 | req->dbc = dbc; |
|
|
1918 | req->uint1 = flags; |
|
|
1919 | if ((flags & DB_SET) == DB_SET |
|
|
1920 | || (flags & DB_SET_RANGE) == DB_SET_RANGE) |
|
|
1921 | sv_to_dbt (&req->dbt1, key); |
|
|
1922 | else |
|
|
1923 | req->dbt1.flags = DB_DBT_MALLOC; |
|
|
1924 | |
|
|
1925 | req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); |
|
|
1926 | |
|
|
1927 | req->dbt2.flags = DB_DBT_MALLOC; |
|
|
1928 | req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey); |
|
|
1929 | |
|
|
1930 | if ((flags & DB_GET_BOTH) == DB_GET_BOTH |
|
|
1931 | || (flags & DB_GET_BOTH_RANGE) == DB_GET_BOTH_RANGE) |
|
|
1932 | sv_to_dbt (&req->dbt3, data); |
|
|
1933 | else |
|
|
1934 | req->dbt3.flags = DB_DBT_MALLOC; |
|
|
1935 | |
|
|
1936 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
|
|
1937 | REQ_SEND; |
|
|
1938 | } |
|
|
1939 | |
|
|
1940 | void |
|
|
1941 | db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0) |
|
|
1942 | PREINIT: |
|
|
1943 | CALLBACK |
|
|
1944 | CODE: |
|
|
1945 | { |
|
|
1946 | dREQ (REQ_C_DEL, 1); |
|
|
1947 | req->dbc = dbc; |
|
|
1948 | req->uint1 = flags; |
|
|
1949 | REQ_SEND; |
|
|
1950 | } |
|
|
1951 | |
|
|
1952 | |
|
|
1953 | #if DB_VERSION_MINOR >= 3 |
|
|
1954 | |
|
|
1955 | void |
|
|
1956 | db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0) |
|
|
1957 | PREINIT: |
|
|
1958 | CALLBACK |
|
|
1959 | CODE: |
|
|
1960 | { |
|
|
1961 | dREQ (REQ_SEQ_OPEN, 2); |
|
|
1962 | req->seq = seq; |
|
|
1963 | req->txn = txnid; |
|
|
1964 | req->uint1 = flags | DB_THREAD; |
|
|
1965 | sv_to_dbt (&req->dbt1, key); |
|
|
1966 | REQ_SEND; |
|
|
1967 | } |
|
|
1968 | |
|
|
1969 | void |
|
|
1970 | db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0) |
|
|
1971 | PREINIT: |
|
|
1972 | CALLBACK |
|
|
1973 | CODE: |
|
|
1974 | { |
|
|
1975 | dREQ (REQ_SEQ_CLOSE, 1); |
|
|
1976 | req->seq = seq; |
|
|
1977 | req->uint1 = flags; |
|
|
1978 | REQ_SEND; |
|
|
1979 | ptr_nuke (ST (0)); |
|
|
1980 | } |
|
|
1981 | |
|
|
1982 | void |
|
|
1983 | db_sequence_get (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, int delta, SV *seq_value, U32 flags = DB_TXN_NOSYNC, SV *callback = 0) |
|
|
1984 | PREINIT: |
|
|
1985 | CALLBACK |
|
|
1986 | CODE: |
|
|
1987 | { |
|
|
1988 | dREQ (REQ_SEQ_GET, 2); |
|
|
1989 | req->seq = seq; |
|
|
1990 | req->txn = txnid; |
|
|
1991 | req->int1 = delta; |
|
|
1992 | req->uint1 = flags; |
|
|
1993 | req->sv1 = SvREFCNT_inc (seq_value); SvREADONLY_on (seq_value); |
|
|
1994 | REQ_SEND; |
|
|
1995 | } |
|
|
1996 | |
|
|
1997 | void |
|
|
1998 | db_sequence_remove (DB_SEQUENCE *seq, DB_TXN_ornull *txnid = 0, U32 flags = 0, SV *callback = 0) |
|
|
1999 | PREINIT: |
|
|
2000 | CALLBACK |
|
|
2001 | CODE: |
|
|
2002 | { |
|
|
2003 | dREQ (REQ_SEQ_REMOVE, 2); |
|
|
2004 | req->seq = seq; |
|
|
2005 | req->txn = txnid; |
|
|
2006 | req->uint1 = flags; |
|
|
2007 | REQ_SEND; |
|
|
2008 | } |
|
|
2009 | |
|
|
2010 | #endif |
|
|
2011 | |
1203 | |
2012 | |
1204 | MODULE = BDB PACKAGE = BDB::Env |
2013 | MODULE = BDB PACKAGE = BDB::Env |
1205 | |
2014 | |
1206 | void |
2015 | void |
1207 | DESTROY (DB_ENV_ornull *env) |
2016 | DESTROY (DB_ENV_ornuked *env) |
1208 | CODE: |
2017 | CODE: |
1209 | if (env) |
2018 | if (env) |
1210 | env->close (env, 0); |
2019 | env->close (env, 0); |
1211 | |
2020 | |
|
|
2021 | int set_data_dir (DB_ENV *env, const char *dir) |
|
|
2022 | CODE: |
|
|
2023 | RETVAL = env->set_data_dir (env, dir); |
|
|
2024 | OUTPUT: |
|
|
2025 | RETVAL |
|
|
2026 | |
|
|
2027 | int set_tmp_dir (DB_ENV *env, const char *dir) |
|
|
2028 | CODE: |
|
|
2029 | RETVAL = env->set_tmp_dir (env, dir); |
|
|
2030 | OUTPUT: |
|
|
2031 | RETVAL |
|
|
2032 | |
|
|
2033 | int set_lg_dir (DB_ENV *env, const char *dir) |
|
|
2034 | CODE: |
|
|
2035 | RETVAL = env->set_lg_dir (env, dir); |
|
|
2036 | OUTPUT: |
|
|
2037 | RETVAL |
|
|
2038 | |
|
|
2039 | int set_shm_key (DB_ENV *env, long shm_key) |
|
|
2040 | CODE: |
|
|
2041 | RETVAL = env->set_shm_key (env, shm_key); |
|
|
2042 | OUTPUT: |
|
|
2043 | RETVAL |
|
|
2044 | |
1212 | int set_cachesize (DB_ENV *env, U32 gbytes, U32 bytes, int ncache = 0) |
2045 | int set_cachesize (DB_ENV *env, U32 gbytes, U32 bytes, int ncache = 0) |
1213 | CODE: |
2046 | CODE: |
1214 | RETVAL = env->set_cachesize (env, gbytes, bytes, ncache); |
2047 | RETVAL = env->set_cachesize (env, gbytes, bytes, ncache); |
1215 | OUTPUT: |
2048 | OUTPUT: |
1216 | RETVAL |
2049 | RETVAL |
1217 | |
2050 | |
1218 | int set_flags (DB_ENV *env, U32 flags, int onoff) |
2051 | int set_flags (DB_ENV *env, U32 flags, int onoff = 1) |
1219 | CODE: |
2052 | CODE: |
1220 | RETVAL = env->set_flags (env, flags, onoff); |
2053 | RETVAL = env->set_flags (env, flags, onoff); |
1221 | OUTPUT: |
2054 | OUTPUT: |
1222 | RETVAL |
2055 | RETVAL |
1223 | |
2056 | |
|
|
2057 | #if DB_VERSION_MINOR >= 7 |
|
|
2058 | |
|
|
2059 | int set_intermediate_dir_mode (DB_ENV *env, const char *mode) |
|
|
2060 | CODE: |
|
|
2061 | RETVAL = env->set_intermediate_dir_mode (env, mode); |
|
|
2062 | OUTPUT: |
|
|
2063 | RETVAL |
|
|
2064 | |
|
|
2065 | int log_set_config (DB_ENV *env, U32 flags, int onoff = 1) |
|
|
2066 | CODE: |
|
|
2067 | RETVAL = env->log_set_config (env, flags, onoff); |
|
|
2068 | OUTPUT: |
|
|
2069 | RETVAL |
|
|
2070 | |
|
|
2071 | #endif |
|
|
2072 | |
|
|
2073 | |
|
|
2074 | void set_errfile (DB_ENV *env, FILE *errfile = 0) |
|
|
2075 | CODE: |
|
|
2076 | env->set_errfile (env, errfile); |
|
|
2077 | |
|
|
2078 | void set_msgfile (DB_ENV *env, FILE *msgfile = 0) |
|
|
2079 | CODE: |
|
|
2080 | env->set_msgfile (env, msgfile); |
|
|
2081 | |
|
|
2082 | int set_verbose (DB_ENV *env, U32 which = -1, int onoff = 1) |
|
|
2083 | CODE: |
|
|
2084 | RETVAL = env->set_verbose (env, which, onoff); |
|
|
2085 | OUTPUT: |
|
|
2086 | RETVAL |
|
|
2087 | |
1224 | int set_encrypt (DB_ENV *env, const char *password, U32 flags = 0) |
2088 | int set_encrypt (DB_ENV *env, const char *password, U32 flags = 0) |
1225 | CODE: |
2089 | CODE: |
1226 | RETVAL = env->set_encrypt (env, password, flags); |
2090 | RETVAL = env->set_encrypt (env, password, flags); |
1227 | OUTPUT: |
2091 | OUTPUT: |
1228 | RETVAL |
2092 | RETVAL |
1229 | |
2093 | |
1230 | int set_timeout (DB_ENV *env, NV timeout, U32 flags) |
2094 | int set_timeout (DB_ENV *env, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT) |
1231 | CODE: |
2095 | CODE: |
1232 | RETVAL = env->set_timeout (env, timeout * 1000000, flags); |
2096 | RETVAL = env->set_timeout (env, timeout * 1000000, flags); |
1233 | OUTPUT: |
2097 | OUTPUT: |
1234 | RETVAL |
2098 | RETVAL |
|
|
2099 | |
|
|
2100 | int set_mp_max_openfd (DB_ENV *env, int maxopenfd); |
|
|
2101 | CODE: |
|
|
2102 | RETVAL = env->set_mp_max_openfd (env, maxopenfd); |
|
|
2103 | OUTPUT: |
|
|
2104 | RETVAL |
|
|
2105 | |
|
|
2106 | int set_mp_max_write (DB_ENV *env, int maxwrite, int maxwrite_sleep); |
|
|
2107 | CODE: |
|
|
2108 | RETVAL = env->set_mp_max_write (env, maxwrite, maxwrite_sleep); |
|
|
2109 | OUTPUT: |
|
|
2110 | RETVAL |
|
|
2111 | |
|
|
2112 | int set_mp_mmapsize (DB_ENV *env, int mmapsize_mb) |
|
|
2113 | CODE: |
|
|
2114 | RETVAL = env->set_mp_mmapsize (env, ((size_t)mmapsize_mb) << 20); |
|
|
2115 | OUTPUT: |
|
|
2116 | RETVAL |
|
|
2117 | |
|
|
2118 | int set_lk_detect (DB_ENV *env, U32 detect = DB_LOCK_DEFAULT) |
|
|
2119 | CODE: |
|
|
2120 | RETVAL = env->set_lk_detect (env, detect); |
|
|
2121 | OUTPUT: |
|
|
2122 | RETVAL |
|
|
2123 | |
|
|
2124 | int set_lk_max_lockers (DB_ENV *env, U32 max) |
|
|
2125 | CODE: |
|
|
2126 | RETVAL = env->set_lk_max_lockers (env, max); |
|
|
2127 | OUTPUT: |
|
|
2128 | RETVAL |
|
|
2129 | |
|
|
2130 | int set_lk_max_locks (DB_ENV *env, U32 max) |
|
|
2131 | CODE: |
|
|
2132 | RETVAL = env->set_lk_max_locks (env, max); |
|
|
2133 | OUTPUT: |
|
|
2134 | RETVAL |
|
|
2135 | |
|
|
2136 | int set_lk_max_objects (DB_ENV *env, U32 max) |
|
|
2137 | CODE: |
|
|
2138 | RETVAL = env->set_lk_max_objects (env, max); |
|
|
2139 | OUTPUT: |
|
|
2140 | RETVAL |
|
|
2141 | |
|
|
2142 | int set_lg_bsize (DB_ENV *env, U32 max) |
|
|
2143 | CODE: |
|
|
2144 | RETVAL = env->set_lg_bsize (env, max); |
|
|
2145 | OUTPUT: |
|
|
2146 | RETVAL |
|
|
2147 | |
|
|
2148 | int set_lg_max (DB_ENV *env, U32 max) |
|
|
2149 | CODE: |
|
|
2150 | RETVAL = env->set_lg_max (env, max); |
|
|
2151 | OUTPUT: |
|
|
2152 | RETVAL |
|
|
2153 | |
|
|
2154 | #if DB_VERSION_MINOR >= 4 |
|
|
2155 | |
|
|
2156 | int mutex_set_max (DB_ENV *env, U32 max) |
|
|
2157 | CODE: |
|
|
2158 | RETVAL = env->mutex_set_max (env, max); |
|
|
2159 | OUTPUT: |
|
|
2160 | RETVAL |
|
|
2161 | |
|
|
2162 | int mutex_set_increment (DB_ENV *env, U32 increment) |
|
|
2163 | CODE: |
|
|
2164 | RETVAL = env->mutex_set_increment (env, increment); |
|
|
2165 | OUTPUT: |
|
|
2166 | RETVAL |
|
|
2167 | |
|
|
2168 | int mutex_set_tas_spins (DB_ENV *env, U32 tas_spins) |
|
|
2169 | CODE: |
|
|
2170 | RETVAL = env->mutex_set_tas_spins (env, tas_spins); |
|
|
2171 | OUTPUT: |
|
|
2172 | RETVAL |
|
|
2173 | |
|
|
2174 | int mutex_set_align (DB_ENV *env, U32 align) |
|
|
2175 | CODE: |
|
|
2176 | RETVAL = env->mutex_set_align (env, align); |
|
|
2177 | OUTPUT: |
|
|
2178 | RETVAL |
|
|
2179 | |
|
|
2180 | #endif |
1235 | |
2181 | |
1236 | DB_TXN * |
2182 | DB_TXN * |
1237 | txn_begin (DB_ENV *env, DB_TXN_ornull *parent = 0, U32 flags = 0) |
2183 | txn_begin (DB_ENV *env, DB_TXN_ornull *parent = 0, U32 flags = 0) |
1238 | CODE: |
2184 | CODE: |
1239 | errno = env->txn_begin (env, parent, &RETVAL, flags); |
2185 | errno = env->txn_begin (env, parent, &RETVAL, flags); |
1240 | if (errno) |
2186 | if (errno) |
1241 | croak ("txn_begin: %s", db_strerror (errno)); |
2187 | croak ("DB_ENV->txn_begin: %s", db_strerror (errno)); |
1242 | OUTPUT: |
2188 | OUTPUT: |
1243 | RETVAL |
2189 | RETVAL |
1244 | |
2190 | |
|
|
2191 | #if DB_VERSION_MINOR >= 5 |
|
|
2192 | |
|
|
2193 | DB_TXN * |
|
|
2194 | cdsgroup_begin (DB_ENV *env) |
|
|
2195 | CODE: |
|
|
2196 | errno = env->cdsgroup_begin (env, &RETVAL); |
|
|
2197 | if (errno) |
|
|
2198 | croak ("DB_ENV->cdsgroup_begin: %s", db_strerror (errno)); |
|
|
2199 | OUTPUT: |
|
|
2200 | RETVAL |
|
|
2201 | |
|
|
2202 | #endif |
|
|
2203 | |
1245 | MODULE = BDB PACKAGE = BDB::Db |
2204 | MODULE = BDB PACKAGE = BDB::Db |
1246 | |
2205 | |
1247 | void |
2206 | void |
1248 | DESTROY (DB_ornull *db) |
2207 | DESTROY (DB_ornuked *db) |
1249 | CODE: |
2208 | CODE: |
1250 | if (db) |
2209 | if (db) |
1251 | { |
2210 | { |
1252 | SV *env = (SV *)db->app_private; |
2211 | SV *env = (SV *)db->app_private; |
1253 | db->close (db, 0); |
2212 | db->close (db, 0); |
… | |
… | |
1258 | CODE: |
2217 | CODE: |
1259 | RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); |
2218 | RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); |
1260 | OUTPUT: |
2219 | OUTPUT: |
1261 | RETVAL |
2220 | RETVAL |
1262 | |
2221 | |
1263 | int set_flags (DB *db, U32 flags); |
2222 | int set_flags (DB *db, U32 flags) |
1264 | CODE: |
2223 | CODE: |
1265 | RETVAL = db->set_flags (db, flags); |
2224 | RETVAL = db->set_flags (db, flags); |
1266 | OUTPUT: |
2225 | OUTPUT: |
1267 | RETVAL |
2226 | RETVAL |
1268 | |
2227 | |
… | |
… | |
1276 | CODE: |
2235 | CODE: |
1277 | RETVAL = db->set_lorder (db, lorder); |
2236 | RETVAL = db->set_lorder (db, lorder); |
1278 | OUTPUT: |
2237 | OUTPUT: |
1279 | RETVAL |
2238 | RETVAL |
1280 | |
2239 | |
1281 | |
|
|
1282 | int set_bt_minkey (DB *db, U32 minkey) |
2240 | int set_bt_minkey (DB *db, U32 minkey) |
1283 | CODE: |
2241 | CODE: |
1284 | RETVAL = db->set_bt_minkey (db, minkey); |
2242 | RETVAL = db->set_bt_minkey (db, minkey); |
1285 | OUTPUT: |
2243 | OUTPUT: |
1286 | RETVAL |
2244 | RETVAL |
1287 | |
2245 | |
1288 | int set_re_delim(DB *db, int delim); |
2246 | int set_re_delim (DB *db, int delim) |
1289 | CODE: |
2247 | CODE: |
1290 | RETVAL = db->set_re_delim (db, delim); |
2248 | RETVAL = db->set_re_delim (db, delim); |
1291 | OUTPUT: |
2249 | OUTPUT: |
1292 | RETVAL |
2250 | RETVAL |
1293 | |
2251 | |
… | |
… | |
1325 | CODE: |
2283 | CODE: |
1326 | RETVAL = db->set_q_extentsize (db, extentsize); |
2284 | RETVAL = db->set_q_extentsize (db, extentsize); |
1327 | OUTPUT: |
2285 | OUTPUT: |
1328 | RETVAL |
2286 | RETVAL |
1329 | |
2287 | |
|
|
2288 | DBC * |
|
|
2289 | cursor (DB *db, DB_TXN_ornull *txn = 0, U32 flags = 0) |
|
|
2290 | CODE: |
|
|
2291 | errno = db->cursor (db, txn, &RETVAL, flags); |
|
|
2292 | if (errno) |
|
|
2293 | croak ("DB->cursor: %s", db_strerror (errno)); |
|
|
2294 | OUTPUT: |
|
|
2295 | RETVAL |
|
|
2296 | |
|
|
2297 | #if DB_VERSION_MINOR >= 3 |
|
|
2298 | |
|
|
2299 | DB_SEQUENCE * |
|
|
2300 | sequence (DB *db, U32 flags = 0) |
|
|
2301 | CODE: |
|
|
2302 | { |
|
|
2303 | errno = db_sequence_create (&RETVAL, db, flags); |
|
|
2304 | if (errno) |
|
|
2305 | croak ("db_sequence_create: %s", db_strerror (errno)); |
|
|
2306 | } |
|
|
2307 | OUTPUT: |
|
|
2308 | RETVAL |
|
|
2309 | |
|
|
2310 | #endif |
|
|
2311 | |
|
|
2312 | |
1330 | MODULE = BDB PACKAGE = BDB::Txn |
2313 | MODULE = BDB PACKAGE = BDB::Txn |
1331 | |
2314 | |
1332 | void |
2315 | void |
1333 | DESTROY (DB_TXN_ornull *txn) |
2316 | DESTROY (DB_TXN_ornuked *txn) |
1334 | CODE: |
2317 | CODE: |
1335 | if (txn) |
2318 | if (txn) |
1336 | txn->abort (txn); |
2319 | txn->abort (txn); |
1337 | |
2320 | |
1338 | int set_timeout (DB_TXN *txn, NV timeout, U32 flags) |
2321 | int set_timeout (DB_TXN *txn, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT) |
1339 | CODE: |
2322 | CODE: |
1340 | RETVAL = txn->set_timeout (txn, timeout * 1000000, flags); |
2323 | RETVAL = txn->set_timeout (txn, timeout * 1000000, flags); |
1341 | OUTPUT: |
2324 | OUTPUT: |
1342 | RETVAL |
2325 | RETVAL |
1343 | |
2326 | |
|
|
2327 | int failed (DB_TXN *txn) |
|
|
2328 | CODE: |
|
|
2329 | RETVAL = !!(txn->flags & TXN_DEADLOCK); |
|
|
2330 | OUTPUT: |
|
|
2331 | RETVAL |
1344 | |
2332 | |
|
|
2333 | |
|
|
2334 | MODULE = BDB PACKAGE = BDB::Cursor |
|
|
2335 | |
|
|
2336 | void |
|
|
2337 | DESTROY (DBC_ornuked *dbc) |
|
|
2338 | CODE: |
|
|
2339 | if (dbc) |
|
|
2340 | dbc->c_close (dbc); |
|
|
2341 | |
|
|
2342 | #if DB_VERSION_MINOR >= 6 |
|
|
2343 | |
|
|
2344 | int set_priority (DBC *dbc, int priority) |
|
|
2345 | CODE: |
|
|
2346 | dbc->set_priority (dbc, priority); |
|
|
2347 | |
|
|
2348 | #endif |
|
|
2349 | |
|
|
2350 | #if DB_VERSION_MINOR >= 3 |
|
|
2351 | |
|
|
2352 | MODULE = BDB PACKAGE = BDB::Sequence |
|
|
2353 | |
|
|
2354 | void |
|
|
2355 | DESTROY (DB_SEQUENCE_ornuked *seq) |
|
|
2356 | CODE: |
|
|
2357 | if (seq) |
|
|
2358 | seq->close (seq, 0); |
|
|
2359 | |
|
|
2360 | int initial_value (DB_SEQUENCE *seq, db_seq_t value) |
|
|
2361 | CODE: |
|
|
2362 | RETVAL = seq->initial_value (seq, value); |
|
|
2363 | OUTPUT: |
|
|
2364 | RETVAL |
|
|
2365 | |
|
|
2366 | int set_cachesize (DB_SEQUENCE *seq, U32 size) |
|
|
2367 | CODE: |
|
|
2368 | RETVAL = seq->set_cachesize (seq, size); |
|
|
2369 | OUTPUT: |
|
|
2370 | RETVAL |
|
|
2371 | |
|
|
2372 | int set_flags (DB_SEQUENCE *seq, U32 flags) |
|
|
2373 | CODE: |
|
|
2374 | RETVAL = seq->set_flags (seq, flags); |
|
|
2375 | OUTPUT: |
|
|
2376 | RETVAL |
|
|
2377 | |
|
|
2378 | int set_range (DB_SEQUENCE *seq, db_seq_t min, db_seq_t max) |
|
|
2379 | CODE: |
|
|
2380 | RETVAL = seq->set_range (seq, min, max); |
|
|
2381 | OUTPUT: |
|
|
2382 | RETVAL |
|
|
2383 | |
|
|
2384 | #endif |
|
|
2385 | |
|
|
2386 | |