|
|
1 | #define X_STACKSIZE 1024 * 128 + sizeof (long) * 64 * 1024 / 4 |
|
|
2 | |
1 | #include "xthread.h" |
3 | #include "xthread.h" |
2 | |
4 | |
3 | #include <errno.h> |
5 | #include <errno.h> |
4 | |
6 | |
5 | #include "EXTERN.h" |
7 | #include "EXTERN.h" |
… | |
… | |
27 | # include <unistd.h> |
29 | # include <unistd.h> |
28 | #endif |
30 | #endif |
29 | |
31 | |
30 | #include <db.h> |
32 | #include <db.h> |
31 | |
33 | |
32 | #if DB_VERSION_MAJOR < 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 4) |
34 | #if DB_VERSION_MAJOR != 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 3) |
33 | # error you need Berkeley DB 4.4 or newer installed |
35 | # error you need Berkeley DB 4.3 or a newer 4.x version installed |
34 | #endif |
36 | #endif |
35 | |
37 | |
36 | /* number of seconds after which idle threads exit */ |
38 | /* number of seconds after which idle threads exit */ |
37 | #define IDLE_TIMEOUT 10 |
39 | #define IDLE_TIMEOUT 10 |
38 | |
40 | |
39 | typedef DB_ENV DB_ENV_ornull; |
41 | typedef DB_ENV DB_ENV_ornull; |
40 | typedef DB_TXN DB_TXN_ornull; |
42 | typedef DB_TXN DB_TXN_ornull; |
41 | typedef DBC DBC_ornull; |
43 | typedef DBC DBC_ornull; |
42 | typedef DB DB_ornull; |
44 | typedef DB DB_ornull; |
|
|
45 | |
|
|
46 | typedef DB_ENV DB_ENV_ornuked; |
|
|
47 | typedef DB_TXN DB_TXN_ornuked; |
|
|
48 | typedef DBC DBC_ornuked; |
|
|
49 | typedef DB DB_ornuked; |
|
|
50 | |
|
|
51 | #if DB_VERSION_MINOR >= 3 |
43 | typedef DB_SEQUENCE DB_SEQUENCE_ornull; |
52 | typedef DB_SEQUENCE DB_SEQUENCE_ornull; |
|
|
53 | typedef DB_SEQUENCE DB_SEQUENCE_ornuked; |
|
|
54 | #endif |
44 | |
55 | |
45 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
56 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
46 | typedef char *octetstring; |
57 | typedef char *bdb_filename; |
47 | |
58 | |
48 | static SV *prepare_cb; |
59 | static SV *prepare_cb; |
49 | |
60 | |
50 | #if DB_VERSION_MINOR >= 6 |
61 | #if DB_VERSION_MINOR >= 6 |
51 | # define c_close close |
62 | # define c_close close |
… | |
… | |
55 | # define c_get get |
66 | # define c_get get |
56 | # define c_pget pget |
67 | # define c_pget pget |
57 | # define c_put put |
68 | # define c_put put |
58 | #endif |
69 | #endif |
59 | |
70 | |
|
|
71 | static char * |
|
|
72 | get_bdb_filename (SV *sv) |
|
|
73 | { |
|
|
74 | if (!SvOK (sv)) |
|
|
75 | return 0; |
|
|
76 | |
|
|
77 | #if _WIN32 |
|
|
78 | /* win32 madness + win32 perl absolutely brokenness make for horrible hacks */ |
|
|
79 | { |
|
|
80 | STRLEN len; |
|
|
81 | char *src = SvPVbyte (sv, len); |
|
|
82 | SV *t1 = sv_newmortal (); |
|
|
83 | SV *t2 = sv_newmortal (); |
|
|
84 | |
|
|
85 | sv_upgrade (t1, SVt_PV); SvPOK_only (t1); SvGROW (t1, len * 16 + 1); |
|
|
86 | sv_upgrade (t2, SVt_PV); SvPOK_only (t2); SvGROW (t2, len * 16 + 1); |
|
|
87 | |
|
|
88 | len = MultiByteToWideChar (CP_ACP, 0, src, len, (WCHAR *)SvPVX (t1), SvLEN (t1) / sizeof (WCHAR)); |
|
|
89 | len = WideCharToMultiByte (CP_UTF8, 0, (WCHAR *)SvPVX (t1), len, SvPVX (t2), SvLEN (t2), 0, 0); |
|
|
90 | SvPOK_only (t2); |
|
|
91 | SvPVX (t2)[len] = 0; |
|
|
92 | SvCUR_set (t2, len); |
|
|
93 | |
|
|
94 | return SvPVX (t2); |
|
|
95 | } |
|
|
96 | #else |
|
|
97 | return SvPVbyte_nolen (sv); |
|
|
98 | #endif |
|
|
99 | } |
|
|
100 | |
60 | static void |
101 | static void |
61 | debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg) |
102 | debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg) |
62 | { |
103 | { |
63 | printf ("err[%s]\n", msg); |
104 | printf ("err[%s]\n", msg); |
64 | } |
105 | } |
… | |
… | |
101 | } |
142 | } |
102 | |
143 | |
103 | enum { |
144 | enum { |
104 | REQ_QUIT, |
145 | REQ_QUIT, |
105 | REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, |
146 | REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, |
106 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, |
147 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME, |
107 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE, |
148 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE, |
108 | REQ_DB_PUT, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, |
149 | REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, |
109 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
150 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
110 | REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, |
151 | REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, |
111 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
152 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
112 | }; |
153 | }; |
113 | |
154 | |
114 | typedef struct aio_cb |
155 | typedef struct bdb_cb |
115 | { |
156 | { |
116 | struct aio_cb *volatile next; |
157 | struct bdb_cb *volatile next; |
117 | SV *callback; |
158 | SV *callback; |
118 | int type, pri, result; |
159 | int type, pri, result; |
119 | |
160 | |
120 | DB_ENV *env; |
161 | DB_ENV *env; |
121 | DB *db; |
162 | DB *db; |
… | |
… | |
123 | DBC *dbc; |
164 | DBC *dbc; |
124 | |
165 | |
125 | UV uv1; |
166 | UV uv1; |
126 | int int1, int2; |
167 | int int1, int2; |
127 | U32 uint1, uint2; |
168 | U32 uint1, uint2; |
128 | char *buf1, *buf2; |
169 | char *buf1, *buf2, *buf3; |
129 | SV *sv1, *sv2, *sv3; |
170 | SV *sv1, *sv2, *sv3; |
130 | |
171 | |
131 | DBT dbt1, dbt2, dbt3; |
172 | DBT dbt1, dbt2, dbt3; |
132 | DB_KEY_RANGE key_range; |
173 | DB_KEY_RANGE key_range; |
|
|
174 | #if DB_VERSION_MINOR >= 3 |
133 | DB_SEQUENCE *seq; |
175 | DB_SEQUENCE *seq; |
134 | db_seq_t seq_t; |
176 | db_seq_t seq_t; |
135 | } aio_cb; |
177 | #endif |
|
|
178 | } bdb_cb; |
136 | |
179 | |
137 | typedef aio_cb *aio_req; |
180 | typedef bdb_cb *bdb_req; |
138 | |
181 | |
139 | enum { |
182 | enum { |
140 | PRI_MIN = -4, |
183 | PRI_MIN = -4, |
141 | PRI_MAX = 4, |
184 | PRI_MAX = 4, |
142 | |
185 | |
… | |
… | |
145 | NUM_PRI = PRI_MAX + PRI_BIAS + 1, |
188 | NUM_PRI = PRI_MAX + PRI_BIAS + 1, |
146 | }; |
189 | }; |
147 | |
190 | |
148 | #define AIO_TICKS ((1000000 + 1023) >> 10) |
191 | #define AIO_TICKS ((1000000 + 1023) >> 10) |
149 | |
192 | |
|
|
193 | static SV *on_next_submit; |
|
|
194 | |
150 | static unsigned int max_poll_time = 0; |
195 | static unsigned int max_poll_time = 0; |
151 | static unsigned int max_poll_reqs = 0; |
196 | static unsigned int max_poll_reqs = 0; |
152 | |
197 | |
153 | /* calculcate time difference in ~1/AIO_TICKS of a second */ |
198 | /* calculcate time difference in ~1/AIO_TICKS of a second */ |
154 | static int tvdiff (struct timeval *tv1, struct timeval *tv2) |
199 | static int tvdiff (struct timeval *tv1, struct timeval *tv2) |
… | |
… | |
169 | struct worker *prev, *next; |
214 | struct worker *prev, *next; |
170 | |
215 | |
171 | thread_t tid; |
216 | thread_t tid; |
172 | |
217 | |
173 | /* locked by reslock, reqlock or wrklock */ |
218 | /* locked by reslock, reqlock or wrklock */ |
174 | aio_req req; /* currently processed request */ |
219 | bdb_req req; /* currently processed request */ |
175 | void *dbuf; |
220 | void *dbuf; |
176 | DIR *dirp; |
221 | DIR *dirp; |
177 | } worker; |
222 | } worker; |
178 | |
223 | |
179 | static worker wrk_first = { &wrk_first, &wrk_first, 0 }; |
224 | static worker wrk_first = { &wrk_first, &wrk_first, 0 }; |
… | |
… | |
199 | static mutex_t reqlock = X_MUTEX_INIT; |
244 | static mutex_t reqlock = X_MUTEX_INIT; |
200 | static cond_t reqwait = X_COND_INIT; |
245 | static cond_t reqwait = X_COND_INIT; |
201 | |
246 | |
202 | #if WORDACCESS_UNSAFE |
247 | #if WORDACCESS_UNSAFE |
203 | |
248 | |
204 | static unsigned int get_nready () |
249 | static unsigned int get_nready (void) |
205 | { |
250 | { |
206 | unsigned int retval; |
251 | unsigned int retval; |
207 | |
252 | |
208 | X_LOCK (reqlock); |
253 | X_LOCK (reqlock); |
209 | retval = nready; |
254 | retval = nready; |
210 | X_UNLOCK (reqlock); |
255 | X_UNLOCK (reqlock); |
211 | |
256 | |
212 | return retval; |
257 | return retval; |
213 | } |
258 | } |
214 | |
259 | |
215 | static unsigned int get_npending () |
260 | static unsigned int get_npending (void) |
216 | { |
261 | { |
217 | unsigned int retval; |
262 | unsigned int retval; |
218 | |
263 | |
219 | X_LOCK (reslock); |
264 | X_LOCK (reslock); |
220 | retval = npending; |
265 | retval = npending; |
221 | X_UNLOCK (reslock); |
266 | X_UNLOCK (reslock); |
222 | |
267 | |
223 | return retval; |
268 | return retval; |
224 | } |
269 | } |
225 | |
270 | |
226 | static unsigned int get_nthreads () |
271 | static unsigned int get_nthreads (void) |
227 | { |
272 | { |
228 | unsigned int retval; |
273 | unsigned int retval; |
229 | |
274 | |
230 | X_LOCK (wrklock); |
275 | X_LOCK (wrklock); |
231 | retval = started; |
276 | retval = started; |
… | |
… | |
246 | * a somewhat faster data structure might be nice, but |
291 | * a somewhat faster data structure might be nice, but |
247 | * with 8 priorities this actually needs <20 insns |
292 | * with 8 priorities this actually needs <20 insns |
248 | * per shift, the most expensive operation. |
293 | * per shift, the most expensive operation. |
249 | */ |
294 | */ |
250 | typedef struct { |
295 | typedef struct { |
251 | aio_req qs[NUM_PRI], qe[NUM_PRI]; /* qstart, qend */ |
296 | bdb_req qs[NUM_PRI], qe[NUM_PRI]; /* qstart, qend */ |
252 | int size; |
297 | int size; |
253 | } reqq; |
298 | } reqq; |
254 | |
299 | |
255 | static reqq req_queue; |
300 | static reqq req_queue; |
256 | static reqq res_queue; |
301 | static reqq res_queue; |
257 | |
302 | |
258 | int reqq_push (reqq *q, aio_req req) |
303 | int reqq_push (reqq *q, bdb_req req) |
259 | { |
304 | { |
260 | int pri = req->pri; |
305 | int pri = req->pri; |
261 | req->next = 0; |
306 | req->next = 0; |
262 | |
307 | |
263 | if (q->qe[pri]) |
308 | if (q->qe[pri]) |
… | |
… | |
269 | q->qe[pri] = q->qs[pri] = req; |
314 | q->qe[pri] = q->qs[pri] = req; |
270 | |
315 | |
271 | return q->size++; |
316 | return q->size++; |
272 | } |
317 | } |
273 | |
318 | |
274 | aio_req reqq_shift (reqq *q) |
319 | bdb_req reqq_shift (reqq *q) |
275 | { |
320 | { |
276 | int pri; |
321 | int pri; |
277 | |
322 | |
278 | if (!q->size) |
323 | if (!q->size) |
279 | return 0; |
324 | return 0; |
280 | |
325 | |
281 | --q->size; |
326 | --q->size; |
282 | |
327 | |
283 | for (pri = NUM_PRI; pri--; ) |
328 | for (pri = NUM_PRI; pri--; ) |
284 | { |
329 | { |
285 | aio_req req = q->qs[pri]; |
330 | bdb_req req = q->qs[pri]; |
286 | |
331 | |
287 | if (req) |
332 | if (req) |
288 | { |
333 | { |
289 | if (!(q->qs[pri] = req->next)) |
334 | if (!(q->qs[pri] = req->next)) |
290 | q->qe[pri] = 0; |
335 | q->qe[pri] = 0; |
… | |
… | |
294 | } |
339 | } |
295 | |
340 | |
296 | abort (); |
341 | abort (); |
297 | } |
342 | } |
298 | |
343 | |
299 | static int poll_cb (); |
344 | static int poll_cb (void); |
300 | static void req_free (aio_req req); |
345 | static void req_free (bdb_req req); |
301 | static void req_cancel (aio_req req); |
346 | static void req_cancel (bdb_req req); |
302 | |
347 | |
303 | static int req_invoke (aio_req req) |
348 | static int req_invoke (bdb_req req) |
304 | { |
349 | { |
305 | dSP; |
350 | dSP; |
306 | |
351 | |
307 | if (SvOK (req->callback)) |
352 | if (req->callback) |
308 | { |
353 | { |
309 | ENTER; |
354 | ENTER; |
310 | SAVETMPS; |
355 | SAVETMPS; |
311 | PUSHMARK (SP); |
356 | PUSHMARK (SP); |
312 | |
357 | |
… | |
… | |
346 | sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); |
391 | sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); |
347 | SvREFCNT_dec (req->sv1); |
392 | SvREFCNT_dec (req->sv1); |
348 | } |
393 | } |
349 | break; |
394 | break; |
350 | |
395 | |
|
|
396 | #if DB_VERSION_MINOR >= 3 |
351 | case REQ_SEQ_GET: |
397 | case REQ_SEQ_GET: |
352 | SvREADONLY_off (req->sv1); |
398 | SvREADONLY_off (req->sv1); |
353 | |
399 | |
354 | if (sizeof (IV) > 4) |
400 | if (sizeof (IV) > 4) |
355 | sv_setiv_mg (req->sv1, (IV)req->seq_t); |
401 | sv_setiv_mg (req->sv1, (IV)req->seq_t); |
356 | else |
402 | else |
357 | sv_setnv_mg (req->sv1, (NV)req->seq_t); |
403 | sv_setnv_mg (req->sv1, (NV)req->seq_t); |
358 | |
404 | |
359 | SvREFCNT_dec (req->sv1); |
405 | SvREFCNT_dec (req->sv1); |
360 | break; |
406 | break; |
|
|
407 | #endif |
361 | } |
408 | } |
362 | |
409 | |
363 | errno = req->result; |
410 | errno = req->result; |
364 | |
411 | |
365 | PUTBACK; |
412 | PUTBACK; |
… | |
… | |
371 | } |
418 | } |
372 | |
419 | |
373 | return !SvTRUE (ERRSV); |
420 | return !SvTRUE (ERRSV); |
374 | } |
421 | } |
375 | |
422 | |
376 | static void req_free (aio_req req) |
423 | static void req_free (bdb_req req) |
377 | { |
424 | { |
|
|
425 | SvREFCNT_dec (req->callback); |
|
|
426 | |
378 | free (req->buf1); |
427 | free (req->buf1); |
379 | free (req->buf2); |
428 | free (req->buf2); |
|
|
429 | free (req->buf3); |
|
|
430 | |
380 | Safefree (req); |
431 | Safefree (req); |
381 | } |
432 | } |
382 | |
433 | |
383 | #ifdef USE_SOCKETS_AS_HANDLES |
434 | #ifdef USE_SOCKETS_AS_HANDLES |
384 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
435 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
385 | #else |
436 | #else |
386 | # define TO_SOCKET(x) (x) |
437 | # define TO_SOCKET(x) (x) |
387 | #endif |
438 | #endif |
388 | |
439 | |
389 | static void |
440 | static void |
390 | create_respipe () |
441 | create_respipe (void) |
391 | { |
442 | { |
392 | #ifdef _WIN32 |
443 | #ifdef _WIN32 |
393 | int arg; /* argg */ |
444 | int arg; /* argg */ |
394 | #endif |
445 | #endif |
395 | int old_readfd = respipe [0]; |
446 | int old_readfd = respipe [0]; |
… | |
… | |
449 | free (wrk); |
500 | free (wrk); |
450 | |
501 | |
451 | X_UNLOCK (wrklock); |
502 | X_UNLOCK (wrklock); |
452 | } |
503 | } |
453 | |
504 | |
454 | static void maybe_start_thread () |
505 | static void maybe_start_thread (void) |
455 | { |
506 | { |
456 | if (get_nthreads () >= wanted) |
507 | if (get_nthreads () >= wanted) |
457 | return; |
508 | return; |
458 | |
509 | |
459 | /* todo: maybe use idle here, but might be less exact */ |
510 | /* todo: maybe use idle here, but might be less exact */ |
… | |
… | |
461 | return; |
512 | return; |
462 | |
513 | |
463 | start_thread (); |
514 | start_thread (); |
464 | } |
515 | } |
465 | |
516 | |
466 | static void req_send (aio_req req) |
517 | static void req_send (bdb_req req) |
467 | { |
518 | { |
468 | SV *wait_callback = 0; |
519 | SV *wait_callback = 0; |
469 | |
520 | |
|
|
521 | if (on_next_submit) |
|
|
522 | { |
|
|
523 | dSP; |
|
|
524 | SV *cb = sv_2mortal (on_next_submit); |
|
|
525 | |
|
|
526 | on_next_submit = 0; |
|
|
527 | |
|
|
528 | PUSHMARK (SP); |
|
|
529 | PUTBACK; |
|
|
530 | call_sv (cb, G_DISCARD | G_EVAL); |
|
|
531 | } |
|
|
532 | |
470 | // synthesize callback if none given |
533 | // synthesize callback if none given |
471 | if (!SvOK (req->callback)) |
534 | if (!req->callback) |
472 | { |
535 | { |
473 | int count; |
536 | int count; |
474 | |
537 | |
475 | dSP; |
538 | dSP; |
476 | PUSHMARK (SP); |
539 | PUSHMARK (SP); |
… | |
… | |
479 | SPAGAIN; |
542 | SPAGAIN; |
480 | |
543 | |
481 | if (count != 2) |
544 | if (count != 2) |
482 | croak ("prepare callback must return exactly two values\n"); |
545 | croak ("prepare callback must return exactly two values\n"); |
483 | |
546 | |
484 | wait_callback = SvREFCNT_inc (POPs); |
547 | wait_callback = POPs; |
485 | SvREFCNT_dec (req->callback); |
548 | SvREFCNT_dec (req->callback); |
486 | req->callback = SvREFCNT_inc (POPs); |
549 | req->callback = SvREFCNT_inc (POPs); |
487 | } |
550 | } |
488 | |
551 | |
489 | ++nreqs; |
552 | ++nreqs; |
… | |
… | |
500 | { |
563 | { |
501 | dSP; |
564 | dSP; |
502 | PUSHMARK (SP); |
565 | PUSHMARK (SP); |
503 | PUTBACK; |
566 | PUTBACK; |
504 | call_sv (wait_callback, G_DISCARD); |
567 | call_sv (wait_callback, G_DISCARD); |
505 | SvREFCNT_dec (wait_callback); |
|
|
506 | } |
568 | } |
507 | } |
569 | } |
508 | |
570 | |
509 | static void end_thread (void) |
571 | static void end_thread (void) |
510 | { |
572 | { |
511 | aio_req req; |
573 | bdb_req req; |
512 | |
574 | |
513 | Newz (0, req, 1, aio_cb); |
575 | Newz (0, req, 1, bdb_cb); |
514 | |
576 | |
515 | req->type = REQ_QUIT; |
577 | req->type = REQ_QUIT; |
516 | req->pri = PRI_MAX + PRI_BIAS; |
578 | req->pri = PRI_MAX + PRI_BIAS; |
517 | |
579 | |
518 | X_LOCK (reqlock); |
580 | X_LOCK (reqlock); |
… | |
… | |
545 | |
607 | |
546 | while (started > wanted) |
608 | while (started > wanted) |
547 | end_thread (); |
609 | end_thread (); |
548 | } |
610 | } |
549 | |
611 | |
550 | static void poll_wait () |
612 | static void poll_wait (void) |
551 | { |
613 | { |
552 | fd_set rfd; |
614 | fd_set rfd; |
553 | |
615 | |
554 | while (nreqs) |
616 | while (nreqs) |
555 | { |
617 | { |
… | |
… | |
568 | |
630 | |
569 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
631 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
570 | } |
632 | } |
571 | } |
633 | } |
572 | |
634 | |
573 | static int poll_cb () |
635 | static int poll_cb (void) |
574 | { |
636 | { |
575 | dSP; |
637 | dSP; |
576 | int count = 0; |
638 | int count = 0; |
577 | int maxreqs = max_poll_reqs; |
639 | int maxreqs = max_poll_reqs; |
578 | int do_croak = 0; |
640 | int do_croak = 0; |
579 | struct timeval tv_start, tv_now; |
641 | struct timeval tv_start, tv_now; |
580 | aio_req req; |
642 | bdb_req req; |
581 | |
643 | |
582 | if (max_poll_time) |
644 | if (max_poll_time) |
583 | gettimeofday (&tv_start, 0); |
645 | gettimeofday (&tv_start, 0); |
584 | |
646 | |
585 | for (;;) |
647 | for (;;) |
… | |
… | |
646 | |
708 | |
647 | /*****************************************************************************/ |
709 | /*****************************************************************************/ |
648 | |
710 | |
649 | X_THREAD_PROC (bdb_proc) |
711 | X_THREAD_PROC (bdb_proc) |
650 | { |
712 | { |
651 | aio_req req; |
713 | bdb_req req; |
652 | struct timespec ts; |
714 | struct timespec ts; |
653 | worker *self = (worker *)thr_arg; |
715 | worker *self = (worker *)thr_arg; |
654 | |
716 | |
655 | /* try to distribute timeouts somewhat evenly */ |
717 | /* try to distribute timeouts somewhat evenly */ |
656 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
718 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
… | |
… | |
723 | |
785 | |
724 | case REQ_ENV_MEMP_TRICKLE: |
786 | case REQ_ENV_MEMP_TRICKLE: |
725 | req->result = req->env->memp_trickle (req->env, req->int1, &req->int2); |
787 | req->result = req->env->memp_trickle (req->env, req->int1, &req->int2); |
726 | break; |
788 | break; |
727 | |
789 | |
|
|
790 | case REQ_ENV_DBREMOVE: |
|
|
791 | req->result = req->env->dbremove (req->env, req->txn, req->buf1, req->buf2, req->uint1); |
|
|
792 | break; |
|
|
793 | |
|
|
794 | case REQ_ENV_DBRENAME: |
|
|
795 | req->result = req->env->dbrename (req->env, req->txn, req->buf1, req->buf2, req->buf3, req->uint1); |
|
|
796 | break; |
|
|
797 | |
728 | case REQ_DB_OPEN: |
798 | case REQ_DB_OPEN: |
729 | req->result = req->db->open (req->db, req->txn, req->buf1, req->buf2, req->int1, req->uint1, req->int2); |
799 | req->result = req->db->open (req->db, req->txn, req->buf1, req->buf2, req->int1, req->uint1, req->int2); |
730 | break; |
800 | break; |
731 | |
801 | |
732 | case REQ_DB_CLOSE: |
802 | case REQ_DB_CLOSE: |
733 | req->result = req->db->close (req->db, req->uint1); |
803 | req->result = req->db->close (req->db, req->uint1); |
734 | break; |
804 | break; |
735 | |
805 | |
|
|
806 | #if DB_VERSION_MINOR >= 4 |
736 | case REQ_DB_COMPACT: |
807 | case REQ_DB_COMPACT: |
737 | req->result = req->db->compact (req->db, req->txn, &req->dbt1, &req->dbt2, 0, req->uint1, 0); |
808 | req->result = req->db->compact (req->db, req->txn, &req->dbt1, &req->dbt2, 0, req->uint1, 0); |
738 | break; |
809 | break; |
|
|
810 | #endif |
739 | |
811 | |
740 | case REQ_DB_SYNC: |
812 | case REQ_DB_SYNC: |
741 | req->result = req->db->sync (req->db, req->uint1); |
813 | req->result = req->db->sync (req->db, req->uint1); |
742 | break; |
814 | break; |
743 | |
815 | |
… | |
… | |
747 | |
819 | |
748 | case REQ_DB_PUT: |
820 | case REQ_DB_PUT: |
749 | req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1); |
821 | req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1); |
750 | break; |
822 | break; |
751 | |
823 | |
|
|
824 | #if DB_VERSION_MINOR >= 6 |
|
|
825 | case REQ_DB_EXISTS: |
|
|
826 | req->result = req->db->exists (req->db, req->txn, &req->dbt1, req->uint1); |
|
|
827 | break; |
|
|
828 | #endif |
752 | case REQ_DB_GET: |
829 | case REQ_DB_GET: |
753 | req->result = req->db->get (req->db, req->txn, &req->dbt1, &req->dbt3, req->uint1); |
830 | req->result = req->db->get (req->db, req->txn, &req->dbt1, &req->dbt3, req->uint1); |
754 | break; |
831 | break; |
755 | |
832 | |
756 | case REQ_DB_PGET: |
833 | case REQ_DB_PGET: |
… | |
… | |
810 | |
887 | |
811 | case REQ_C_DEL: |
888 | case REQ_C_DEL: |
812 | req->result = req->dbc->c_del (req->dbc, req->uint1); |
889 | req->result = req->dbc->c_del (req->dbc, req->uint1); |
813 | break; |
890 | break; |
814 | |
891 | |
|
|
892 | #if DB_VERSION_MINOR >= 3 |
815 | case REQ_SEQ_OPEN: |
893 | case REQ_SEQ_OPEN: |
816 | req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1); |
894 | req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1); |
817 | break; |
895 | break; |
818 | |
896 | |
819 | case REQ_SEQ_CLOSE: |
897 | case REQ_SEQ_CLOSE: |
… | |
… | |
825 | break; |
903 | break; |
826 | |
904 | |
827 | case REQ_SEQ_REMOVE: |
905 | case REQ_SEQ_REMOVE: |
828 | req->result = req->seq->remove (req->seq, req->txn, req->uint1); |
906 | req->result = req->seq->remove (req->seq, req->txn, req->uint1); |
829 | break; |
907 | break; |
|
|
908 | #endif |
830 | |
909 | |
831 | default: |
910 | default: |
832 | req->result = ENOSYS; |
911 | req->result = ENOSYS; |
833 | break; |
912 | break; |
834 | } |
913 | } |
… | |
… | |
874 | X_UNLOCK (wrklock); |
953 | X_UNLOCK (wrklock); |
875 | } |
954 | } |
876 | |
955 | |
877 | static void atfork_child (void) |
956 | static void atfork_child (void) |
878 | { |
957 | { |
879 | aio_req prv; |
958 | bdb_req prv; |
880 | |
959 | |
881 | while (prv = reqq_shift (&req_queue)) |
960 | while (prv = reqq_shift (&req_queue)) |
882 | req_free (prv); |
961 | req_free (prv); |
883 | |
962 | |
884 | while (prv = reqq_shift (&res_queue)) |
963 | while (prv = reqq_shift (&res_queue)) |
… | |
… | |
905 | |
984 | |
906 | atfork_parent (); |
985 | atfork_parent (); |
907 | } |
986 | } |
908 | |
987 | |
909 | #define dREQ(reqtype) \ |
988 | #define dREQ(reqtype) \ |
910 | aio_req req; \ |
989 | bdb_req req; \ |
911 | int req_pri = next_pri; \ |
990 | int req_pri = next_pri; \ |
912 | next_pri = DEFAULT_PRI + PRI_BIAS; \ |
991 | next_pri = DEFAULT_PRI + PRI_BIAS; \ |
913 | \ |
992 | \ |
914 | if (SvOK (callback) && !SvROK (callback)) \ |
993 | if (callback && SvOK (callback)) \ |
915 | croak ("callback must be undef or of reference type"); \ |
994 | croak ("callback has illegal type or extra arguments"); \ |
916 | \ |
995 | \ |
917 | Newz (0, req, 1, aio_cb); \ |
996 | Newz (0, req, 1, bdb_cb); \ |
918 | if (!req) \ |
997 | if (!req) \ |
919 | croak ("out of memory during aio_req allocation"); \ |
998 | croak ("out of memory during bdb_req allocation"); \ |
920 | \ |
999 | \ |
921 | req->callback = newSVsv (callback); \ |
1000 | req->callback = cb ? SvREFCNT_inc (cb) : 0; \ |
922 | req->type = (reqtype); \ |
1001 | req->type = (reqtype); \ |
923 | req->pri = req_pri |
1002 | req->pri = req_pri |
924 | |
1003 | |
925 | #define REQ_SEND \ |
1004 | #define REQ_SEND \ |
926 | req_send (req) |
1005 | req_send (req) |
927 | |
1006 | |
928 | #define SvPTR(var, arg, type, class, nullok) \ |
1007 | #define SvPTR(var, arg, type, class, nullok) \ |
929 | if (!SvOK (arg)) \ |
1008 | if (!SvOK (arg)) \ |
930 | { \ |
1009 | { \ |
931 | if (!nullok) \ |
1010 | if (nullok != 1) \ |
932 | croak (# var " must be a " # class " object, not undef"); \ |
1011 | croak (# var " must be a " # class " object, not undef"); \ |
933 | \ |
1012 | \ |
934 | (var) = 0; \ |
1013 | (var) = 0; \ |
935 | } \ |
1014 | } \ |
936 | else if (sv_derived_from ((arg), # class)) \ |
1015 | else if (sv_derived_from ((arg), # class)) \ |
937 | { \ |
1016 | { \ |
938 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
1017 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
939 | (var) = INT2PTR (type, tmp); \ |
1018 | (var) = INT2PTR (type, tmp); \ |
940 | if (!var) \ |
1019 | if (!var && nullok != 2) \ |
941 | croak (# var " is not a valid " # class " object anymore"); \ |
1020 | croak (# var " is not a valid " # class " object anymore"); \ |
942 | } \ |
1021 | } \ |
943 | else \ |
1022 | else \ |
944 | croak (# var " is not of type " # class); \ |
1023 | croak (# var " is not of type " # class); |
945 | \ |
|
|
946 | |
1024 | |
947 | static void |
1025 | static void |
948 | ptr_nuke (SV *sv) |
1026 | ptr_nuke (SV *sv) |
949 | { |
1027 | { |
950 | assert (SvROK (sv)); |
1028 | assert (SvROK (sv)); |
951 | sv_setiv (SvRV (sv), 0); |
1029 | sv_setiv (SvRV (sv), 0); |
952 | } |
1030 | } |
|
|
1031 | |
|
|
1032 | static int |
|
|
1033 | errno_get (pTHX_ SV *sv, MAGIC *mg) |
|
|
1034 | { |
|
|
1035 | if (*mg->mg_ptr == '!') // should always be the case |
|
|
1036 | if (-30999 <= errno && errno <= -30800) |
|
|
1037 | { |
|
|
1038 | sv_setnv (sv, (NV)errno); |
|
|
1039 | sv_setpv (sv, db_strerror (errno)); |
|
|
1040 | SvNOK_on (sv); /* what a wonderful hack! */ |
|
|
1041 | // ^^^ copied from perl sources |
|
|
1042 | return 0; |
|
|
1043 | } |
|
|
1044 | |
|
|
1045 | return PL_vtbl_sv.svt_get (aTHX_ sv, mg); |
|
|
1046 | } |
|
|
1047 | |
|
|
1048 | static MGVTBL vtbl_errno; |
|
|
1049 | |
|
|
1050 | // this wonderful hack :( patches perl's $! variable to support our errno values |
|
|
1051 | static void |
|
|
1052 | patch_errno (void) |
|
|
1053 | { |
|
|
1054 | SV *sv; |
|
|
1055 | MAGIC *mg; |
|
|
1056 | |
|
|
1057 | if (!(sv = get_sv ("!", 1))) |
|
|
1058 | return; |
|
|
1059 | |
|
|
1060 | if (!(mg = mg_find (sv, PERL_MAGIC_sv))) |
|
|
1061 | return; |
|
|
1062 | |
|
|
1063 | if (mg->mg_virtual != &PL_vtbl_sv) |
|
|
1064 | return; |
|
|
1065 | |
|
|
1066 | vtbl_errno = PL_vtbl_sv; |
|
|
1067 | vtbl_errno.svt_get = errno_get; |
|
|
1068 | mg->mg_virtual = &vtbl_errno; |
|
|
1069 | } |
|
|
1070 | |
|
|
1071 | #if __GNUC__ >= 4 |
|
|
1072 | # define noinline __attribute__ ((noinline)) |
|
|
1073 | #else |
|
|
1074 | # define noinline |
|
|
1075 | #endif |
|
|
1076 | |
|
|
1077 | static noinline SV * |
|
|
1078 | pop_callback (I32 *ritems, SV *sv) |
|
|
1079 | { |
|
|
1080 | if (SvROK (sv)) |
|
|
1081 | { |
|
|
1082 | HV *st; |
|
|
1083 | GV *gvp; |
|
|
1084 | CV *cv; |
|
|
1085 | const char *name; |
|
|
1086 | |
|
|
1087 | /* forgive me */ |
|
|
1088 | if (SvTYPE (SvRV (sv)) == SVt_PVMG |
|
|
1089 | && (st = SvSTASH (SvRV (sv))) |
|
|
1090 | && (name = HvNAME_get (st)) |
|
|
1091 | && (name [0] == 'B' && name [1] == 'D' && name [2] == 'B' && name [3] == ':')) |
|
|
1092 | return 0; |
|
|
1093 | |
|
|
1094 | if ((cv = sv_2cv (sv, &st, &gvp, 0))) |
|
|
1095 | { |
|
|
1096 | --*ritems; |
|
|
1097 | return (SV *)cv; |
|
|
1098 | } |
|
|
1099 | } |
|
|
1100 | |
|
|
1101 | return 0; |
|
|
1102 | } |
|
|
1103 | |
|
|
1104 | /* stupid windoes defined CALLBACK as well */ |
|
|
1105 | #undef CALLBACK |
|
|
1106 | #define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); |
953 | |
1107 | |
954 | MODULE = BDB PACKAGE = BDB |
1108 | MODULE = BDB PACKAGE = BDB |
955 | |
1109 | |
956 | PROTOTYPES: ENABLE |
1110 | PROTOTYPES: ENABLE |
957 | |
1111 | |
… | |
… | |
978 | const_iv (RDONLY) |
1132 | const_iv (RDONLY) |
979 | const_iv (USE_ENVIRON) |
1133 | const_iv (USE_ENVIRON) |
980 | const_iv (USE_ENVIRON_ROOT) |
1134 | const_iv (USE_ENVIRON_ROOT) |
981 | const_iv (LOCKDOWN) |
1135 | const_iv (LOCKDOWN) |
982 | const_iv (PRIVATE) |
1136 | const_iv (PRIVATE) |
983 | const_iv (REGISTER) |
|
|
984 | const_iv (SYSTEM_MEM) |
1137 | const_iv (SYSTEM_MEM) |
985 | const_iv (AUTO_COMMIT) |
1138 | const_iv (AUTO_COMMIT) |
986 | const_iv (CDB_ALLDB) |
1139 | const_iv (CDB_ALLDB) |
987 | const_iv (DIRECT_DB) |
1140 | const_iv (DIRECT_DB) |
988 | const_iv (DIRECT_LOG) |
|
|
989 | const_iv (DSYNC_DB) |
|
|
990 | const_iv (DSYNC_LOG) |
|
|
991 | const_iv (LOG_AUTOREMOVE) |
|
|
992 | const_iv (LOG_INMEMORY) |
|
|
993 | const_iv (NOLOCKING) |
1141 | const_iv (NOLOCKING) |
994 | const_iv (NOMMAP) |
1142 | const_iv (NOMMAP) |
995 | const_iv (NOPANIC) |
1143 | const_iv (NOPANIC) |
996 | const_iv (OVERWRITE) |
1144 | const_iv (OVERWRITE) |
997 | const_iv (PANIC_ENVIRONMENT) |
1145 | const_iv (PANIC_ENVIRONMENT) |
… | |
… | |
1008 | const_iv (HASH) |
1156 | const_iv (HASH) |
1009 | const_iv (QUEUE) |
1157 | const_iv (QUEUE) |
1010 | const_iv (RECNO) |
1158 | const_iv (RECNO) |
1011 | const_iv (UNKNOWN) |
1159 | const_iv (UNKNOWN) |
1012 | const_iv (EXCL) |
1160 | const_iv (EXCL) |
1013 | const_iv (READ_COMMITTED) |
|
|
1014 | const_iv (READ_UNCOMMITTED) |
|
|
1015 | const_iv (TRUNCATE) |
1161 | const_iv (TRUNCATE) |
1016 | const_iv (NOSYNC) |
1162 | const_iv (NOSYNC) |
1017 | const_iv (CHKSUM) |
1163 | const_iv (CHKSUM) |
1018 | const_iv (ENCRYPT) |
1164 | const_iv (ENCRYPT) |
1019 | const_iv (DUP) |
1165 | const_iv (DUP) |
1020 | const_iv (DUPSORT) |
1166 | const_iv (DUPSORT) |
1021 | const_iv (RECNUM) |
1167 | const_iv (RECNUM) |
1022 | const_iv (RENUMBER) |
1168 | const_iv (RENUMBER) |
1023 | const_iv (REVSPLITOFF) |
1169 | const_iv (REVSPLITOFF) |
1024 | const_iv (INORDER) |
|
|
1025 | const_iv (CONSUME) |
1170 | const_iv (CONSUME) |
1026 | const_iv (CONSUME_WAIT) |
1171 | const_iv (CONSUME_WAIT) |
1027 | const_iv (GET_BOTH) |
1172 | const_iv (GET_BOTH) |
1028 | const_iv (GET_BOTH_RANGE) |
1173 | const_iv (GET_BOTH_RANGE) |
1029 | //const_iv (SET_RECNO) |
1174 | //const_iv (SET_RECNO) |
1030 | //const_iv (MULTIPLE) |
1175 | //const_iv (MULTIPLE) |
1031 | const_iv (SNAPSHOT) |
1176 | const_iv (SNAPSHOT) |
1032 | const_iv (JOIN_ITEM) |
1177 | const_iv (JOIN_ITEM) |
|
|
1178 | const_iv (JOIN_NOSORT) |
1033 | const_iv (RMW) |
1179 | const_iv (RMW) |
1034 | |
1180 | |
1035 | const_iv (NOTFOUND) |
1181 | const_iv (NOTFOUND) |
1036 | const_iv (KEYEMPTY) |
1182 | const_iv (KEYEMPTY) |
1037 | const_iv (LOCK_DEADLOCK) |
1183 | const_iv (LOCK_DEADLOCK) |
1038 | const_iv (LOCK_NOTGRANTED) |
1184 | const_iv (LOCK_NOTGRANTED) |
1039 | const_iv (RUNRECOVERY) |
1185 | const_iv (RUNRECOVERY) |
1040 | const_iv (OLD_VERSION) |
1186 | const_iv (OLD_VERSION) |
1041 | const_iv (REP_HANDLE_DEAD) |
1187 | const_iv (REP_HANDLE_DEAD) |
1042 | const_iv (REP_LOCKOUT) |
|
|
1043 | const_iv (SECONDARY_BAD) |
1188 | const_iv (SECONDARY_BAD) |
1044 | |
|
|
1045 | const_iv (FREE_SPACE) |
|
|
1046 | const_iv (FREELIST_ONLY) |
|
|
1047 | |
1189 | |
1048 | const_iv (APPEND) |
1190 | const_iv (APPEND) |
1049 | const_iv (NODUPDATA) |
1191 | const_iv (NODUPDATA) |
1050 | const_iv (NOOVERWRITE) |
1192 | const_iv (NOOVERWRITE) |
1051 | |
1193 | |
… | |
… | |
1053 | const_iv (TXN_SYNC) |
1195 | const_iv (TXN_SYNC) |
1054 | |
1196 | |
1055 | const_iv (SET_LOCK_TIMEOUT) |
1197 | const_iv (SET_LOCK_TIMEOUT) |
1056 | const_iv (SET_TXN_TIMEOUT) |
1198 | const_iv (SET_TXN_TIMEOUT) |
1057 | |
1199 | |
1058 | const_iv (JOIN_ITEM) |
|
|
1059 | const_iv (FIRST) |
1200 | const_iv (FIRST) |
1060 | const_iv (NEXT) |
1201 | const_iv (NEXT) |
1061 | const_iv (NEXT_DUP) |
1202 | const_iv (NEXT_DUP) |
1062 | const_iv (NEXT_NODUP) |
1203 | const_iv (NEXT_NODUP) |
1063 | const_iv (PREV) |
1204 | const_iv (PREV) |
… | |
… | |
1075 | const_iv (FORCE) |
1216 | const_iv (FORCE) |
1076 | |
1217 | |
1077 | const_iv (LOCK_DEFAULT) |
1218 | const_iv (LOCK_DEFAULT) |
1078 | const_iv (LOCK_EXPIRE) |
1219 | const_iv (LOCK_EXPIRE) |
1079 | const_iv (LOCK_MAXLOCKS) |
1220 | const_iv (LOCK_MAXLOCKS) |
1080 | const_iv (LOCK_MAXWRITE) |
|
|
1081 | const_iv (LOCK_MINLOCKS) |
1221 | const_iv (LOCK_MINLOCKS) |
1082 | const_iv (LOCK_MINWRITE) |
1222 | const_iv (LOCK_MINWRITE) |
1083 | const_iv (LOCK_OLDEST) |
1223 | const_iv (LOCK_OLDEST) |
1084 | const_iv (LOCK_RANDOM) |
1224 | const_iv (LOCK_RANDOM) |
1085 | const_iv (LOCK_YOUNGEST) |
1225 | const_iv (LOCK_YOUNGEST) |
1086 | |
1226 | |
1087 | const_iv (SEQ_DEC) |
|
|
1088 | const_iv (SEQ_INC) |
|
|
1089 | const_iv (SEQ_WRAP) |
|
|
1090 | |
|
|
1091 | const_iv (BUFFER_SMALL) |
|
|
1092 | const_iv (DONOTINDEX) |
1227 | const_iv (DONOTINDEX) |
1093 | const_iv (KEYEMPTY ) |
1228 | const_iv (KEYEMPTY ) |
1094 | const_iv (KEYEXIST ) |
1229 | const_iv (KEYEXIST ) |
1095 | const_iv (LOCK_DEADLOCK) |
1230 | const_iv (LOCK_DEADLOCK) |
1096 | const_iv (LOCK_NOTGRANTED) |
1231 | const_iv (LOCK_NOTGRANTED) |
1097 | const_iv (LOG_BUFFER_FULL) |
|
|
1098 | const_iv (NOSERVER) |
1232 | const_iv (NOSERVER) |
1099 | const_iv (NOSERVER_HOME) |
1233 | const_iv (NOSERVER_HOME) |
1100 | const_iv (NOSERVER_ID) |
1234 | const_iv (NOSERVER_ID) |
1101 | const_iv (NOTFOUND) |
1235 | const_iv (NOTFOUND) |
1102 | const_iv (PAGE_NOTFOUND) |
1236 | const_iv (PAGE_NOTFOUND) |
1103 | const_iv (REP_DUPMASTER) |
1237 | const_iv (REP_DUPMASTER) |
1104 | const_iv (REP_HANDLE_DEAD) |
1238 | const_iv (REP_HANDLE_DEAD) |
1105 | const_iv (REP_HOLDELECTION) |
1239 | const_iv (REP_HOLDELECTION) |
1106 | const_iv (REP_IGNORE) |
|
|
1107 | const_iv (REP_ISPERM) |
1240 | const_iv (REP_ISPERM) |
1108 | const_iv (REP_JOIN_FAILURE) |
|
|
1109 | const_iv (REP_LOCKOUT) |
|
|
1110 | const_iv (REP_NEWMASTER) |
1241 | const_iv (REP_NEWMASTER) |
1111 | const_iv (REP_NEWSITE) |
1242 | const_iv (REP_NEWSITE) |
1112 | const_iv (REP_NOTPERM) |
1243 | const_iv (REP_NOTPERM) |
1113 | const_iv (REP_UNAVAIL) |
1244 | const_iv (REP_UNAVAIL) |
1114 | const_iv (RUNRECOVERY) |
1245 | const_iv (RUNRECOVERY) |
1115 | const_iv (SECONDARY_BAD) |
1246 | const_iv (SECONDARY_BAD) |
1116 | const_iv (VERIFY_BAD) |
1247 | const_iv (VERIFY_BAD) |
1117 | const_iv (VERSION_MISMATCH) |
|
|
1118 | |
1248 | |
1119 | const_iv (VERB_DEADLOCK) |
1249 | const_iv (VERB_DEADLOCK) |
1120 | const_iv (VERB_RECOVERY) |
1250 | const_iv (VERB_RECOVERY) |
1121 | const_iv (VERB_REGISTER) |
|
|
1122 | const_iv (VERB_REPLICATION) |
1251 | const_iv (VERB_REPLICATION) |
1123 | const_iv (VERB_WAITSFOR) |
1252 | const_iv (VERB_WAITSFOR) |
1124 | |
1253 | |
1125 | const_iv (VERSION_MAJOR) |
1254 | const_iv (VERSION_MAJOR) |
1126 | const_iv (VERSION_MINOR) |
1255 | const_iv (VERSION_MINOR) |
1127 | const_iv (VERSION_PATCH) |
1256 | const_iv (VERSION_PATCH) |
|
|
1257 | #if DB_VERSION_MINOR >= 3 |
|
|
1258 | const_iv (INORDER) |
|
|
1259 | const_iv (LOCK_MAXWRITE) |
|
|
1260 | const_iv (SEQ_DEC) |
|
|
1261 | const_iv (SEQ_INC) |
|
|
1262 | const_iv (SEQ_WRAP) |
|
|
1263 | const_iv (BUFFER_SMALL) |
|
|
1264 | const_iv (LOG_BUFFER_FULL) |
|
|
1265 | const_iv (VERSION_MISMATCH) |
|
|
1266 | #endif |
|
|
1267 | #if DB_VERSION_MINOR >= 4 |
|
|
1268 | const_iv (REGISTER) |
|
|
1269 | const_iv (DSYNC_DB) |
|
|
1270 | const_iv (READ_COMMITTED) |
|
|
1271 | const_iv (READ_UNCOMMITTED) |
|
|
1272 | const_iv (REP_IGNORE) |
|
|
1273 | const_iv (REP_LOCKOUT) |
|
|
1274 | const_iv (REP_JOIN_FAILURE) |
|
|
1275 | const_iv (FREE_SPACE) |
|
|
1276 | const_iv (FREELIST_ONLY) |
|
|
1277 | const_iv (VERB_REGISTER) |
|
|
1278 | #endif |
1128 | #if DB_VERSION_MINOR >= 5 |
1279 | #if DB_VERSION_MINOR >= 5 |
1129 | const_iv (MULTIVERSION) |
1280 | const_iv (MULTIVERSION) |
1130 | const_iv (TXN_SNAPSHOT) |
1281 | const_iv (TXN_SNAPSHOT) |
1131 | #endif |
1282 | #endif |
1132 | #if DB_VERSION_MINOR >= 6 |
1283 | #if DB_VERSION_MINOR >= 6 |
1133 | const_iv (PREV_DUP) |
1284 | const_iv (PREV_DUP) |
1134 | # if 0 |
|
|
1135 | const_iv (PRIORITY_UNCHANGED) |
1285 | const_iv (PRIORITY_UNCHANGED) |
1136 | const_iv (PRIORITY_VERY_LOW) |
1286 | const_iv (PRIORITY_VERY_LOW) |
1137 | const_iv (PRIORITY_LOW) |
1287 | const_iv (PRIORITY_LOW) |
1138 | const_iv (PRIORITY_DEFAULT) |
1288 | const_iv (PRIORITY_DEFAULT) |
1139 | const_iv (PRIORITY_HIGH) |
1289 | const_iv (PRIORITY_HIGH) |
1140 | const_iv (PRIORITY_VERY_HIGH) |
1290 | const_iv (PRIORITY_VERY_HIGH) |
|
|
1291 | #endif |
|
|
1292 | #if DB_VERSION_MINOR >= 7 |
|
|
1293 | const_iv (LOG_DIRECT) |
|
|
1294 | const_iv (LOG_DSYNC) |
|
|
1295 | const_iv (LOG_AUTO_REMOVE) |
|
|
1296 | const_iv (LOG_IN_MEMORY) |
|
|
1297 | const_iv (LOG_ZERO) |
|
|
1298 | #else |
|
|
1299 | const_iv (DIRECT_LOG) |
|
|
1300 | const_iv (LOG_AUTOREMOVE) |
|
|
1301 | # if DB_VERSION_MINOR >= 3 |
|
|
1302 | const_iv (DSYNC_LOG) |
|
|
1303 | const_iv (LOG_INMEMORY) |
1141 | # endif |
1304 | # endif |
1142 | #endif |
1305 | #endif |
1143 | }; |
1306 | }; |
1144 | |
1307 | |
1145 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1308 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1146 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1309 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1147 | |
1310 | |
1148 | newCONSTSUB (stash, "VERSION", newSVnv (DB_VERSION_MAJOR + DB_VERSION_MINOR * .1)); |
1311 | { |
|
|
1312 | /* we currently only allow version, minor-version and patchlevel to go up to 255 */ |
|
|
1313 | char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; |
|
|
1314 | |
|
|
1315 | newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); |
|
|
1316 | } |
|
|
1317 | |
1149 | newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1318 | newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1150 | |
1319 | |
1151 | create_respipe (); |
1320 | create_respipe (); |
1152 | |
1321 | |
1153 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1322 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1154 | #ifdef _WIN32 |
1323 | patch_errno (); |
1155 | X_MUTEX_CHECK (wrklock); |
|
|
1156 | X_MUTEX_CHECK (reslock); |
|
|
1157 | X_MUTEX_CHECK (reqlock); |
|
|
1158 | |
|
|
1159 | X_COND_CHECK (reqwait); |
|
|
1160 | #endif |
|
|
1161 | } |
1324 | } |
1162 | |
1325 | |
1163 | void |
1326 | void |
1164 | max_poll_reqs (int nreqs) |
1327 | max_poll_reqs (int nreqs) |
1165 | PROTOTYPE: $ |
1328 | PROTOTYPE: $ |
… | |
… | |
1305 | CODE: |
1468 | CODE: |
1306 | RETVAL = db_strerror (errorno); |
1469 | RETVAL = db_strerror (errorno); |
1307 | OUTPUT: |
1470 | OUTPUT: |
1308 | RETVAL |
1471 | RETVAL |
1309 | |
1472 | |
|
|
1473 | void _on_next_submit (SV *cb) |
|
|
1474 | CODE: |
|
|
1475 | SvREFCNT_dec (on_next_submit); |
|
|
1476 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
|
|
1477 | |
1310 | DB_ENV * |
1478 | DB_ENV * |
1311 | db_env_create (U32 env_flags = 0) |
1479 | db_env_create (U32 env_flags = 0) |
1312 | CODE: |
1480 | CODE: |
1313 | { |
1481 | { |
1314 | errno = db_env_create (&RETVAL, env_flags); |
1482 | errno = db_env_create (&RETVAL, env_flags); |
… | |
… | |
1323 | } |
1491 | } |
1324 | OUTPUT: |
1492 | OUTPUT: |
1325 | RETVAL |
1493 | RETVAL |
1326 | |
1494 | |
1327 | void |
1495 | void |
1328 | db_env_open (DB_ENV *env, octetstring db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef) |
1496 | db_env_open (DB_ENV *env, bdb_filename db_home, U32 open_flags, int mode, SV *callback = 0) |
|
|
1497 | PREINIT: |
|
|
1498 | CALLBACK |
1329 | CODE: |
1499 | CODE: |
1330 | { |
1500 | { |
1331 | dREQ (REQ_ENV_OPEN); |
1501 | dREQ (REQ_ENV_OPEN); |
1332 | |
|
|
1333 | env->set_thread_count (env, wanted + 2); |
|
|
1334 | |
|
|
1335 | req->env = env; |
1502 | req->env = env; |
1336 | req->uint1 = open_flags | DB_THREAD; |
1503 | req->uint1 = open_flags | DB_THREAD; |
1337 | req->int1 = mode; |
1504 | req->int1 = mode; |
1338 | req->buf1 = strdup_ornull (db_home); |
1505 | req->buf1 = strdup_ornull (db_home); |
1339 | REQ_SEND; |
1506 | REQ_SEND; |
1340 | } |
1507 | } |
1341 | |
1508 | |
1342 | void |
1509 | void |
1343 | db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = &PL_sv_undef) |
1510 | db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0) |
|
|
1511 | PREINIT: |
|
|
1512 | CALLBACK |
1344 | CODE: |
1513 | CODE: |
1345 | { |
1514 | { |
1346 | dREQ (REQ_ENV_CLOSE); |
1515 | dREQ (REQ_ENV_CLOSE); |
1347 | req->env = env; |
1516 | req->env = env; |
1348 | req->uint1 = flags; |
1517 | req->uint1 = flags; |
1349 | REQ_SEND; |
1518 | REQ_SEND; |
1350 | ptr_nuke (ST (0)); |
1519 | ptr_nuke (ST (0)); |
1351 | } |
1520 | } |
1352 | |
1521 | |
1353 | void |
1522 | void |
1354 | db_env_txn_checkpoint (DB_ENV *env, U32 kbyte = 0, U32 min = 0, U32 flags = 0, SV *callback = &PL_sv_undef) |
1523 | db_env_txn_checkpoint (DB_ENV *env, U32 kbyte = 0, U32 min = 0, U32 flags = 0, SV *callback = 0) |
|
|
1524 | PREINIT: |
|
|
1525 | CALLBACK |
1355 | CODE: |
1526 | CODE: |
1356 | { |
1527 | { |
1357 | dREQ (REQ_ENV_TXN_CHECKPOINT); |
1528 | dREQ (REQ_ENV_TXN_CHECKPOINT); |
1358 | req->env = env; |
1529 | req->env = env; |
1359 | req->uint1 = kbyte; |
1530 | req->uint1 = kbyte; |
… | |
… | |
1361 | req->uint2 = flags; |
1532 | req->uint2 = flags; |
1362 | REQ_SEND; |
1533 | REQ_SEND; |
1363 | } |
1534 | } |
1364 | |
1535 | |
1365 | void |
1536 | void |
1366 | db_env_lock_detect (DB_ENV *env, U32 flags = 0, U32 atype = DB_LOCK_DEFAULT, SV *dummy = 0, SV *callback = &PL_sv_undef) |
1537 | db_env_lock_detect (DB_ENV *env, U32 flags = 0, U32 atype = DB_LOCK_DEFAULT, SV *dummy = 0, SV *callback = 0) |
|
|
1538 | PREINIT: |
|
|
1539 | CALLBACK |
1367 | CODE: |
1540 | CODE: |
1368 | { |
1541 | { |
1369 | dREQ (REQ_ENV_LOCK_DETECT); |
1542 | dREQ (REQ_ENV_LOCK_DETECT); |
1370 | req->env = env; |
1543 | req->env = env; |
1371 | req->uint1 = flags; |
1544 | req->uint1 = flags; |
1372 | req->uint2 = atype; |
1545 | req->uint2 = atype; |
|
|
1546 | /* req->int2 = 0; dummy */ |
1373 | REQ_SEND; |
1547 | REQ_SEND; |
1374 | } |
1548 | } |
1375 | |
1549 | |
1376 | void |
1550 | void |
1377 | db_env_memp_sync (DB_ENV *env, SV *dummy = 0, SV *callback = &PL_sv_undef) |
1551 | db_env_memp_sync (DB_ENV *env, SV *dummy = 0, SV *callback = 0) |
|
|
1552 | PREINIT: |
|
|
1553 | CALLBACK |
1378 | CODE: |
1554 | CODE: |
1379 | { |
1555 | { |
1380 | dREQ (REQ_ENV_MEMP_SYNC); |
1556 | dREQ (REQ_ENV_MEMP_SYNC); |
1381 | req->env = env; |
1557 | req->env = env; |
1382 | REQ_SEND; |
1558 | REQ_SEND; |
1383 | } |
1559 | } |
1384 | |
1560 | |
1385 | void |
1561 | void |
1386 | db_env_memp_trickle (DB_ENV *env, int percent, SV *dummy = 0, SV *callback = &PL_sv_undef) |
1562 | db_env_memp_trickle (DB_ENV *env, int percent, SV *dummy = 0, SV *callback = 0) |
|
|
1563 | PREINIT: |
|
|
1564 | CALLBACK |
1387 | CODE: |
1565 | CODE: |
1388 | { |
1566 | { |
1389 | dREQ (REQ_ENV_MEMP_TRICKLE); |
1567 | dREQ (REQ_ENV_MEMP_TRICKLE); |
1390 | req->env = env; |
1568 | req->env = env; |
1391 | req->int1 = percent; |
1569 | req->int1 = percent; |
1392 | REQ_SEND; |
1570 | REQ_SEND; |
1393 | } |
1571 | } |
1394 | |
1572 | |
|
|
1573 | void |
|
|
1574 | db_env_dbremove (DB_ENV *env, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, U32 flags = 0, SV *callback = 0) |
|
|
1575 | PREINIT: |
|
|
1576 | CALLBACK |
|
|
1577 | CODE: |
|
|
1578 | { |
|
|
1579 | dREQ (REQ_ENV_DBREMOVE); |
|
|
1580 | req->env = env; |
|
|
1581 | req->buf1 = strdup_ornull (file); |
|
|
1582 | req->buf2 = strdup_ornull (database); |
|
|
1583 | req->uint1 = flags; |
|
|
1584 | REQ_SEND; |
|
|
1585 | } |
|
|
1586 | |
|
|
1587 | void |
|
|
1588 | 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) |
|
|
1589 | PREINIT: |
|
|
1590 | CALLBACK |
|
|
1591 | CODE: |
|
|
1592 | { |
|
|
1593 | dREQ (REQ_ENV_DBRENAME); |
|
|
1594 | req->env = env; |
|
|
1595 | req->buf1 = strdup_ornull (file); |
|
|
1596 | req->buf2 = strdup_ornull (database); |
|
|
1597 | req->buf3 = strdup_ornull (newname); |
|
|
1598 | req->uint1 = flags; |
|
|
1599 | REQ_SEND; |
|
|
1600 | } |
1395 | |
1601 | |
1396 | DB * |
1602 | DB * |
1397 | db_create (DB_ENV *env = 0, U32 flags = 0) |
1603 | db_create (DB_ENV *env = 0, U32 flags = 0) |
1398 | CODE: |
1604 | CODE: |
1399 | { |
1605 | { |
… | |
… | |
1406 | } |
1612 | } |
1407 | OUTPUT: |
1613 | OUTPUT: |
1408 | RETVAL |
1614 | RETVAL |
1409 | |
1615 | |
1410 | void |
1616 | void |
1411 | db_open (DB *db, DB_TXN_ornull *txnid, octetstring file, octetstring database, int type, U32 flags, int mode, SV *callback = &PL_sv_undef) |
1617 | db_open (DB *db, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, int type, U32 flags, int mode, SV *callback = 0) |
|
|
1618 | PREINIT: |
|
|
1619 | CALLBACK |
1412 | CODE: |
1620 | CODE: |
1413 | { |
1621 | { |
1414 | dREQ (REQ_DB_OPEN); |
1622 | dREQ (REQ_DB_OPEN); |
1415 | req->db = db; |
1623 | req->db = db; |
1416 | req->txn = txnid; |
1624 | req->txn = txnid; |
… | |
… | |
1421 | req->int2 = mode; |
1629 | req->int2 = mode; |
1422 | REQ_SEND; |
1630 | REQ_SEND; |
1423 | } |
1631 | } |
1424 | |
1632 | |
1425 | void |
1633 | void |
1426 | db_close (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) |
1634 | db_close (DB *db, U32 flags = 0, SV *callback = 0) |
|
|
1635 | PREINIT: |
|
|
1636 | CALLBACK |
1427 | CODE: |
1637 | CODE: |
1428 | { |
1638 | { |
1429 | dREQ (REQ_DB_CLOSE); |
1639 | dREQ (REQ_DB_CLOSE); |
1430 | req->db = db; |
1640 | req->db = db; |
1431 | req->uint1 = flags; |
1641 | req->uint1 = flags; |
1432 | req->sv1 = (SV *)db->app_private; |
1642 | req->sv1 = (SV *)db->app_private; |
1433 | REQ_SEND; |
1643 | REQ_SEND; |
1434 | ptr_nuke (ST (0)); |
1644 | ptr_nuke (ST (0)); |
1435 | } |
1645 | } |
1436 | |
1646 | |
|
|
1647 | #if DB_VERSION_MINOR >= 4 |
|
|
1648 | |
1437 | void |
1649 | void |
1438 | 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) |
1650 | 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) |
|
|
1651 | PREINIT: |
|
|
1652 | CALLBACK |
1439 | CODE: |
1653 | CODE: |
1440 | { |
1654 | { |
1441 | dREQ (REQ_DB_COMPACT); |
1655 | dREQ (REQ_DB_COMPACT); |
1442 | req->db = db; |
1656 | req->db = db; |
1443 | req->txn = txn; |
1657 | req->txn = txn; |
… | |
… | |
1445 | sv_to_dbt (&req->dbt2, stop); |
1659 | sv_to_dbt (&req->dbt2, stop); |
1446 | req->uint1 = flags; |
1660 | req->uint1 = flags; |
1447 | REQ_SEND; |
1661 | REQ_SEND; |
1448 | } |
1662 | } |
1449 | |
1663 | |
|
|
1664 | #endif |
|
|
1665 | |
1450 | void |
1666 | void |
1451 | db_sync (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) |
1667 | db_sync (DB *db, U32 flags = 0, SV *callback = 0) |
|
|
1668 | PREINIT: |
|
|
1669 | CALLBACK |
1452 | CODE: |
1670 | CODE: |
1453 | { |
1671 | { |
1454 | dREQ (REQ_DB_SYNC); |
1672 | dREQ (REQ_DB_SYNC); |
1455 | req->db = db; |
1673 | req->db = db; |
1456 | req->uint1 = flags; |
1674 | req->uint1 = flags; |
1457 | REQ_SEND; |
1675 | REQ_SEND; |
1458 | } |
1676 | } |
1459 | |
1677 | |
1460 | void |
1678 | void |
1461 | db_upgrade (DB *db, octetstring file, U32 flags = 0, SV *callback = &PL_sv_undef) |
1679 | db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) |
|
|
1680 | PREINIT: |
|
|
1681 | CALLBACK |
1462 | CODE: |
1682 | CODE: |
1463 | { |
1683 | { |
1464 | dREQ (REQ_DB_SYNC); |
1684 | dREQ (REQ_DB_SYNC); |
1465 | req->db = db; |
1685 | req->db = db; |
1466 | req->buf1 = strdup (file); |
1686 | req->buf1 = strdup (file); |
1467 | req->uint1 = flags; |
1687 | req->uint1 = flags; |
1468 | REQ_SEND; |
1688 | REQ_SEND; |
1469 | } |
1689 | } |
1470 | |
1690 | |
1471 | void |
1691 | void |
1472 | db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = &PL_sv_undef) |
1692 | db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = 0) |
|
|
1693 | PREINIT: |
|
|
1694 | CALLBACK |
1473 | CODE: |
1695 | CODE: |
1474 | { |
1696 | { |
1475 | dREQ (REQ_DB_KEY_RANGE); |
1697 | dREQ (REQ_DB_KEY_RANGE); |
1476 | req->db = db; |
1698 | req->db = db; |
1477 | req->txn = txn; |
1699 | req->txn = txn; |
… | |
… | |
1480 | req->sv1 = SvREFCNT_inc (key_range); SvREADONLY_on (key_range); |
1702 | req->sv1 = SvREFCNT_inc (key_range); SvREADONLY_on (key_range); |
1481 | REQ_SEND; |
1703 | REQ_SEND; |
1482 | } |
1704 | } |
1483 | |
1705 | |
1484 | void |
1706 | void |
1485 | db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1707 | db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = 0) |
|
|
1708 | PREINIT: |
|
|
1709 | CALLBACK |
1486 | CODE: |
1710 | CODE: |
1487 | { |
1711 | { |
1488 | dREQ (REQ_DB_PUT); |
1712 | dREQ (REQ_DB_PUT); |
1489 | req->db = db; |
1713 | req->db = db; |
1490 | req->txn = txn; |
1714 | req->txn = txn; |
… | |
… | |
1492 | sv_to_dbt (&req->dbt2, data); |
1716 | sv_to_dbt (&req->dbt2, data); |
1493 | req->uint1 = flags; |
1717 | req->uint1 = flags; |
1494 | REQ_SEND; |
1718 | REQ_SEND; |
1495 | } |
1719 | } |
1496 | |
1720 | |
|
|
1721 | #if DB_VERSION_MINOR >= 6 |
|
|
1722 | |
1497 | void |
1723 | void |
|
|
1724 | db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) |
|
|
1725 | PREINIT: |
|
|
1726 | CALLBACK |
|
|
1727 | CODE: |
|
|
1728 | { |
|
|
1729 | dREQ (REQ_DB_EXISTS); |
|
|
1730 | req->db = db; |
|
|
1731 | req->txn = txn; |
|
|
1732 | req->uint1 = flags; |
|
|
1733 | sv_to_dbt (&req->dbt1, key); |
|
|
1734 | REQ_SEND; |
|
|
1735 | } |
|
|
1736 | |
|
|
1737 | #endif |
|
|
1738 | |
|
|
1739 | void |
1498 | db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1740 | db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = 0) |
|
|
1741 | PREINIT: |
|
|
1742 | CALLBACK |
1499 | CODE: |
1743 | CODE: |
|
|
1744 | if (SvREADONLY (data)) |
|
|
1745 | croak ("can't modify read-only data scalar in db_get"); |
1500 | { |
1746 | { |
1501 | dREQ (REQ_DB_GET); |
1747 | dREQ (REQ_DB_GET); |
1502 | req->db = db; |
1748 | req->db = db; |
1503 | req->txn = txn; |
1749 | req->txn = txn; |
1504 | req->uint1 = flags; |
1750 | req->uint1 = flags; |
… | |
… | |
1507 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1753 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1508 | REQ_SEND; |
1754 | REQ_SEND; |
1509 | } |
1755 | } |
1510 | |
1756 | |
1511 | void |
1757 | void |
1512 | db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1758 | db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = 0) |
|
|
1759 | PREINIT: |
|
|
1760 | CALLBACK |
1513 | CODE: |
1761 | CODE: |
|
|
1762 | if (SvREADONLY (data)) |
|
|
1763 | croak ("can't modify read-only data scalar in db_pget"); |
1514 | { |
1764 | { |
1515 | dREQ (REQ_DB_PGET); |
1765 | dREQ (REQ_DB_PGET); |
1516 | req->db = db; |
1766 | req->db = db; |
1517 | req->txn = txn; |
1767 | req->txn = txn; |
1518 | req->uint1 = flags; |
1768 | req->uint1 = flags; |
… | |
… | |
1522 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1772 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1523 | REQ_SEND; |
1773 | REQ_SEND; |
1524 | } |
1774 | } |
1525 | |
1775 | |
1526 | void |
1776 | void |
1527 | db_del (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = &PL_sv_undef) |
1777 | db_del (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) |
|
|
1778 | PREINIT: |
|
|
1779 | CALLBACK |
1528 | CODE: |
1780 | CODE: |
1529 | { |
1781 | { |
1530 | dREQ (REQ_DB_DEL); |
1782 | dREQ (REQ_DB_DEL); |
1531 | req->db = db; |
1783 | req->db = db; |
1532 | req->txn = txn; |
1784 | req->txn = txn; |
… | |
… | |
1534 | sv_to_dbt (&req->dbt1, key); |
1786 | sv_to_dbt (&req->dbt1, key); |
1535 | REQ_SEND; |
1787 | REQ_SEND; |
1536 | } |
1788 | } |
1537 | |
1789 | |
1538 | void |
1790 | void |
1539 | db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = &PL_sv_undef) |
1791 | db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0) |
|
|
1792 | PREINIT: |
|
|
1793 | CALLBACK |
1540 | CODE: |
1794 | CODE: |
1541 | { |
1795 | { |
1542 | dREQ (REQ_TXN_COMMIT); |
1796 | dREQ (REQ_TXN_COMMIT); |
1543 | req->txn = txn; |
1797 | req->txn = txn; |
1544 | req->uint1 = flags; |
1798 | req->uint1 = flags; |
1545 | REQ_SEND; |
1799 | REQ_SEND; |
1546 | ptr_nuke (ST (0)); |
1800 | ptr_nuke (ST (0)); |
1547 | } |
1801 | } |
1548 | |
1802 | |
1549 | void |
1803 | void |
1550 | db_txn_abort (DB_TXN *txn, SV *callback = &PL_sv_undef) |
1804 | db_txn_abort (DB_TXN *txn, SV *callback = 0) |
|
|
1805 | PREINIT: |
|
|
1806 | CALLBACK |
1551 | CODE: |
1807 | CODE: |
1552 | { |
1808 | { |
1553 | dREQ (REQ_TXN_ABORT); |
1809 | dREQ (REQ_TXN_ABORT); |
1554 | req->txn = txn; |
1810 | req->txn = txn; |
1555 | REQ_SEND; |
1811 | REQ_SEND; |
1556 | ptr_nuke (ST (0)); |
1812 | ptr_nuke (ST (0)); |
1557 | } |
1813 | } |
1558 | |
1814 | |
1559 | void |
1815 | void |
1560 | db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = &PL_sv_undef) |
1816 | db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0) |
|
|
1817 | PREINIT: |
|
|
1818 | CALLBACK |
1561 | CODE: |
1819 | CODE: |
1562 | { |
1820 | { |
1563 | dREQ (REQ_TXN_FINISH); |
1821 | dREQ (REQ_TXN_FINISH); |
1564 | req->txn = txn; |
1822 | req->txn = txn; |
1565 | req->uint1 = flags; |
1823 | req->uint1 = flags; |
1566 | REQ_SEND; |
1824 | REQ_SEND; |
1567 | ptr_nuke (ST (0)); |
1825 | ptr_nuke (ST (0)); |
1568 | } |
1826 | } |
1569 | |
1827 | |
1570 | void |
1828 | void |
1571 | db_c_close (DBC *dbc, SV *callback = &PL_sv_undef) |
1829 | db_c_close (DBC *dbc, SV *callback = 0) |
|
|
1830 | PREINIT: |
|
|
1831 | CALLBACK |
1572 | CODE: |
1832 | CODE: |
1573 | { |
1833 | { |
1574 | dREQ (REQ_C_CLOSE); |
1834 | dREQ (REQ_C_CLOSE); |
1575 | req->dbc = dbc; |
1835 | req->dbc = dbc; |
1576 | REQ_SEND; |
1836 | REQ_SEND; |
1577 | ptr_nuke (ST (0)); |
1837 | ptr_nuke (ST (0)); |
1578 | } |
1838 | } |
1579 | |
1839 | |
1580 | void |
1840 | void |
1581 | db_c_count (DBC *dbc, SV *count, U32 flags = 0, SV *callback = &PL_sv_undef) |
1841 | db_c_count (DBC *dbc, SV *count, U32 flags = 0, SV *callback = 0) |
|
|
1842 | PREINIT: |
|
|
1843 | CALLBACK |
1582 | CODE: |
1844 | CODE: |
1583 | { |
1845 | { |
1584 | dREQ (REQ_C_COUNT); |
1846 | dREQ (REQ_C_COUNT); |
1585 | req->dbc = dbc; |
1847 | req->dbc = dbc; |
1586 | req->sv1 = SvREFCNT_inc (count); |
1848 | req->sv1 = SvREFCNT_inc (count); |
1587 | REQ_SEND; |
1849 | REQ_SEND; |
1588 | } |
1850 | } |
1589 | |
1851 | |
1590 | void |
1852 | void |
1591 | db_c_put (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1853 | db_c_put (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = 0) |
|
|
1854 | PREINIT: |
|
|
1855 | CALLBACK |
1592 | CODE: |
1856 | CODE: |
1593 | { |
1857 | { |
1594 | dREQ (REQ_C_PUT); |
1858 | dREQ (REQ_C_PUT); |
1595 | req->dbc = dbc; |
1859 | req->dbc = dbc; |
1596 | sv_to_dbt (&req->dbt1, key); |
1860 | sv_to_dbt (&req->dbt1, key); |
… | |
… | |
1598 | req->uint1 = flags; |
1862 | req->uint1 = flags; |
1599 | REQ_SEND; |
1863 | REQ_SEND; |
1600 | } |
1864 | } |
1601 | |
1865 | |
1602 | void |
1866 | void |
1603 | db_c_get (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1867 | db_c_get (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = 0) |
|
|
1868 | PREINIT: |
|
|
1869 | CALLBACK |
1604 | CODE: |
1870 | CODE: |
1605 | { |
1871 | { |
1606 | dREQ (REQ_C_GET); |
1872 | dREQ (REQ_C_GET); |
1607 | req->dbc = dbc; |
1873 | req->dbc = dbc; |
1608 | req->uint1 = flags; |
1874 | req->uint1 = flags; |
… | |
… | |
1623 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1889 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1624 | REQ_SEND; |
1890 | REQ_SEND; |
1625 | } |
1891 | } |
1626 | |
1892 | |
1627 | void |
1893 | void |
1628 | db_c_pget (DBC *dbc, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1894 | db_c_pget (DBC *dbc, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = 0) |
|
|
1895 | PREINIT: |
|
|
1896 | CALLBACK |
1629 | CODE: |
1897 | CODE: |
1630 | { |
1898 | { |
1631 | dREQ (REQ_C_PGET); |
1899 | dREQ (REQ_C_PGET); |
1632 | req->dbc = dbc; |
1900 | req->dbc = dbc; |
1633 | req->uint1 = flags; |
1901 | req->uint1 = flags; |
… | |
… | |
1651 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1919 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1652 | REQ_SEND; |
1920 | REQ_SEND; |
1653 | } |
1921 | } |
1654 | |
1922 | |
1655 | void |
1923 | void |
1656 | db_c_del (DBC *dbc, U32 flags = 0, SV *callback = &PL_sv_undef) |
1924 | db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0) |
|
|
1925 | PREINIT: |
|
|
1926 | CALLBACK |
1657 | CODE: |
1927 | CODE: |
1658 | { |
1928 | { |
1659 | dREQ (REQ_C_DEL); |
1929 | dREQ (REQ_C_DEL); |
1660 | req->dbc = dbc; |
1930 | req->dbc = dbc; |
1661 | req->uint1 = flags; |
1931 | req->uint1 = flags; |
1662 | REQ_SEND; |
1932 | REQ_SEND; |
1663 | } |
1933 | } |
1664 | |
1934 | |
1665 | |
1935 | |
|
|
1936 | #if DB_VERSION_MINOR >= 3 |
|
|
1937 | |
1666 | void |
1938 | void |
1667 | db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = &PL_sv_undef) |
1939 | db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0) |
|
|
1940 | PREINIT: |
|
|
1941 | CALLBACK |
1668 | CODE: |
1942 | CODE: |
1669 | { |
1943 | { |
1670 | dREQ (REQ_SEQ_OPEN); |
1944 | dREQ (REQ_SEQ_OPEN); |
1671 | req->seq = seq; |
1945 | req->seq = seq; |
1672 | req->txn = txnid; |
1946 | req->txn = txnid; |
… | |
… | |
1674 | sv_to_dbt (&req->dbt1, key); |
1948 | sv_to_dbt (&req->dbt1, key); |
1675 | REQ_SEND; |
1949 | REQ_SEND; |
1676 | } |
1950 | } |
1677 | |
1951 | |
1678 | void |
1952 | void |
1679 | db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = &PL_sv_undef) |
1953 | db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0) |
|
|
1954 | PREINIT: |
|
|
1955 | CALLBACK |
1680 | CODE: |
1956 | CODE: |
1681 | { |
1957 | { |
1682 | dREQ (REQ_SEQ_CLOSE); |
1958 | dREQ (REQ_SEQ_CLOSE); |
1683 | req->seq = seq; |
1959 | req->seq = seq; |
1684 | req->uint1 = flags; |
1960 | req->uint1 = flags; |
1685 | REQ_SEND; |
1961 | REQ_SEND; |
1686 | ptr_nuke (ST (0)); |
1962 | ptr_nuke (ST (0)); |
1687 | } |
1963 | } |
1688 | |
1964 | |
1689 | void |
1965 | void |
1690 | db_sequence_get (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, int delta, SV *seq_value, U32 flags = DB_TXN_NOSYNC, SV *callback = &PL_sv_undef) |
1966 | db_sequence_get (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, int delta, SV *seq_value, U32 flags = DB_TXN_NOSYNC, SV *callback = 0) |
|
|
1967 | PREINIT: |
|
|
1968 | CALLBACK |
1691 | CODE: |
1969 | CODE: |
1692 | { |
1970 | { |
1693 | dREQ (REQ_SEQ_GET); |
1971 | dREQ (REQ_SEQ_GET); |
1694 | req->seq = seq; |
1972 | req->seq = seq; |
1695 | req->txn = txnid; |
1973 | req->txn = txnid; |
… | |
… | |
1698 | req->sv1 = SvREFCNT_inc (seq_value); SvREADONLY_on (seq_value); |
1976 | req->sv1 = SvREFCNT_inc (seq_value); SvREADONLY_on (seq_value); |
1699 | REQ_SEND; |
1977 | REQ_SEND; |
1700 | } |
1978 | } |
1701 | |
1979 | |
1702 | void |
1980 | void |
1703 | db_sequence_remove (DB_SEQUENCE *seq, DB_TXN_ornull *txnid = 0, U32 flags = 0, SV *callback = &PL_sv_undef) |
1981 | db_sequence_remove (DB_SEQUENCE *seq, DB_TXN_ornull *txnid = 0, U32 flags = 0, SV *callback = 0) |
|
|
1982 | PREINIT: |
|
|
1983 | CALLBACK |
1704 | CODE: |
1984 | CODE: |
1705 | { |
1985 | { |
1706 | dREQ (REQ_SEQ_REMOVE); |
1986 | dREQ (REQ_SEQ_REMOVE); |
1707 | req->seq = seq; |
1987 | req->seq = seq; |
1708 | req->txn = txnid; |
1988 | req->txn = txnid; |
1709 | req->uint1 = flags; |
1989 | req->uint1 = flags; |
1710 | REQ_SEND; |
1990 | REQ_SEND; |
1711 | } |
1991 | } |
1712 | |
1992 | |
|
|
1993 | #endif |
|
|
1994 | |
1713 | |
1995 | |
1714 | MODULE = BDB PACKAGE = BDB::Env |
1996 | MODULE = BDB PACKAGE = BDB::Env |
1715 | |
1997 | |
1716 | void |
1998 | void |
1717 | DESTROY (DB_ENV_ornull *env) |
1999 | DESTROY (DB_ENV_ornuked *env) |
1718 | CODE: |
2000 | CODE: |
1719 | if (env) |
2001 | if (env) |
1720 | env->close (env, 0); |
2002 | env->close (env, 0); |
1721 | |
2003 | |
1722 | int set_data_dir (DB_ENV *env, const char *dir) |
2004 | int set_data_dir (DB_ENV *env, const char *dir) |
… | |
… | |
1753 | CODE: |
2035 | CODE: |
1754 | RETVAL = env->set_flags (env, flags, onoff); |
2036 | RETVAL = env->set_flags (env, flags, onoff); |
1755 | OUTPUT: |
2037 | OUTPUT: |
1756 | RETVAL |
2038 | RETVAL |
1757 | |
2039 | |
|
|
2040 | #if DB_VERSION_MINOR >= 7 |
|
|
2041 | |
|
|
2042 | int set_intermediate_dir_mode (DB_ENV *env, const char *mode) |
|
|
2043 | CODE: |
|
|
2044 | RETVAL = env->set_intermediate_dir_mode (env, mode); |
|
|
2045 | OUTPUT: |
|
|
2046 | RETVAL |
|
|
2047 | |
|
|
2048 | int log_set_config (DB_ENV *env, U32 flags, int onoff = 1) |
|
|
2049 | CODE: |
|
|
2050 | RETVAL = env->log_set_config (env, flags, onoff); |
|
|
2051 | OUTPUT: |
|
|
2052 | RETVAL |
|
|
2053 | |
|
|
2054 | #endif |
|
|
2055 | |
|
|
2056 | |
1758 | void set_errfile (DB_ENV *env, FILE *errfile = 0) |
2057 | void set_errfile (DB_ENV *env, FILE *errfile = 0) |
1759 | CODE: |
2058 | CODE: |
1760 | env->set_errfile (env, errfile); |
2059 | env->set_errfile (env, errfile); |
1761 | |
2060 | |
1762 | void set_msgfile (DB_ENV *env, FILE *msgfile = 0) |
2061 | void set_msgfile (DB_ENV *env, FILE *msgfile = 0) |
… | |
… | |
1832 | int set_lg_max (DB_ENV *env, U32 max) |
2131 | int set_lg_max (DB_ENV *env, U32 max) |
1833 | CODE: |
2132 | CODE: |
1834 | RETVAL = env->set_lg_max (env, max); |
2133 | RETVAL = env->set_lg_max (env, max); |
1835 | OUTPUT: |
2134 | OUTPUT: |
1836 | RETVAL |
2135 | RETVAL |
|
|
2136 | |
|
|
2137 | #if DB_VERSION_MINOR >= 4 |
1837 | |
2138 | |
1838 | int mutex_set_max (DB_ENV *env, U32 max) |
2139 | int mutex_set_max (DB_ENV *env, U32 max) |
1839 | CODE: |
2140 | CODE: |
1840 | RETVAL = env->mutex_set_max (env, max); |
2141 | RETVAL = env->mutex_set_max (env, max); |
1841 | OUTPUT: |
2142 | OUTPUT: |
… | |
… | |
1857 | CODE: |
2158 | CODE: |
1858 | RETVAL = env->mutex_set_align (env, align); |
2159 | RETVAL = env->mutex_set_align (env, align); |
1859 | OUTPUT: |
2160 | OUTPUT: |
1860 | RETVAL |
2161 | RETVAL |
1861 | |
2162 | |
|
|
2163 | #endif |
|
|
2164 | |
1862 | DB_TXN * |
2165 | DB_TXN * |
1863 | txn_begin (DB_ENV *env, DB_TXN_ornull *parent = 0, U32 flags = 0) |
2166 | txn_begin (DB_ENV *env, DB_TXN_ornull *parent = 0, U32 flags = 0) |
1864 | CODE: |
2167 | CODE: |
1865 | errno = env->txn_begin (env, parent, &RETVAL, flags); |
2168 | errno = env->txn_begin (env, parent, &RETVAL, flags); |
1866 | if (errno) |
2169 | if (errno) |
1867 | croak ("DB_ENV->txn_begin: %s", db_strerror (errno)); |
2170 | croak ("DB_ENV->txn_begin: %s", db_strerror (errno)); |
1868 | OUTPUT: |
2171 | OUTPUT: |
1869 | RETVAL |
2172 | RETVAL |
1870 | |
2173 | |
|
|
2174 | #if DB_VERSION_MINOR >= 5 |
|
|
2175 | |
|
|
2176 | DB_TXN * |
|
|
2177 | cdsgroup_begin (DB_ENV *env) |
|
|
2178 | CODE: |
|
|
2179 | errno = env->cdsgroup_begin (env, &RETVAL); |
|
|
2180 | if (errno) |
|
|
2181 | croak ("DB_ENV->cdsgroup_begin: %s", db_strerror (errno)); |
|
|
2182 | OUTPUT: |
|
|
2183 | RETVAL |
|
|
2184 | |
|
|
2185 | #endif |
|
|
2186 | |
1871 | MODULE = BDB PACKAGE = BDB::Db |
2187 | MODULE = BDB PACKAGE = BDB::Db |
1872 | |
2188 | |
1873 | void |
2189 | void |
1874 | DESTROY (DB_ornull *db) |
2190 | DESTROY (DB_ornuked *db) |
1875 | CODE: |
2191 | CODE: |
1876 | if (db) |
2192 | if (db) |
1877 | { |
2193 | { |
1878 | SV *env = (SV *)db->app_private; |
2194 | SV *env = (SV *)db->app_private; |
1879 | db->close (db, 0); |
2195 | db->close (db, 0); |
… | |
… | |
1959 | if (errno) |
2275 | if (errno) |
1960 | croak ("DB->cursor: %s", db_strerror (errno)); |
2276 | croak ("DB->cursor: %s", db_strerror (errno)); |
1961 | OUTPUT: |
2277 | OUTPUT: |
1962 | RETVAL |
2278 | RETVAL |
1963 | |
2279 | |
|
|
2280 | #if DB_VERSION_MINOR >= 3 |
|
|
2281 | |
1964 | DB_SEQUENCE * |
2282 | DB_SEQUENCE * |
1965 | sequence (DB *db, U32 flags = 0) |
2283 | sequence (DB *db, U32 flags = 0) |
1966 | CODE: |
2284 | CODE: |
1967 | { |
2285 | { |
1968 | errno = db_sequence_create (&RETVAL, db, flags); |
2286 | errno = db_sequence_create (&RETVAL, db, flags); |
… | |
… | |
1970 | croak ("db_sequence_create: %s", db_strerror (errno)); |
2288 | croak ("db_sequence_create: %s", db_strerror (errno)); |
1971 | } |
2289 | } |
1972 | OUTPUT: |
2290 | OUTPUT: |
1973 | RETVAL |
2291 | RETVAL |
1974 | |
2292 | |
|
|
2293 | #endif |
|
|
2294 | |
1975 | |
2295 | |
1976 | MODULE = BDB PACKAGE = BDB::Txn |
2296 | MODULE = BDB PACKAGE = BDB::Txn |
1977 | |
2297 | |
1978 | void |
2298 | void |
1979 | DESTROY (DB_TXN_ornull *txn) |
2299 | DESTROY (DB_TXN_ornuked *txn) |
1980 | CODE: |
2300 | CODE: |
1981 | if (txn) |
2301 | if (txn) |
1982 | txn->abort (txn); |
2302 | txn->abort (txn); |
1983 | |
2303 | |
1984 | int set_timeout (DB_TXN *txn, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT) |
2304 | int set_timeout (DB_TXN *txn, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT) |
… | |
… | |
1995 | |
2315 | |
1996 | |
2316 | |
1997 | MODULE = BDB PACKAGE = BDB::Cursor |
2317 | MODULE = BDB PACKAGE = BDB::Cursor |
1998 | |
2318 | |
1999 | void |
2319 | void |
2000 | DESTROY (DBC_ornull *dbc) |
2320 | DESTROY (DBC_ornuked *dbc) |
2001 | CODE: |
2321 | CODE: |
2002 | if (dbc) |
2322 | if (dbc) |
2003 | dbc->c_close (dbc); |
2323 | dbc->c_close (dbc); |
2004 | |
2324 | |
|
|
2325 | #if DB_VERSION_MINOR >= 6 |
|
|
2326 | |
|
|
2327 | int set_priority (DBC *dbc, int priority) |
|
|
2328 | CODE: |
|
|
2329 | dbc->set_priority (dbc, priority); |
|
|
2330 | |
|
|
2331 | #endif |
|
|
2332 | |
|
|
2333 | #if DB_VERSION_MINOR >= 3 |
|
|
2334 | |
2005 | MODULE = BDB PACKAGE = BDB::Sequence |
2335 | MODULE = BDB PACKAGE = BDB::Sequence |
2006 | |
2336 | |
2007 | void |
2337 | void |
2008 | DESTROY (DB_SEQUENCE_ornull *seq) |
2338 | DESTROY (DB_SEQUENCE_ornuked *seq) |
2009 | CODE: |
2339 | CODE: |
2010 | if (seq) |
2340 | if (seq) |
2011 | seq->close (seq, 0); |
2341 | seq->close (seq, 0); |
2012 | |
2342 | |
2013 | int initial_value (DB_SEQUENCE *seq, db_seq_t value) |
2343 | int initial_value (DB_SEQUENCE *seq, db_seq_t value) |
… | |
… | |
2032 | CODE: |
2362 | CODE: |
2033 | RETVAL = seq->set_range (seq, min, max); |
2363 | RETVAL = seq->set_range (seq, min, max); |
2034 | OUTPUT: |
2364 | OUTPUT: |
2035 | RETVAL |
2365 | RETVAL |
2036 | |
2366 | |
|
|
2367 | #endif |
|
|
2368 | |
|
|
2369 | |