… | |
… | |
40 | typedef DB_TXN DB_TXN_ornull; |
40 | typedef DB_TXN DB_TXN_ornull; |
41 | typedef DBC DBC_ornull; |
41 | typedef DBC DBC_ornull; |
42 | typedef DB DB_ornull; |
42 | typedef DB DB_ornull; |
43 | typedef DB_SEQUENCE DB_SEQUENCE_ornull; |
43 | typedef DB_SEQUENCE DB_SEQUENCE_ornull; |
44 | |
44 | |
|
|
45 | typedef DB_ENV DB_ENV_ornuked; |
|
|
46 | typedef DB_TXN DB_TXN_ornuked; |
|
|
47 | typedef DBC DBC_ornuked; |
|
|
48 | typedef DB DB_ornuked; |
|
|
49 | typedef DB_SEQUENCE DB_SEQUENCE_ornuked; |
|
|
50 | |
45 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
51 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
46 | typedef char *octetstring; |
52 | typedef char *bdb_filename; |
47 | |
53 | |
48 | static SV *prepare_cb; |
54 | static SV *prepare_cb; |
|
|
55 | |
|
|
56 | #if DB_VERSION_MINOR >= 6 |
|
|
57 | # define c_close close |
|
|
58 | # define c_count count |
|
|
59 | # define c_del del |
|
|
60 | # define c_dup dup |
|
|
61 | # define c_get get |
|
|
62 | # define c_pget pget |
|
|
63 | # define c_put put |
|
|
64 | #endif |
|
|
65 | |
|
|
66 | static char * |
|
|
67 | get_bdb_filename (SV *sv) |
|
|
68 | { |
|
|
69 | if (!SvOK (sv)) |
|
|
70 | return 0; |
|
|
71 | |
|
|
72 | #if _WIN32 |
|
|
73 | /* win32 madness + win32 perl absolutely brokenness make for horrible hacks */ |
|
|
74 | { |
|
|
75 | STRLEN len; |
|
|
76 | char *src = SvPVbyte (sv, len); |
|
|
77 | SV *t1 = sv_newmortal (); |
|
|
78 | SV *t2 = sv_newmortal (); |
|
|
79 | |
|
|
80 | sv_upgrade (t1, SVt_PV); SvPOK_only (t1); SvGROW (t1, len * 16 + 1); |
|
|
81 | sv_upgrade (t2, SVt_PV); SvPOK_only (t2); SvGROW (t2, len * 16 + 1); |
|
|
82 | |
|
|
83 | len = MultiByteToWideChar (CP_ACP, 0, src, len, (WCHAR *)SvPVX (t1), SvLEN (t1) / sizeof (WCHAR)); |
|
|
84 | len = WideCharToMultiByte (CP_UTF8, 0, (WCHAR *)SvPVX (t1), len, SvPVX (t2), SvLEN (t2), 0, 0); |
|
|
85 | SvPOK_only (t2); |
|
|
86 | SvPVX (t2)[len] = 0; |
|
|
87 | SvCUR_set (t2, len); |
|
|
88 | |
|
|
89 | return SvPVX (t2); |
|
|
90 | } |
|
|
91 | #else |
|
|
92 | return SvPVbyte_nolen (sv); |
|
|
93 | #endif |
|
|
94 | } |
49 | |
95 | |
50 | static void |
96 | static void |
51 | debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg) |
97 | debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg) |
52 | { |
98 | { |
53 | printf ("err[%s]\n", msg); |
99 | printf ("err[%s]\n", msg); |
… | |
… | |
92 | |
138 | |
93 | enum { |
139 | enum { |
94 | REQ_QUIT, |
140 | REQ_QUIT, |
95 | REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, |
141 | REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, |
96 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, |
142 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, |
97 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, |
143 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE, |
98 | REQ_DB_PUT, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, |
144 | REQ_DB_PUT, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, |
99 | REQ_TXN_COMMIT, REQ_TXN_ABORT, |
145 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
100 | REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, |
146 | REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, |
101 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
147 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
102 | }; |
148 | }; |
103 | |
149 | |
104 | typedef struct aio_cb |
150 | typedef struct bdb_cb |
105 | { |
151 | { |
106 | struct aio_cb *volatile next; |
152 | struct bdb_cb *volatile next; |
107 | SV *callback; |
153 | SV *callback; |
108 | int type, pri, result; |
154 | int type, pri, result; |
109 | |
155 | |
110 | DB_ENV *env; |
156 | DB_ENV *env; |
111 | DB *db; |
157 | DB *db; |
… | |
… | |
120 | |
166 | |
121 | DBT dbt1, dbt2, dbt3; |
167 | DBT dbt1, dbt2, dbt3; |
122 | DB_KEY_RANGE key_range; |
168 | DB_KEY_RANGE key_range; |
123 | DB_SEQUENCE *seq; |
169 | DB_SEQUENCE *seq; |
124 | db_seq_t seq_t; |
170 | db_seq_t seq_t; |
125 | } aio_cb; |
171 | } bdb_cb; |
126 | |
172 | |
127 | typedef aio_cb *aio_req; |
173 | typedef bdb_cb *bdb_req; |
128 | |
174 | |
129 | enum { |
175 | enum { |
130 | PRI_MIN = -4, |
176 | PRI_MIN = -4, |
131 | PRI_MAX = 4, |
177 | PRI_MAX = 4, |
132 | |
178 | |
… | |
… | |
135 | NUM_PRI = PRI_MAX + PRI_BIAS + 1, |
181 | NUM_PRI = PRI_MAX + PRI_BIAS + 1, |
136 | }; |
182 | }; |
137 | |
183 | |
138 | #define AIO_TICKS ((1000000 + 1023) >> 10) |
184 | #define AIO_TICKS ((1000000 + 1023) >> 10) |
139 | |
185 | |
|
|
186 | static SV *on_next_submit; |
|
|
187 | |
140 | static unsigned int max_poll_time = 0; |
188 | static unsigned int max_poll_time = 0; |
141 | static unsigned int max_poll_reqs = 0; |
189 | static unsigned int max_poll_reqs = 0; |
142 | |
190 | |
143 | /* calculcate time difference in ~1/AIO_TICKS of a second */ |
191 | /* calculcate time difference in ~1/AIO_TICKS of a second */ |
144 | static int tvdiff (struct timeval *tv1, struct timeval *tv2) |
192 | static int tvdiff (struct timeval *tv1, struct timeval *tv2) |
… | |
… | |
159 | struct worker *prev, *next; |
207 | struct worker *prev, *next; |
160 | |
208 | |
161 | thread_t tid; |
209 | thread_t tid; |
162 | |
210 | |
163 | /* locked by reslock, reqlock or wrklock */ |
211 | /* locked by reslock, reqlock or wrklock */ |
164 | aio_req req; /* currently processed request */ |
212 | bdb_req req; /* currently processed request */ |
165 | void *dbuf; |
213 | void *dbuf; |
166 | DIR *dirp; |
214 | DIR *dirp; |
167 | } worker; |
215 | } worker; |
168 | |
216 | |
169 | static worker wrk_first = { &wrk_first, &wrk_first, 0 }; |
217 | static worker wrk_first = { &wrk_first, &wrk_first, 0 }; |
… | |
… | |
181 | } |
229 | } |
182 | |
230 | |
183 | static volatile unsigned int nreqs, nready, npending; |
231 | static volatile unsigned int nreqs, nready, npending; |
184 | static volatile unsigned int max_idle = 4; |
232 | static volatile unsigned int max_idle = 4; |
185 | static volatile unsigned int max_outstanding = 0xffffffff; |
233 | static volatile unsigned int max_outstanding = 0xffffffff; |
186 | static int respipe [2], respipe_osf [2]; |
234 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
187 | |
235 | |
188 | static mutex_t reslock = X_MUTEX_INIT; |
236 | static mutex_t reslock = X_MUTEX_INIT; |
189 | static mutex_t reqlock = X_MUTEX_INIT; |
237 | static mutex_t reqlock = X_MUTEX_INIT; |
190 | static cond_t reqwait = X_COND_INIT; |
238 | static cond_t reqwait = X_COND_INIT; |
191 | |
239 | |
192 | #if WORDACCESS_UNSAFE |
240 | #if WORDACCESS_UNSAFE |
193 | |
241 | |
194 | static unsigned int get_nready () |
242 | static unsigned int get_nready (void) |
195 | { |
243 | { |
196 | unsigned int retval; |
244 | unsigned int retval; |
197 | |
245 | |
198 | X_LOCK (reqlock); |
246 | X_LOCK (reqlock); |
199 | retval = nready; |
247 | retval = nready; |
200 | X_UNLOCK (reqlock); |
248 | X_UNLOCK (reqlock); |
201 | |
249 | |
202 | return retval; |
250 | return retval; |
203 | } |
251 | } |
204 | |
252 | |
205 | static unsigned int get_npending () |
253 | static unsigned int get_npending (void) |
206 | { |
254 | { |
207 | unsigned int retval; |
255 | unsigned int retval; |
208 | |
256 | |
209 | X_LOCK (reslock); |
257 | X_LOCK (reslock); |
210 | retval = npending; |
258 | retval = npending; |
211 | X_UNLOCK (reslock); |
259 | X_UNLOCK (reslock); |
212 | |
260 | |
213 | return retval; |
261 | return retval; |
214 | } |
262 | } |
215 | |
263 | |
216 | static unsigned int get_nthreads () |
264 | static unsigned int get_nthreads (void) |
217 | { |
265 | { |
218 | unsigned int retval; |
266 | unsigned int retval; |
219 | |
267 | |
220 | X_LOCK (wrklock); |
268 | X_LOCK (wrklock); |
221 | retval = started; |
269 | retval = started; |
… | |
… | |
236 | * a somewhat faster data structure might be nice, but |
284 | * a somewhat faster data structure might be nice, but |
237 | * with 8 priorities this actually needs <20 insns |
285 | * with 8 priorities this actually needs <20 insns |
238 | * per shift, the most expensive operation. |
286 | * per shift, the most expensive operation. |
239 | */ |
287 | */ |
240 | typedef struct { |
288 | typedef struct { |
241 | aio_req qs[NUM_PRI], qe[NUM_PRI]; /* qstart, qend */ |
289 | bdb_req qs[NUM_PRI], qe[NUM_PRI]; /* qstart, qend */ |
242 | int size; |
290 | int size; |
243 | } reqq; |
291 | } reqq; |
244 | |
292 | |
245 | static reqq req_queue; |
293 | static reqq req_queue; |
246 | static reqq res_queue; |
294 | static reqq res_queue; |
247 | |
295 | |
248 | int reqq_push (reqq *q, aio_req req) |
296 | int reqq_push (reqq *q, bdb_req req) |
249 | { |
297 | { |
250 | int pri = req->pri; |
298 | int pri = req->pri; |
251 | req->next = 0; |
299 | req->next = 0; |
252 | |
300 | |
253 | if (q->qe[pri]) |
301 | if (q->qe[pri]) |
… | |
… | |
259 | q->qe[pri] = q->qs[pri] = req; |
307 | q->qe[pri] = q->qs[pri] = req; |
260 | |
308 | |
261 | return q->size++; |
309 | return q->size++; |
262 | } |
310 | } |
263 | |
311 | |
264 | aio_req reqq_shift (reqq *q) |
312 | bdb_req reqq_shift (reqq *q) |
265 | { |
313 | { |
266 | int pri; |
314 | int pri; |
267 | |
315 | |
268 | if (!q->size) |
316 | if (!q->size) |
269 | return 0; |
317 | return 0; |
270 | |
318 | |
271 | --q->size; |
319 | --q->size; |
272 | |
320 | |
273 | for (pri = NUM_PRI; pri--; ) |
321 | for (pri = NUM_PRI; pri--; ) |
274 | { |
322 | { |
275 | aio_req req = q->qs[pri]; |
323 | bdb_req req = q->qs[pri]; |
276 | |
324 | |
277 | if (req) |
325 | if (req) |
278 | { |
326 | { |
279 | if (!(q->qs[pri] = req->next)) |
327 | if (!(q->qs[pri] = req->next)) |
280 | q->qe[pri] = 0; |
328 | q->qe[pri] = 0; |
… | |
… | |
284 | } |
332 | } |
285 | |
333 | |
286 | abort (); |
334 | abort (); |
287 | } |
335 | } |
288 | |
336 | |
289 | static int poll_cb (); |
337 | static int poll_cb (void); |
290 | static void req_free (aio_req req); |
338 | static void req_free (bdb_req req); |
291 | static void req_cancel (aio_req req); |
339 | static void req_cancel (bdb_req req); |
292 | |
340 | |
293 | static int req_invoke (aio_req req) |
341 | static int req_invoke (bdb_req req) |
294 | { |
342 | { |
295 | dSP; |
343 | dSP; |
296 | |
344 | |
297 | if (SvOK (req->callback)) |
345 | if (SvOK (req->callback)) |
298 | { |
346 | { |
… | |
… | |
316 | dbt_to_sv (req->sv1, &req->dbt1); |
364 | dbt_to_sv (req->sv1, &req->dbt1); |
317 | dbt_to_sv (req->sv2, &req->dbt2); |
365 | dbt_to_sv (req->sv2, &req->dbt2); |
318 | dbt_to_sv (req->sv3, &req->dbt3); |
366 | dbt_to_sv (req->sv3, &req->dbt3); |
319 | break; |
367 | break; |
320 | |
368 | |
|
|
369 | case REQ_DB_PUT: |
|
|
370 | case REQ_C_PUT: |
|
|
371 | dbt_to_sv (0, &req->dbt1); |
|
|
372 | dbt_to_sv (0, &req->dbt2); |
|
|
373 | break; |
|
|
374 | |
321 | case REQ_DB_KEY_RANGE: |
375 | case REQ_DB_KEY_RANGE: |
322 | { |
376 | { |
323 | AV *av = newAV (); |
377 | AV *av = newAV (); |
324 | |
378 | |
325 | av_push (av, newSVnv (req->key_range.less)); |
379 | av_push (av, newSVnv (req->key_range.less)); |
… | |
… | |
334 | |
388 | |
335 | case REQ_SEQ_GET: |
389 | case REQ_SEQ_GET: |
336 | SvREADONLY_off (req->sv1); |
390 | SvREADONLY_off (req->sv1); |
337 | |
391 | |
338 | if (sizeof (IV) > 4) |
392 | if (sizeof (IV) > 4) |
339 | sv_setiv_mg (req->sv1, req->seq_t); |
393 | sv_setiv_mg (req->sv1, (IV)req->seq_t); |
340 | else |
394 | else |
341 | sv_setnv_mg (req->sv1, req->seq_t); |
395 | sv_setnv_mg (req->sv1, (NV)req->seq_t); |
342 | |
396 | |
343 | SvREFCNT_dec (req->sv1); |
397 | SvREFCNT_dec (req->sv1); |
344 | break; |
398 | break; |
345 | } |
399 | } |
346 | |
400 | |
… | |
… | |
355 | } |
409 | } |
356 | |
410 | |
357 | return !SvTRUE (ERRSV); |
411 | return !SvTRUE (ERRSV); |
358 | } |
412 | } |
359 | |
413 | |
360 | static void req_free (aio_req req) |
414 | static void req_free (bdb_req req) |
361 | { |
415 | { |
362 | free (req->buf1); |
416 | free (req->buf1); |
363 | free (req->buf2); |
417 | free (req->buf2); |
364 | Safefree (req); |
418 | Safefree (req); |
365 | } |
419 | } |
… | |
… | |
369 | #else |
423 | #else |
370 | # define TO_SOCKET(x) (x) |
424 | # define TO_SOCKET(x) (x) |
371 | #endif |
425 | #endif |
372 | |
426 | |
373 | static void |
427 | static void |
374 | create_pipe (int fd[2]) |
428 | create_respipe (void) |
375 | { |
429 | { |
376 | #ifdef _WIN32 |
430 | #ifdef _WIN32 |
377 | int arg = 1; |
431 | int arg; /* argg */ |
|
|
432 | #endif |
|
|
433 | int old_readfd = respipe [0]; |
|
|
434 | |
|
|
435 | if (respipe [1] >= 0) |
|
|
436 | respipe_close (TO_SOCKET (respipe [1])); |
|
|
437 | |
|
|
438 | #ifdef _WIN32 |
378 | if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, fd) |
439 | if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe)) |
379 | || ioctlsocket (TO_SOCKET (fd [0]), FIONBIO, &arg) |
|
|
380 | || ioctlsocket (TO_SOCKET (fd [1]), FIONBIO, &arg)) |
|
|
381 | #else |
440 | #else |
382 | if (pipe (fd) |
441 | if (pipe (respipe)) |
383 | || fcntl (fd [0], F_SETFL, O_NONBLOCK) |
|
|
384 | || fcntl (fd [1], F_SETFL, O_NONBLOCK)) |
|
|
385 | #endif |
442 | #endif |
386 | croak ("unable to initialize result pipe"); |
443 | croak ("unable to initialize result pipe"); |
|
|
444 | |
|
|
445 | if (old_readfd >= 0) |
|
|
446 | { |
|
|
447 | if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) |
|
|
448 | croak ("unable to initialize result pipe(2)"); |
|
|
449 | |
|
|
450 | respipe_close (respipe [0]); |
|
|
451 | respipe [0] = old_readfd; |
|
|
452 | } |
|
|
453 | |
|
|
454 | #ifdef _WIN32 |
|
|
455 | arg = 1; |
|
|
456 | if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) |
|
|
457 | || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) |
|
|
458 | #else |
|
|
459 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) |
|
|
460 | || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
461 | #endif |
|
|
462 | croak ("unable to initialize result pipe(3)"); |
387 | |
463 | |
388 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
464 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
389 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
465 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
390 | } |
466 | } |
391 | |
467 | |
… | |
… | |
411 | free (wrk); |
487 | free (wrk); |
412 | |
488 | |
413 | X_UNLOCK (wrklock); |
489 | X_UNLOCK (wrklock); |
414 | } |
490 | } |
415 | |
491 | |
416 | static void maybe_start_thread () |
492 | static void maybe_start_thread (void) |
417 | { |
493 | { |
418 | if (get_nthreads () >= wanted) |
494 | if (get_nthreads () >= wanted) |
419 | return; |
495 | return; |
420 | |
496 | |
421 | /* todo: maybe use idle here, but might be less exact */ |
497 | /* todo: maybe use idle here, but might be less exact */ |
… | |
… | |
423 | return; |
499 | return; |
424 | |
500 | |
425 | start_thread (); |
501 | start_thread (); |
426 | } |
502 | } |
427 | |
503 | |
428 | static void req_send (aio_req req) |
504 | static void req_send (bdb_req req) |
429 | { |
505 | { |
430 | SV *wait_callback = 0; |
506 | SV *wait_callback = 0; |
|
|
507 | |
|
|
508 | if (on_next_submit) |
|
|
509 | { |
|
|
510 | dSP; |
|
|
511 | SV *cb = sv_2mortal (on_next_submit); |
|
|
512 | |
|
|
513 | on_next_submit = 0; |
|
|
514 | |
|
|
515 | PUSHMARK (SP); |
|
|
516 | PUTBACK; |
|
|
517 | call_sv (cb, G_DISCARD | G_EVAL); |
|
|
518 | } |
431 | |
519 | |
432 | // synthesize callback if none given |
520 | // synthesize callback if none given |
433 | if (!SvOK (req->callback)) |
521 | if (!SvOK (req->callback)) |
434 | { |
522 | { |
435 | int count; |
523 | int count; |
… | |
… | |
441 | SPAGAIN; |
529 | SPAGAIN; |
442 | |
530 | |
443 | if (count != 2) |
531 | if (count != 2) |
444 | croak ("prepare callback must return exactly two values\n"); |
532 | croak ("prepare callback must return exactly two values\n"); |
445 | |
533 | |
446 | wait_callback = SvREFCNT_inc (POPs); |
534 | wait_callback = POPs; |
447 | SvREFCNT_dec (req->callback); |
535 | SvREFCNT_dec (req->callback); |
448 | req->callback = SvREFCNT_inc (POPs); |
536 | req->callback = SvREFCNT_inc (POPs); |
449 | } |
537 | } |
450 | |
538 | |
451 | ++nreqs; |
539 | ++nreqs; |
… | |
… | |
462 | { |
550 | { |
463 | dSP; |
551 | dSP; |
464 | PUSHMARK (SP); |
552 | PUSHMARK (SP); |
465 | PUTBACK; |
553 | PUTBACK; |
466 | call_sv (wait_callback, G_DISCARD); |
554 | call_sv (wait_callback, G_DISCARD); |
467 | SvREFCNT_dec (wait_callback); |
|
|
468 | } |
555 | } |
469 | } |
556 | } |
470 | |
557 | |
471 | static void end_thread (void) |
558 | static void end_thread (void) |
472 | { |
559 | { |
473 | aio_req req; |
560 | bdb_req req; |
474 | |
561 | |
475 | Newz (0, req, 1, aio_cb); |
562 | Newz (0, req, 1, bdb_cb); |
476 | |
563 | |
477 | req->type = REQ_QUIT; |
564 | req->type = REQ_QUIT; |
478 | req->pri = PRI_MAX + PRI_BIAS; |
565 | req->pri = PRI_MAX + PRI_BIAS; |
479 | |
566 | |
480 | X_LOCK (reqlock); |
567 | X_LOCK (reqlock); |
… | |
… | |
507 | |
594 | |
508 | while (started > wanted) |
595 | while (started > wanted) |
509 | end_thread (); |
596 | end_thread (); |
510 | } |
597 | } |
511 | |
598 | |
512 | static void poll_wait () |
599 | static void poll_wait (void) |
513 | { |
600 | { |
514 | fd_set rfd; |
601 | fd_set rfd; |
515 | |
602 | |
516 | while (nreqs) |
603 | while (nreqs) |
517 | { |
604 | { |
… | |
… | |
530 | |
617 | |
531 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
618 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
532 | } |
619 | } |
533 | } |
620 | } |
534 | |
621 | |
535 | static int poll_cb () |
622 | static int poll_cb (void) |
536 | { |
623 | { |
537 | dSP; |
624 | dSP; |
538 | int count = 0; |
625 | int count = 0; |
539 | int maxreqs = max_poll_reqs; |
626 | int maxreqs = max_poll_reqs; |
540 | int do_croak = 0; |
627 | int do_croak = 0; |
541 | struct timeval tv_start, tv_now; |
628 | struct timeval tv_start, tv_now; |
542 | aio_req req; |
629 | bdb_req req; |
543 | |
630 | |
544 | if (max_poll_time) |
631 | if (max_poll_time) |
545 | gettimeofday (&tv_start, 0); |
632 | gettimeofday (&tv_start, 0); |
546 | |
633 | |
547 | for (;;) |
634 | for (;;) |
… | |
… | |
608 | |
695 | |
609 | /*****************************************************************************/ |
696 | /*****************************************************************************/ |
610 | |
697 | |
611 | X_THREAD_PROC (bdb_proc) |
698 | X_THREAD_PROC (bdb_proc) |
612 | { |
699 | { |
613 | aio_req req; |
700 | bdb_req req; |
614 | struct timespec ts; |
701 | struct timespec ts; |
615 | worker *self = (worker *)thr_arg; |
702 | worker *self = (worker *)thr_arg; |
616 | |
703 | |
617 | /* try to distribute timeouts somewhat evenly */ |
704 | /* try to distribute timeouts somewhat evenly */ |
618 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
705 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
… | |
… | |
658 | X_UNLOCK (reqlock); |
745 | X_UNLOCK (reqlock); |
659 | |
746 | |
660 | switch (req->type) |
747 | switch (req->type) |
661 | { |
748 | { |
662 | case REQ_QUIT: |
749 | case REQ_QUIT: |
|
|
750 | req->result = ENOSYS; |
663 | goto quit; |
751 | goto quit; |
664 | |
752 | |
665 | case REQ_ENV_OPEN: |
753 | case REQ_ENV_OPEN: |
666 | req->result = req->env->open (req->env, req->buf1, req->uint1, req->int1); |
754 | req->result = req->env->open (req->env, req->buf1, req->uint1, req->int1); |
667 | break; |
755 | break; |
… | |
… | |
700 | |
788 | |
701 | case REQ_DB_SYNC: |
789 | case REQ_DB_SYNC: |
702 | req->result = req->db->sync (req->db, req->uint1); |
790 | req->result = req->db->sync (req->db, req->uint1); |
703 | break; |
791 | break; |
704 | |
792 | |
|
|
793 | case REQ_DB_UPGRADE: |
|
|
794 | req->result = req->db->upgrade (req->db, req->buf1, req->uint1); |
|
|
795 | break; |
|
|
796 | |
705 | case REQ_DB_PUT: |
797 | case REQ_DB_PUT: |
706 | req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1); |
798 | req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1); |
707 | break; |
799 | break; |
708 | |
800 | |
709 | case REQ_DB_GET: |
801 | case REQ_DB_GET: |
… | |
… | |
726 | req->result = req->txn->commit (req->txn, req->uint1); |
818 | req->result = req->txn->commit (req->txn, req->uint1); |
727 | break; |
819 | break; |
728 | |
820 | |
729 | case REQ_TXN_ABORT: |
821 | case REQ_TXN_ABORT: |
730 | req->result = req->txn->abort (req->txn); |
822 | req->result = req->txn->abort (req->txn); |
|
|
823 | break; |
|
|
824 | |
|
|
825 | case REQ_TXN_FINISH: |
|
|
826 | if (req->txn->flags & TXN_DEADLOCK) |
|
|
827 | { |
|
|
828 | req->result = req->txn->abort (req->txn); |
|
|
829 | if (!req->result) |
|
|
830 | req->result = DB_LOCK_DEADLOCK; |
|
|
831 | } |
|
|
832 | else |
|
|
833 | req->result = req->txn->commit (req->txn, req->uint1); |
731 | break; |
834 | break; |
732 | |
835 | |
733 | case REQ_C_CLOSE: |
836 | case REQ_C_CLOSE: |
734 | req->result = req->dbc->c_close (req->dbc); |
837 | req->result = req->dbc->c_close (req->dbc); |
735 | break; |
838 | break; |
… | |
… | |
777 | default: |
880 | default: |
778 | req->result = ENOSYS; |
881 | req->result = ENOSYS; |
779 | break; |
882 | break; |
780 | } |
883 | } |
781 | |
884 | |
|
|
885 | if (req->txn && (req->result > 0 || req->result == DB_LOCK_NOTGRANTED)) |
|
|
886 | req->txn->flags |= TXN_DEADLOCK; |
|
|
887 | |
782 | X_LOCK (reslock); |
888 | X_LOCK (reslock); |
783 | |
889 | |
784 | ++npending; |
890 | ++npending; |
785 | |
891 | |
786 | if (!reqq_push (&res_queue, req)) |
892 | if (!reqq_push (&res_queue, req)) |
… | |
… | |
817 | X_UNLOCK (wrklock); |
923 | X_UNLOCK (wrklock); |
818 | } |
924 | } |
819 | |
925 | |
820 | static void atfork_child (void) |
926 | static void atfork_child (void) |
821 | { |
927 | { |
822 | aio_req prv; |
928 | bdb_req prv; |
823 | |
929 | |
824 | while (prv = reqq_shift (&req_queue)) |
930 | while (prv = reqq_shift (&req_queue)) |
825 | req_free (prv); |
931 | req_free (prv); |
826 | |
932 | |
827 | while (prv = reqq_shift (&res_queue)) |
933 | while (prv = reqq_shift (&res_queue)) |
… | |
… | |
842 | idle = 0; |
948 | idle = 0; |
843 | nreqs = 0; |
949 | nreqs = 0; |
844 | nready = 0; |
950 | nready = 0; |
845 | npending = 0; |
951 | npending = 0; |
846 | |
952 | |
847 | respipe_close (respipe [0]); |
|
|
848 | respipe_close (respipe [1]); |
|
|
849 | |
|
|
850 | create_pipe (respipe); |
953 | create_respipe (); |
851 | |
954 | |
852 | atfork_parent (); |
955 | atfork_parent (); |
853 | } |
956 | } |
854 | |
957 | |
855 | #define dREQ(reqtype) \ |
958 | #define dREQ(reqtype) \ |
856 | aio_req req; \ |
959 | bdb_req req; \ |
857 | int req_pri = next_pri; \ |
960 | int req_pri = next_pri; \ |
858 | next_pri = DEFAULT_PRI + PRI_BIAS; \ |
961 | next_pri = DEFAULT_PRI + PRI_BIAS; \ |
859 | \ |
962 | \ |
860 | if (SvOK (callback) && !SvROK (callback)) \ |
963 | if (SvOK (callback) && !SvROK (callback)) \ |
861 | croak ("callback must be undef or of reference type"); \ |
964 | croak ("callback must be undef or of reference type"); \ |
862 | \ |
965 | \ |
863 | Newz (0, req, 1, aio_cb); \ |
966 | Newz (0, req, 1, bdb_cb); \ |
864 | if (!req) \ |
967 | if (!req) \ |
865 | croak ("out of memory during aio_req allocation"); \ |
968 | croak ("out of memory during bdb_req allocation"); \ |
866 | \ |
969 | \ |
867 | req->callback = newSVsv (callback); \ |
970 | req->callback = newSVsv (callback); \ |
868 | req->type = (reqtype); \ |
971 | req->type = (reqtype); \ |
869 | req->pri = req_pri |
972 | req->pri = req_pri |
870 | |
973 | |
871 | #define REQ_SEND \ |
974 | #define REQ_SEND \ |
872 | req_send (req) |
975 | req_send (req) |
873 | |
976 | |
874 | #define SvPTR(var, arg, type, class, nullok) \ |
977 | #define SvPTR(var, arg, type, class, nullok) \ |
875 | if (!SvOK (arg)) \ |
978 | if (!SvOK (arg)) \ |
876 | { \ |
979 | { \ |
877 | if (!nullok) \ |
980 | if (nullok != 1) \ |
878 | croak (# var " must be a " # class " object, not undef"); \ |
981 | croak (# var " must be a " # class " object, not undef"); \ |
879 | \ |
982 | \ |
880 | (var) = 0; \ |
983 | (var) = 0; \ |
881 | } \ |
984 | } \ |
882 | else if (sv_derived_from ((arg), # class)) \ |
985 | else if (sv_derived_from ((arg), # class)) \ |
883 | { \ |
986 | { \ |
884 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
987 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
885 | (var) = INT2PTR (type, tmp); \ |
988 | (var) = INT2PTR (type, tmp); \ |
886 | if (!var) \ |
989 | if (!var && nullok != 2) \ |
887 | croak (# var " is not a valid " # class " object anymore"); \ |
990 | croak (# var " is not a valid " # class " object anymore"); \ |
888 | } \ |
991 | } \ |
889 | else \ |
992 | else \ |
890 | croak (# var " is not of type " # class); \ |
993 | croak (# var " is not of type " # class); \ |
891 | \ |
994 | \ |
… | |
… | |
893 | static void |
996 | static void |
894 | ptr_nuke (SV *sv) |
997 | ptr_nuke (SV *sv) |
895 | { |
998 | { |
896 | assert (SvROK (sv)); |
999 | assert (SvROK (sv)); |
897 | sv_setiv (SvRV (sv), 0); |
1000 | sv_setiv (SvRV (sv), 0); |
|
|
1001 | } |
|
|
1002 | |
|
|
1003 | static int |
|
|
1004 | errno_get (pTHX_ SV *sv, MAGIC *mg) |
|
|
1005 | { |
|
|
1006 | if (*mg->mg_ptr == '!') // should always be the case |
|
|
1007 | if (-30999 <= errno && errno <= -30800) |
|
|
1008 | { |
|
|
1009 | sv_setnv (sv, (NV)errno); |
|
|
1010 | sv_setpv (sv, db_strerror (errno)); |
|
|
1011 | SvNOK_on (sv); /* what a wonderful hack! */ |
|
|
1012 | // ^^^ copied from perl sources |
|
|
1013 | return 0; |
|
|
1014 | } |
|
|
1015 | |
|
|
1016 | return PL_vtbl_sv.svt_get (aTHX_ sv, mg); |
|
|
1017 | } |
|
|
1018 | |
|
|
1019 | static MGVTBL vtbl_errno; |
|
|
1020 | |
|
|
1021 | // this wonderful hack :( patches perl's $! variable to support our errno values |
|
|
1022 | static void |
|
|
1023 | patch_errno (void) |
|
|
1024 | { |
|
|
1025 | SV *sv; |
|
|
1026 | MAGIC *mg; |
|
|
1027 | |
|
|
1028 | if (!(sv = get_sv ("!", 1))) |
|
|
1029 | return; |
|
|
1030 | |
|
|
1031 | if (!(mg = mg_find (sv, PERL_MAGIC_sv))) |
|
|
1032 | return; |
|
|
1033 | |
|
|
1034 | if (mg->mg_virtual != &PL_vtbl_sv) |
|
|
1035 | return; |
|
|
1036 | |
|
|
1037 | vtbl_errno = PL_vtbl_sv; |
|
|
1038 | vtbl_errno.svt_get = errno_get; |
|
|
1039 | mg->mg_virtual = &vtbl_errno; |
898 | } |
1040 | } |
899 | |
1041 | |
900 | MODULE = BDB PACKAGE = BDB |
1042 | MODULE = BDB PACKAGE = BDB |
901 | |
1043 | |
902 | PROTOTYPES: ENABLE |
1044 | PROTOTYPES: ENABLE |
… | |
… | |
919 | const_iv (INIT_TXN) |
1061 | const_iv (INIT_TXN) |
920 | const_iv (RECOVER) |
1062 | const_iv (RECOVER) |
921 | const_iv (INIT_TXN) |
1063 | const_iv (INIT_TXN) |
922 | const_iv (RECOVER_FATAL) |
1064 | const_iv (RECOVER_FATAL) |
923 | const_iv (CREATE) |
1065 | const_iv (CREATE) |
|
|
1066 | const_iv (RDONLY) |
924 | const_iv (USE_ENVIRON) |
1067 | const_iv (USE_ENVIRON) |
925 | const_iv (USE_ENVIRON_ROOT) |
1068 | const_iv (USE_ENVIRON_ROOT) |
926 | const_iv (LOCKDOWN) |
1069 | const_iv (LOCKDOWN) |
927 | const_iv (PRIVATE) |
1070 | const_iv (PRIVATE) |
928 | const_iv (REGISTER) |
1071 | const_iv (REGISTER) |
… | |
… | |
941 | const_iv (OVERWRITE) |
1084 | const_iv (OVERWRITE) |
942 | const_iv (PANIC_ENVIRONMENT) |
1085 | const_iv (PANIC_ENVIRONMENT) |
943 | const_iv (REGION_INIT) |
1086 | const_iv (REGION_INIT) |
944 | const_iv (TIME_NOTGRANTED) |
1087 | const_iv (TIME_NOTGRANTED) |
945 | const_iv (TXN_NOSYNC) |
1088 | const_iv (TXN_NOSYNC) |
|
|
1089 | const_iv (TXN_NOT_DURABLE) |
946 | const_iv (TXN_WRITE_NOSYNC) |
1090 | const_iv (TXN_WRITE_NOSYNC) |
947 | const_iv (WRITECURSOR) |
1091 | const_iv (WRITECURSOR) |
948 | const_iv (YIELDCPU) |
1092 | const_iv (YIELDCPU) |
949 | const_iv (ENCRYPT_AES) |
1093 | const_iv (ENCRYPT_AES) |
950 | const_iv (XA_CREATE) |
1094 | const_iv (XA_CREATE) |
… | |
… | |
958 | const_iv (READ_UNCOMMITTED) |
1102 | const_iv (READ_UNCOMMITTED) |
959 | const_iv (TRUNCATE) |
1103 | const_iv (TRUNCATE) |
960 | const_iv (NOSYNC) |
1104 | const_iv (NOSYNC) |
961 | const_iv (CHKSUM) |
1105 | const_iv (CHKSUM) |
962 | const_iv (ENCRYPT) |
1106 | const_iv (ENCRYPT) |
963 | const_iv (TXN_NOT_DURABLE) |
|
|
964 | const_iv (DUP) |
1107 | const_iv (DUP) |
965 | const_iv (DUPSORT) |
1108 | const_iv (DUPSORT) |
966 | const_iv (RECNUM) |
1109 | const_iv (RECNUM) |
967 | const_iv (RENUMBER) |
1110 | const_iv (RENUMBER) |
968 | const_iv (REVSPLITOFF) |
1111 | const_iv (REVSPLITOFF) |
… | |
… | |
973 | const_iv (GET_BOTH_RANGE) |
1116 | const_iv (GET_BOTH_RANGE) |
974 | //const_iv (SET_RECNO) |
1117 | //const_iv (SET_RECNO) |
975 | //const_iv (MULTIPLE) |
1118 | //const_iv (MULTIPLE) |
976 | const_iv (SNAPSHOT) |
1119 | const_iv (SNAPSHOT) |
977 | const_iv (JOIN_ITEM) |
1120 | const_iv (JOIN_ITEM) |
|
|
1121 | const_iv (JOIN_NOSORT) |
978 | const_iv (RMW) |
1122 | const_iv (RMW) |
979 | |
1123 | |
980 | const_iv (NOTFOUND) |
1124 | const_iv (NOTFOUND) |
981 | const_iv (KEYEMPTY) |
1125 | const_iv (KEYEMPTY) |
982 | const_iv (LOCK_DEADLOCK) |
1126 | const_iv (LOCK_DEADLOCK) |
… | |
… | |
998 | const_iv (TXN_SYNC) |
1142 | const_iv (TXN_SYNC) |
999 | |
1143 | |
1000 | const_iv (SET_LOCK_TIMEOUT) |
1144 | const_iv (SET_LOCK_TIMEOUT) |
1001 | const_iv (SET_TXN_TIMEOUT) |
1145 | const_iv (SET_TXN_TIMEOUT) |
1002 | |
1146 | |
1003 | const_iv (JOIN_ITEM) |
|
|
1004 | const_iv (FIRST) |
1147 | const_iv (FIRST) |
1005 | const_iv (NEXT) |
1148 | const_iv (NEXT) |
1006 | const_iv (NEXT_DUP) |
1149 | const_iv (NEXT_DUP) |
1007 | const_iv (NEXT_NODUP) |
1150 | const_iv (NEXT_NODUP) |
1008 | const_iv (PREV) |
1151 | const_iv (PREV) |
… | |
… | |
1042 | const_iv (LOG_BUFFER_FULL) |
1185 | const_iv (LOG_BUFFER_FULL) |
1043 | const_iv (NOSERVER) |
1186 | const_iv (NOSERVER) |
1044 | const_iv (NOSERVER_HOME) |
1187 | const_iv (NOSERVER_HOME) |
1045 | const_iv (NOSERVER_ID) |
1188 | const_iv (NOSERVER_ID) |
1046 | const_iv (NOTFOUND) |
1189 | const_iv (NOTFOUND) |
1047 | const_iv (OLD_VERSION) |
|
|
1048 | const_iv (PAGE_NOTFOUND) |
1190 | const_iv (PAGE_NOTFOUND) |
1049 | const_iv (REP_DUPMASTER) |
1191 | const_iv (REP_DUPMASTER) |
1050 | const_iv (REP_HANDLE_DEAD) |
1192 | const_iv (REP_HANDLE_DEAD) |
1051 | const_iv (REP_HOLDELECTION) |
1193 | const_iv (REP_HOLDELECTION) |
1052 | const_iv (REP_IGNORE) |
1194 | const_iv (REP_IGNORE) |
… | |
… | |
1074 | #if DB_VERSION_MINOR >= 5 |
1216 | #if DB_VERSION_MINOR >= 5 |
1075 | const_iv (MULTIVERSION) |
1217 | const_iv (MULTIVERSION) |
1076 | const_iv (TXN_SNAPSHOT) |
1218 | const_iv (TXN_SNAPSHOT) |
1077 | #endif |
1219 | #endif |
1078 | #if DB_VERSION_MINOR >= 6 |
1220 | #if DB_VERSION_MINOR >= 6 |
1079 | const_iv (DB_PREV_DUP) |
1221 | const_iv (PREV_DUP) |
|
|
1222 | const_iv (PRIORITY_UNCHANGED) |
|
|
1223 | const_iv (PRIORITY_VERY_LOW) |
|
|
1224 | const_iv (PRIORITY_LOW) |
|
|
1225 | const_iv (PRIORITY_DEFAULT) |
|
|
1226 | const_iv (PRIORITY_HIGH) |
|
|
1227 | const_iv (PRIORITY_VERY_HIGH) |
1080 | #endif |
1228 | #endif |
1081 | }; |
1229 | }; |
1082 | |
1230 | |
1083 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1231 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1084 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1232 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1085 | |
1233 | |
1086 | newCONSTSUB (stash, "DB_VERSION", newSVnv (DB_VERSION_MAJOR + DB_VERSION_MINOR * .1)); |
1234 | newCONSTSUB (stash, "VERSION", newSVnv (DB_VERSION_MAJOR + DB_VERSION_MINOR * .1)); |
1087 | newCONSTSUB (stash, "DB_VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1235 | newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1088 | |
1236 | |
1089 | create_pipe (respipe); |
1237 | create_respipe (); |
1090 | |
1238 | |
1091 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1239 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1092 | #ifdef _WIN32 |
1240 | patch_errno (); |
1093 | X_MUTEX_CHECK (wrklock); |
|
|
1094 | X_MUTEX_CHECK (reslock); |
|
|
1095 | X_MUTEX_CHECK (reqlock); |
|
|
1096 | |
|
|
1097 | X_COND_CHECK (reqwait); |
|
|
1098 | #endif |
|
|
1099 | } |
1241 | } |
1100 | |
1242 | |
1101 | void |
1243 | void |
1102 | max_poll_reqs (int nreqs) |
1244 | max_poll_reqs (int nreqs) |
1103 | PROTOTYPE: $ |
1245 | PROTOTYPE: $ |
… | |
… | |
1243 | CODE: |
1385 | CODE: |
1244 | RETVAL = db_strerror (errorno); |
1386 | RETVAL = db_strerror (errorno); |
1245 | OUTPUT: |
1387 | OUTPUT: |
1246 | RETVAL |
1388 | RETVAL |
1247 | |
1389 | |
|
|
1390 | void _on_next_submit (SV *cb) |
|
|
1391 | CODE: |
|
|
1392 | SvREFCNT_dec (on_next_submit); |
|
|
1393 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
|
|
1394 | |
1248 | DB_ENV * |
1395 | DB_ENV * |
1249 | db_env_create (U32 env_flags = 0) |
1396 | db_env_create (U32 env_flags = 0) |
1250 | CODE: |
1397 | CODE: |
1251 | { |
1398 | { |
1252 | errno = db_env_create (&RETVAL, env_flags); |
1399 | errno = db_env_create (&RETVAL, env_flags); |
… | |
… | |
1261 | } |
1408 | } |
1262 | OUTPUT: |
1409 | OUTPUT: |
1263 | RETVAL |
1410 | RETVAL |
1264 | |
1411 | |
1265 | void |
1412 | void |
1266 | db_env_open (DB_ENV *env, octetstring db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef) |
1413 | db_env_open (DB_ENV *env, bdb_filename db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef) |
1267 | CODE: |
1414 | CODE: |
1268 | { |
1415 | { |
1269 | dREQ (REQ_ENV_OPEN); |
1416 | dREQ (REQ_ENV_OPEN); |
1270 | |
|
|
1271 | env->set_thread_count (env, wanted + 2); |
|
|
1272 | |
1417 | |
1273 | req->env = env; |
1418 | req->env = env; |
1274 | req->uint1 = open_flags | DB_THREAD; |
1419 | req->uint1 = open_flags | DB_THREAD; |
1275 | req->int1 = mode; |
1420 | req->int1 = mode; |
1276 | req->buf1 = strdup_ornull (db_home); |
1421 | req->buf1 = strdup_ornull (db_home); |
… | |
… | |
1344 | } |
1489 | } |
1345 | OUTPUT: |
1490 | OUTPUT: |
1346 | RETVAL |
1491 | RETVAL |
1347 | |
1492 | |
1348 | void |
1493 | void |
1349 | db_open (DB *db, DB_TXN_ornull *txnid, octetstring file, octetstring database, int type, U32 flags, int mode, SV *callback = &PL_sv_undef) |
1494 | db_open (DB *db, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, int type, U32 flags, int mode, SV *callback = &PL_sv_undef) |
1350 | CODE: |
1495 | CODE: |
1351 | { |
1496 | { |
1352 | dREQ (REQ_DB_OPEN); |
1497 | dREQ (REQ_DB_OPEN); |
1353 | req->db = db; |
1498 | req->db = db; |
1354 | req->txn = txnid; |
1499 | req->txn = txnid; |
… | |
… | |
1394 | req->uint1 = flags; |
1539 | req->uint1 = flags; |
1395 | REQ_SEND; |
1540 | REQ_SEND; |
1396 | } |
1541 | } |
1397 | |
1542 | |
1398 | void |
1543 | void |
|
|
1544 | db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = &PL_sv_undef) |
|
|
1545 | CODE: |
|
|
1546 | { |
|
|
1547 | dREQ (REQ_DB_SYNC); |
|
|
1548 | req->db = db; |
|
|
1549 | req->buf1 = strdup (file); |
|
|
1550 | req->uint1 = flags; |
|
|
1551 | REQ_SEND; |
|
|
1552 | } |
|
|
1553 | |
|
|
1554 | void |
1399 | db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = &PL_sv_undef) |
1555 | db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = &PL_sv_undef) |
1400 | CODE: |
1556 | CODE: |
1401 | { |
1557 | { |
1402 | dREQ (REQ_DB_KEY_RANGE); |
1558 | dREQ (REQ_DB_KEY_RANGE); |
1403 | req->db = db; |
1559 | req->db = db; |
… | |
… | |
1422 | } |
1578 | } |
1423 | |
1579 | |
1424 | void |
1580 | void |
1425 | db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1581 | db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1426 | CODE: |
1582 | CODE: |
|
|
1583 | if (SvREADONLY (data)) |
|
|
1584 | croak ("can't modify read-only data scalar in db_get"); |
1427 | { |
1585 | { |
1428 | dREQ (REQ_DB_GET); |
1586 | dREQ (REQ_DB_GET); |
1429 | req->db = db; |
1587 | req->db = db; |
1430 | req->txn = txn; |
1588 | req->txn = txn; |
1431 | req->uint1 = flags; |
1589 | req->uint1 = flags; |
… | |
… | |
1436 | } |
1594 | } |
1437 | |
1595 | |
1438 | void |
1596 | void |
1439 | db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1597 | db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1440 | CODE: |
1598 | CODE: |
|
|
1599 | if (SvREADONLY (data)) |
|
|
1600 | croak ("can't modify read-only data scalar in db_pget"); |
1441 | { |
1601 | { |
1442 | dREQ (REQ_DB_PGET); |
1602 | dREQ (REQ_DB_PGET); |
1443 | req->db = db; |
1603 | req->db = db; |
1444 | req->txn = txn; |
1604 | req->txn = txn; |
1445 | req->uint1 = flags; |
1605 | req->uint1 = flags; |
… | |
… | |
1482 | REQ_SEND; |
1642 | REQ_SEND; |
1483 | ptr_nuke (ST (0)); |
1643 | ptr_nuke (ST (0)); |
1484 | } |
1644 | } |
1485 | |
1645 | |
1486 | void |
1646 | void |
|
|
1647 | db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = &PL_sv_undef) |
|
|
1648 | CODE: |
|
|
1649 | { |
|
|
1650 | dREQ (REQ_TXN_FINISH); |
|
|
1651 | req->txn = txn; |
|
|
1652 | req->uint1 = flags; |
|
|
1653 | REQ_SEND; |
|
|
1654 | ptr_nuke (ST (0)); |
|
|
1655 | } |
|
|
1656 | |
|
|
1657 | void |
1487 | db_c_close (DBC *dbc, SV *callback = &PL_sv_undef) |
1658 | db_c_close (DBC *dbc, SV *callback = &PL_sv_undef) |
1488 | CODE: |
1659 | CODE: |
1489 | { |
1660 | { |
1490 | dREQ (REQ_C_CLOSE); |
1661 | dREQ (REQ_C_CLOSE); |
1491 | req->dbc = dbc; |
1662 | req->dbc = dbc; |
… | |
… | |
1628 | |
1799 | |
1629 | |
1800 | |
1630 | MODULE = BDB PACKAGE = BDB::Env |
1801 | MODULE = BDB PACKAGE = BDB::Env |
1631 | |
1802 | |
1632 | void |
1803 | void |
1633 | DESTROY (DB_ENV_ornull *env) |
1804 | DESTROY (DB_ENV_ornuked *env) |
1634 | CODE: |
1805 | CODE: |
1635 | if (env) |
1806 | if (env) |
1636 | env->close (env, 0); |
1807 | env->close (env, 0); |
1637 | |
1808 | |
1638 | int set_data_dir (DB_ENV *env, const char *dir) |
1809 | int set_data_dir (DB_ENV *env, const char *dir) |
… | |
… | |
1663 | CODE: |
1834 | CODE: |
1664 | RETVAL = env->set_cachesize (env, gbytes, bytes, ncache); |
1835 | RETVAL = env->set_cachesize (env, gbytes, bytes, ncache); |
1665 | OUTPUT: |
1836 | OUTPUT: |
1666 | RETVAL |
1837 | RETVAL |
1667 | |
1838 | |
1668 | int set_flags (DB_ENV *env, U32 flags, int onoff) |
1839 | int set_flags (DB_ENV *env, U32 flags, int onoff = 1) |
1669 | CODE: |
1840 | CODE: |
1670 | RETVAL = env->set_flags (env, flags, onoff); |
1841 | RETVAL = env->set_flags (env, flags, onoff); |
1671 | OUTPUT: |
1842 | OUTPUT: |
1672 | RETVAL |
1843 | RETVAL |
1673 | |
1844 | |
1674 | void set_errfile (DB_ENV *env, FILE *errfile) |
1845 | void set_errfile (DB_ENV *env, FILE *errfile = 0) |
1675 | CODE: |
1846 | CODE: |
1676 | env->set_errfile (env, errfile); |
1847 | env->set_errfile (env, errfile); |
1677 | |
1848 | |
1678 | void set_msgfile (DB_ENV *env, FILE *msgfile) |
1849 | void set_msgfile (DB_ENV *env, FILE *msgfile = 0) |
1679 | CODE: |
1850 | CODE: |
1680 | env->set_msgfile (env, msgfile); |
1851 | env->set_msgfile (env, msgfile); |
1681 | |
1852 | |
1682 | int set_verbose (DB_ENV *env, U32 which, int onoff = 1) |
1853 | int set_verbose (DB_ENV *env, U32 which = -1, int onoff = 1) |
1683 | CODE: |
1854 | CODE: |
1684 | RETVAL = env->set_verbose (env, which, onoff); |
1855 | RETVAL = env->set_verbose (env, which, onoff); |
1685 | OUTPUT: |
1856 | OUTPUT: |
1686 | RETVAL |
1857 | RETVAL |
1687 | |
1858 | |
… | |
… | |
1689 | CODE: |
1860 | CODE: |
1690 | RETVAL = env->set_encrypt (env, password, flags); |
1861 | RETVAL = env->set_encrypt (env, password, flags); |
1691 | OUTPUT: |
1862 | OUTPUT: |
1692 | RETVAL |
1863 | RETVAL |
1693 | |
1864 | |
1694 | int set_timeout (DB_ENV *env, NV timeout, U32 flags) |
1865 | int set_timeout (DB_ENV *env, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT) |
1695 | CODE: |
1866 | CODE: |
1696 | RETVAL = env->set_timeout (env, timeout * 1000000, flags); |
1867 | RETVAL = env->set_timeout (env, timeout * 1000000, flags); |
1697 | OUTPUT: |
1868 | OUTPUT: |
1698 | RETVAL |
1869 | RETVAL |
1699 | |
1870 | |
… | |
… | |
1747 | |
1918 | |
1748 | int set_lg_max (DB_ENV *env, U32 max) |
1919 | int set_lg_max (DB_ENV *env, U32 max) |
1749 | CODE: |
1920 | CODE: |
1750 | RETVAL = env->set_lg_max (env, max); |
1921 | RETVAL = env->set_lg_max (env, max); |
1751 | OUTPUT: |
1922 | OUTPUT: |
|
|
1923 | RETVAL |
|
|
1924 | |
|
|
1925 | int mutex_set_max (DB_ENV *env, U32 max) |
|
|
1926 | CODE: |
|
|
1927 | RETVAL = env->mutex_set_max (env, max); |
|
|
1928 | OUTPUT: |
|
|
1929 | RETVAL |
|
|
1930 | |
|
|
1931 | int mutex_set_increment (DB_ENV *env, U32 increment) |
|
|
1932 | CODE: |
|
|
1933 | RETVAL = env->mutex_set_increment (env, increment); |
|
|
1934 | OUTPUT: |
|
|
1935 | RETVAL |
|
|
1936 | |
|
|
1937 | int mutex_set_tas_spins (DB_ENV *env, U32 tas_spins) |
|
|
1938 | CODE: |
|
|
1939 | RETVAL = env->mutex_set_tas_spins (env, tas_spins); |
|
|
1940 | OUTPUT: |
|
|
1941 | RETVAL |
|
|
1942 | |
|
|
1943 | int mutex_set_align (DB_ENV *env, U32 align) |
|
|
1944 | CODE: |
|
|
1945 | RETVAL = env->mutex_set_align (env, align); |
|
|
1946 | OUTPUT: |
1752 | RETVAL |
1947 | RETVAL |
1753 | |
1948 | |
1754 | DB_TXN * |
1949 | DB_TXN * |
1755 | txn_begin (DB_ENV *env, DB_TXN_ornull *parent = 0, U32 flags = 0) |
1950 | txn_begin (DB_ENV *env, DB_TXN_ornull *parent = 0, U32 flags = 0) |
1756 | CODE: |
1951 | CODE: |
… | |
… | |
1761 | RETVAL |
1956 | RETVAL |
1762 | |
1957 | |
1763 | MODULE = BDB PACKAGE = BDB::Db |
1958 | MODULE = BDB PACKAGE = BDB::Db |
1764 | |
1959 | |
1765 | void |
1960 | void |
1766 | DESTROY (DB_ornull *db) |
1961 | DESTROY (DB_ornuked *db) |
1767 | CODE: |
1962 | CODE: |
1768 | if (db) |
1963 | if (db) |
1769 | { |
1964 | { |
1770 | SV *env = (SV *)db->app_private; |
1965 | SV *env = (SV *)db->app_private; |
1771 | db->close (db, 0); |
1966 | db->close (db, 0); |
… | |
… | |
1776 | CODE: |
1971 | CODE: |
1777 | RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); |
1972 | RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); |
1778 | OUTPUT: |
1973 | OUTPUT: |
1779 | RETVAL |
1974 | RETVAL |
1780 | |
1975 | |
1781 | int set_flags (DB *db, U32 flags); |
1976 | int set_flags (DB *db, U32 flags) |
1782 | CODE: |
1977 | CODE: |
1783 | RETVAL = db->set_flags (db, flags); |
1978 | RETVAL = db->set_flags (db, flags); |
1784 | OUTPUT: |
1979 | OUTPUT: |
1785 | RETVAL |
1980 | RETVAL |
1786 | |
1981 | |
… | |
… | |
1800 | CODE: |
1995 | CODE: |
1801 | RETVAL = db->set_bt_minkey (db, minkey); |
1996 | RETVAL = db->set_bt_minkey (db, minkey); |
1802 | OUTPUT: |
1997 | OUTPUT: |
1803 | RETVAL |
1998 | RETVAL |
1804 | |
1999 | |
1805 | int set_re_delim(DB *db, int delim); |
2000 | int set_re_delim (DB *db, int delim) |
1806 | CODE: |
2001 | CODE: |
1807 | RETVAL = db->set_re_delim (db, delim); |
2002 | RETVAL = db->set_re_delim (db, delim); |
1808 | OUTPUT: |
2003 | OUTPUT: |
1809 | RETVAL |
2004 | RETVAL |
1810 | |
2005 | |
… | |
… | |
1866 | |
2061 | |
1867 | |
2062 | |
1868 | MODULE = BDB PACKAGE = BDB::Txn |
2063 | MODULE = BDB PACKAGE = BDB::Txn |
1869 | |
2064 | |
1870 | void |
2065 | void |
1871 | DESTROY (DB_TXN_ornull *txn) |
2066 | DESTROY (DB_TXN_ornuked *txn) |
1872 | CODE: |
2067 | CODE: |
1873 | if (txn) |
2068 | if (txn) |
1874 | txn->abort (txn); |
2069 | txn->abort (txn); |
1875 | |
2070 | |
1876 | int set_timeout (DB_TXN *txn, NV timeout, U32 flags) |
2071 | int set_timeout (DB_TXN *txn, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT) |
1877 | CODE: |
2072 | CODE: |
1878 | RETVAL = txn->set_timeout (txn, timeout * 1000000, flags); |
2073 | RETVAL = txn->set_timeout (txn, timeout * 1000000, flags); |
1879 | OUTPUT: |
2074 | OUTPUT: |
1880 | RETVAL |
2075 | RETVAL |
1881 | |
2076 | |
|
|
2077 | int failed (DB_TXN *txn) |
|
|
2078 | CODE: |
|
|
2079 | RETVAL = !!(txn->flags & TXN_DEADLOCK); |
|
|
2080 | OUTPUT: |
|
|
2081 | RETVAL |
|
|
2082 | |
1882 | |
2083 | |
1883 | MODULE = BDB PACKAGE = BDB::Cursor |
2084 | MODULE = BDB PACKAGE = BDB::Cursor |
1884 | |
2085 | |
1885 | void |
2086 | void |
1886 | DESTROY (DBC_ornull *dbc) |
2087 | DESTROY (DBC_ornuked *dbc) |
1887 | CODE: |
2088 | CODE: |
1888 | if (dbc) |
2089 | if (dbc) |
1889 | dbc->c_close (dbc); |
2090 | dbc->c_close (dbc); |
1890 | |
2091 | |
|
|
2092 | #if DB_VERSION_MINOR >= 6 |
|
|
2093 | |
|
|
2094 | int set_priority (DBC *dbc, int priority) |
|
|
2095 | CODE: |
|
|
2096 | dbc->set_priority (dbc, priority); |
|
|
2097 | |
|
|
2098 | #endif |
|
|
2099 | |
1891 | MODULE = BDB PACKAGE = BDB::Sequence |
2100 | MODULE = BDB PACKAGE = BDB::Sequence |
1892 | |
2101 | |
1893 | void |
2102 | void |
1894 | DESTROY (DB_SEQUENCE_ornull *seq) |
2103 | DESTROY (DB_SEQUENCE_ornuked *seq) |
1895 | CODE: |
2104 | CODE: |
1896 | if (seq) |
2105 | if (seq) |
1897 | seq->close (seq, 0); |
2106 | seq->close (seq, 0); |
1898 | |
2107 | |
1899 | int initial_value (DB_SEQUENCE *seq, db_seq_t value) |
2108 | int initial_value (DB_SEQUENCE *seq, db_seq_t value) |
… | |
… | |
1918 | CODE: |
2127 | CODE: |
1919 | RETVAL = seq->set_range (seq, min, max); |
2128 | RETVAL = seq->set_range (seq, min, max); |
1920 | OUTPUT: |
2129 | OUTPUT: |
1921 | RETVAL |
2130 | RETVAL |
1922 | |
2131 | |
|
|
2132 | |