… | |
… | |
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; |
49 | |
55 | |
50 | #if DB_VERSION_MINOR >= 6 |
56 | #if DB_VERSION_MINOR >= 6 |
51 | # define c_close close |
57 | # define c_close close |
… | |
… | |
54 | # define c_dup dup |
60 | # define c_dup dup |
55 | # define c_get get |
61 | # define c_get get |
56 | # define c_pget pget |
62 | # define c_pget pget |
57 | # define c_put put |
63 | # define c_put put |
58 | #endif |
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 | } |
59 | |
95 | |
60 | static void |
96 | static void |
61 | 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) |
62 | { |
98 | { |
63 | printf ("err[%s]\n", msg); |
99 | printf ("err[%s]\n", msg); |
… | |
… | |
109 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
145 | 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, |
146 | 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, |
147 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
112 | }; |
148 | }; |
113 | |
149 | |
114 | typedef struct aio_cb |
150 | typedef struct bdb_cb |
115 | { |
151 | { |
116 | struct aio_cb *volatile next; |
152 | struct bdb_cb *volatile next; |
117 | SV *callback; |
153 | SV *callback; |
118 | int type, pri, result; |
154 | int type, pri, result; |
119 | |
155 | |
120 | DB_ENV *env; |
156 | DB_ENV *env; |
121 | DB *db; |
157 | DB *db; |
… | |
… | |
130 | |
166 | |
131 | DBT dbt1, dbt2, dbt3; |
167 | DBT dbt1, dbt2, dbt3; |
132 | DB_KEY_RANGE key_range; |
168 | DB_KEY_RANGE key_range; |
133 | DB_SEQUENCE *seq; |
169 | DB_SEQUENCE *seq; |
134 | db_seq_t seq_t; |
170 | db_seq_t seq_t; |
135 | } aio_cb; |
171 | } bdb_cb; |
136 | |
172 | |
137 | typedef aio_cb *aio_req; |
173 | typedef bdb_cb *bdb_req; |
138 | |
174 | |
139 | enum { |
175 | enum { |
140 | PRI_MIN = -4, |
176 | PRI_MIN = -4, |
141 | PRI_MAX = 4, |
177 | PRI_MAX = 4, |
142 | |
178 | |
… | |
… | |
169 | struct worker *prev, *next; |
205 | struct worker *prev, *next; |
170 | |
206 | |
171 | thread_t tid; |
207 | thread_t tid; |
172 | |
208 | |
173 | /* locked by reslock, reqlock or wrklock */ |
209 | /* locked by reslock, reqlock or wrklock */ |
174 | aio_req req; /* currently processed request */ |
210 | bdb_req req; /* currently processed request */ |
175 | void *dbuf; |
211 | void *dbuf; |
176 | DIR *dirp; |
212 | DIR *dirp; |
177 | } worker; |
213 | } worker; |
178 | |
214 | |
179 | static worker wrk_first = { &wrk_first, &wrk_first, 0 }; |
215 | static worker wrk_first = { &wrk_first, &wrk_first, 0 }; |
… | |
… | |
199 | static mutex_t reqlock = X_MUTEX_INIT; |
235 | static mutex_t reqlock = X_MUTEX_INIT; |
200 | static cond_t reqwait = X_COND_INIT; |
236 | static cond_t reqwait = X_COND_INIT; |
201 | |
237 | |
202 | #if WORDACCESS_UNSAFE |
238 | #if WORDACCESS_UNSAFE |
203 | |
239 | |
204 | static unsigned int get_nready () |
240 | static unsigned int get_nready (void) |
205 | { |
241 | { |
206 | unsigned int retval; |
242 | unsigned int retval; |
207 | |
243 | |
208 | X_LOCK (reqlock); |
244 | X_LOCK (reqlock); |
209 | retval = nready; |
245 | retval = nready; |
210 | X_UNLOCK (reqlock); |
246 | X_UNLOCK (reqlock); |
211 | |
247 | |
212 | return retval; |
248 | return retval; |
213 | } |
249 | } |
214 | |
250 | |
215 | static unsigned int get_npending () |
251 | static unsigned int get_npending (void) |
216 | { |
252 | { |
217 | unsigned int retval; |
253 | unsigned int retval; |
218 | |
254 | |
219 | X_LOCK (reslock); |
255 | X_LOCK (reslock); |
220 | retval = npending; |
256 | retval = npending; |
221 | X_UNLOCK (reslock); |
257 | X_UNLOCK (reslock); |
222 | |
258 | |
223 | return retval; |
259 | return retval; |
224 | } |
260 | } |
225 | |
261 | |
226 | static unsigned int get_nthreads () |
262 | static unsigned int get_nthreads (void) |
227 | { |
263 | { |
228 | unsigned int retval; |
264 | unsigned int retval; |
229 | |
265 | |
230 | X_LOCK (wrklock); |
266 | X_LOCK (wrklock); |
231 | retval = started; |
267 | retval = started; |
… | |
… | |
246 | * a somewhat faster data structure might be nice, but |
282 | * a somewhat faster data structure might be nice, but |
247 | * with 8 priorities this actually needs <20 insns |
283 | * with 8 priorities this actually needs <20 insns |
248 | * per shift, the most expensive operation. |
284 | * per shift, the most expensive operation. |
249 | */ |
285 | */ |
250 | typedef struct { |
286 | typedef struct { |
251 | aio_req qs[NUM_PRI], qe[NUM_PRI]; /* qstart, qend */ |
287 | bdb_req qs[NUM_PRI], qe[NUM_PRI]; /* qstart, qend */ |
252 | int size; |
288 | int size; |
253 | } reqq; |
289 | } reqq; |
254 | |
290 | |
255 | static reqq req_queue; |
291 | static reqq req_queue; |
256 | static reqq res_queue; |
292 | static reqq res_queue; |
257 | |
293 | |
258 | int reqq_push (reqq *q, aio_req req) |
294 | int reqq_push (reqq *q, bdb_req req) |
259 | { |
295 | { |
260 | int pri = req->pri; |
296 | int pri = req->pri; |
261 | req->next = 0; |
297 | req->next = 0; |
262 | |
298 | |
263 | if (q->qe[pri]) |
299 | if (q->qe[pri]) |
… | |
… | |
269 | q->qe[pri] = q->qs[pri] = req; |
305 | q->qe[pri] = q->qs[pri] = req; |
270 | |
306 | |
271 | return q->size++; |
307 | return q->size++; |
272 | } |
308 | } |
273 | |
309 | |
274 | aio_req reqq_shift (reqq *q) |
310 | bdb_req reqq_shift (reqq *q) |
275 | { |
311 | { |
276 | int pri; |
312 | int pri; |
277 | |
313 | |
278 | if (!q->size) |
314 | if (!q->size) |
279 | return 0; |
315 | return 0; |
280 | |
316 | |
281 | --q->size; |
317 | --q->size; |
282 | |
318 | |
283 | for (pri = NUM_PRI; pri--; ) |
319 | for (pri = NUM_PRI; pri--; ) |
284 | { |
320 | { |
285 | aio_req req = q->qs[pri]; |
321 | bdb_req req = q->qs[pri]; |
286 | |
322 | |
287 | if (req) |
323 | if (req) |
288 | { |
324 | { |
289 | if (!(q->qs[pri] = req->next)) |
325 | if (!(q->qs[pri] = req->next)) |
290 | q->qe[pri] = 0; |
326 | q->qe[pri] = 0; |
… | |
… | |
294 | } |
330 | } |
295 | |
331 | |
296 | abort (); |
332 | abort (); |
297 | } |
333 | } |
298 | |
334 | |
299 | static int poll_cb (); |
335 | static int poll_cb (void); |
300 | static void req_free (aio_req req); |
336 | static void req_free (bdb_req req); |
301 | static void req_cancel (aio_req req); |
337 | static void req_cancel (bdb_req req); |
302 | |
338 | |
303 | static int req_invoke (aio_req req) |
339 | static int req_invoke (bdb_req req) |
304 | { |
340 | { |
305 | dSP; |
341 | dSP; |
306 | |
342 | |
307 | if (SvOK (req->callback)) |
343 | if (SvOK (req->callback)) |
308 | { |
344 | { |
… | |
… | |
371 | } |
407 | } |
372 | |
408 | |
373 | return !SvTRUE (ERRSV); |
409 | return !SvTRUE (ERRSV); |
374 | } |
410 | } |
375 | |
411 | |
376 | static void req_free (aio_req req) |
412 | static void req_free (bdb_req req) |
377 | { |
413 | { |
378 | free (req->buf1); |
414 | free (req->buf1); |
379 | free (req->buf2); |
415 | free (req->buf2); |
380 | Safefree (req); |
416 | Safefree (req); |
381 | } |
417 | } |
… | |
… | |
385 | #else |
421 | #else |
386 | # define TO_SOCKET(x) (x) |
422 | # define TO_SOCKET(x) (x) |
387 | #endif |
423 | #endif |
388 | |
424 | |
389 | static void |
425 | static void |
390 | create_respipe () |
426 | create_respipe (void) |
391 | { |
427 | { |
392 | #ifdef _WIN32 |
428 | #ifdef _WIN32 |
393 | int arg; /* argg */ |
429 | int arg; /* argg */ |
394 | #endif |
430 | #endif |
395 | int old_readfd = respipe [0]; |
431 | int old_readfd = respipe [0]; |
… | |
… | |
449 | free (wrk); |
485 | free (wrk); |
450 | |
486 | |
451 | X_UNLOCK (wrklock); |
487 | X_UNLOCK (wrklock); |
452 | } |
488 | } |
453 | |
489 | |
454 | static void maybe_start_thread () |
490 | static void maybe_start_thread (void) |
455 | { |
491 | { |
456 | if (get_nthreads () >= wanted) |
492 | if (get_nthreads () >= wanted) |
457 | return; |
493 | return; |
458 | |
494 | |
459 | /* todo: maybe use idle here, but might be less exact */ |
495 | /* todo: maybe use idle here, but might be less exact */ |
… | |
… | |
461 | return; |
497 | return; |
462 | |
498 | |
463 | start_thread (); |
499 | start_thread (); |
464 | } |
500 | } |
465 | |
501 | |
466 | static void req_send (aio_req req) |
502 | static void req_send (bdb_req req) |
467 | { |
503 | { |
468 | SV *wait_callback = 0; |
504 | SV *wait_callback = 0; |
469 | |
505 | |
470 | // synthesize callback if none given |
506 | // synthesize callback if none given |
471 | if (!SvOK (req->callback)) |
507 | if (!SvOK (req->callback)) |
… | |
… | |
479 | SPAGAIN; |
515 | SPAGAIN; |
480 | |
516 | |
481 | if (count != 2) |
517 | if (count != 2) |
482 | croak ("prepare callback must return exactly two values\n"); |
518 | croak ("prepare callback must return exactly two values\n"); |
483 | |
519 | |
484 | wait_callback = SvREFCNT_inc (POPs); |
520 | wait_callback = POPs; |
485 | SvREFCNT_dec (req->callback); |
521 | SvREFCNT_dec (req->callback); |
486 | req->callback = SvREFCNT_inc (POPs); |
522 | req->callback = SvREFCNT_inc (POPs); |
487 | } |
523 | } |
488 | |
524 | |
489 | ++nreqs; |
525 | ++nreqs; |
… | |
… | |
500 | { |
536 | { |
501 | dSP; |
537 | dSP; |
502 | PUSHMARK (SP); |
538 | PUSHMARK (SP); |
503 | PUTBACK; |
539 | PUTBACK; |
504 | call_sv (wait_callback, G_DISCARD); |
540 | call_sv (wait_callback, G_DISCARD); |
505 | SvREFCNT_dec (wait_callback); |
|
|
506 | } |
541 | } |
507 | } |
542 | } |
508 | |
543 | |
509 | static void end_thread (void) |
544 | static void end_thread (void) |
510 | { |
545 | { |
511 | aio_req req; |
546 | bdb_req req; |
512 | |
547 | |
513 | Newz (0, req, 1, aio_cb); |
548 | Newz (0, req, 1, bdb_cb); |
514 | |
549 | |
515 | req->type = REQ_QUIT; |
550 | req->type = REQ_QUIT; |
516 | req->pri = PRI_MAX + PRI_BIAS; |
551 | req->pri = PRI_MAX + PRI_BIAS; |
517 | |
552 | |
518 | X_LOCK (reqlock); |
553 | X_LOCK (reqlock); |
… | |
… | |
545 | |
580 | |
546 | while (started > wanted) |
581 | while (started > wanted) |
547 | end_thread (); |
582 | end_thread (); |
548 | } |
583 | } |
549 | |
584 | |
550 | static void poll_wait () |
585 | static void poll_wait (void) |
551 | { |
586 | { |
552 | fd_set rfd; |
587 | fd_set rfd; |
553 | |
588 | |
554 | while (nreqs) |
589 | while (nreqs) |
555 | { |
590 | { |
… | |
… | |
568 | |
603 | |
569 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
604 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
570 | } |
605 | } |
571 | } |
606 | } |
572 | |
607 | |
573 | static int poll_cb () |
608 | static int poll_cb (void) |
574 | { |
609 | { |
575 | dSP; |
610 | dSP; |
576 | int count = 0; |
611 | int count = 0; |
577 | int maxreqs = max_poll_reqs; |
612 | int maxreqs = max_poll_reqs; |
578 | int do_croak = 0; |
613 | int do_croak = 0; |
579 | struct timeval tv_start, tv_now; |
614 | struct timeval tv_start, tv_now; |
580 | aio_req req; |
615 | bdb_req req; |
581 | |
616 | |
582 | if (max_poll_time) |
617 | if (max_poll_time) |
583 | gettimeofday (&tv_start, 0); |
618 | gettimeofday (&tv_start, 0); |
584 | |
619 | |
585 | for (;;) |
620 | for (;;) |
… | |
… | |
646 | |
681 | |
647 | /*****************************************************************************/ |
682 | /*****************************************************************************/ |
648 | |
683 | |
649 | X_THREAD_PROC (bdb_proc) |
684 | X_THREAD_PROC (bdb_proc) |
650 | { |
685 | { |
651 | aio_req req; |
686 | bdb_req req; |
652 | struct timespec ts; |
687 | struct timespec ts; |
653 | worker *self = (worker *)thr_arg; |
688 | worker *self = (worker *)thr_arg; |
654 | |
689 | |
655 | /* try to distribute timeouts somewhat evenly */ |
690 | /* try to distribute timeouts somewhat evenly */ |
656 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
691 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
… | |
… | |
874 | X_UNLOCK (wrklock); |
909 | X_UNLOCK (wrklock); |
875 | } |
910 | } |
876 | |
911 | |
877 | static void atfork_child (void) |
912 | static void atfork_child (void) |
878 | { |
913 | { |
879 | aio_req prv; |
914 | bdb_req prv; |
880 | |
915 | |
881 | while (prv = reqq_shift (&req_queue)) |
916 | while (prv = reqq_shift (&req_queue)) |
882 | req_free (prv); |
917 | req_free (prv); |
883 | |
918 | |
884 | while (prv = reqq_shift (&res_queue)) |
919 | while (prv = reqq_shift (&res_queue)) |
… | |
… | |
905 | |
940 | |
906 | atfork_parent (); |
941 | atfork_parent (); |
907 | } |
942 | } |
908 | |
943 | |
909 | #define dREQ(reqtype) \ |
944 | #define dREQ(reqtype) \ |
910 | aio_req req; \ |
945 | bdb_req req; \ |
911 | int req_pri = next_pri; \ |
946 | int req_pri = next_pri; \ |
912 | next_pri = DEFAULT_PRI + PRI_BIAS; \ |
947 | next_pri = DEFAULT_PRI + PRI_BIAS; \ |
913 | \ |
948 | \ |
914 | if (SvOK (callback) && !SvROK (callback)) \ |
949 | if (SvOK (callback) && !SvROK (callback)) \ |
915 | croak ("callback must be undef or of reference type"); \ |
950 | croak ("callback must be undef or of reference type"); \ |
916 | \ |
951 | \ |
917 | Newz (0, req, 1, aio_cb); \ |
952 | Newz (0, req, 1, bdb_cb); \ |
918 | if (!req) \ |
953 | if (!req) \ |
919 | croak ("out of memory during aio_req allocation"); \ |
954 | croak ("out of memory during bdb_req allocation"); \ |
920 | \ |
955 | \ |
921 | req->callback = newSVsv (callback); \ |
956 | req->callback = newSVsv (callback); \ |
922 | req->type = (reqtype); \ |
957 | req->type = (reqtype); \ |
923 | req->pri = req_pri |
958 | req->pri = req_pri |
924 | |
959 | |
925 | #define REQ_SEND \ |
960 | #define REQ_SEND \ |
926 | req_send (req) |
961 | req_send (req) |
927 | |
962 | |
928 | #define SvPTR(var, arg, type, class, nullok) \ |
963 | #define SvPTR(var, arg, type, class, nullok) \ |
929 | if (!SvOK (arg)) \ |
964 | if (!SvOK (arg)) \ |
930 | { \ |
965 | { \ |
931 | if (!nullok) \ |
966 | if (nullok != 1) \ |
932 | croak (# var " must be a " # class " object, not undef"); \ |
967 | croak (# var " must be a " # class " object, not undef"); \ |
933 | \ |
968 | \ |
934 | (var) = 0; \ |
969 | (var) = 0; \ |
935 | } \ |
970 | } \ |
936 | else if (sv_derived_from ((arg), # class)) \ |
971 | else if (sv_derived_from ((arg), # class)) \ |
937 | { \ |
972 | { \ |
938 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
973 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
939 | (var) = INT2PTR (type, tmp); \ |
974 | (var) = INT2PTR (type, tmp); \ |
940 | if (!var) \ |
975 | if (!var && nullok != 2) \ |
941 | croak (# var " is not a valid " # class " object anymore"); \ |
976 | croak (# var " is not a valid " # class " object anymore"); \ |
942 | } \ |
977 | } \ |
943 | else \ |
978 | else \ |
944 | croak (# var " is not of type " # class); \ |
979 | croak (# var " is not of type " # class); \ |
945 | \ |
980 | \ |
… | |
… | |
947 | static void |
982 | static void |
948 | ptr_nuke (SV *sv) |
983 | ptr_nuke (SV *sv) |
949 | { |
984 | { |
950 | assert (SvROK (sv)); |
985 | assert (SvROK (sv)); |
951 | sv_setiv (SvRV (sv), 0); |
986 | sv_setiv (SvRV (sv), 0); |
|
|
987 | } |
|
|
988 | |
|
|
989 | static int |
|
|
990 | errno_get (pTHX_ SV *sv, MAGIC *mg) |
|
|
991 | { |
|
|
992 | if (*mg->mg_ptr == '!') // should always be the case |
|
|
993 | if (-30999 <= errno && errno <= -30800) |
|
|
994 | { |
|
|
995 | sv_setnv (sv, (NV)errno); |
|
|
996 | sv_setpv (sv, db_strerror (errno)); |
|
|
997 | SvNOK_on (sv); /* what a wonderful hack! */ |
|
|
998 | // ^^^ copied from perl sources |
|
|
999 | return 0; |
|
|
1000 | } |
|
|
1001 | |
|
|
1002 | return PL_vtbl_sv.svt_get (aTHX_ sv, mg); |
|
|
1003 | } |
|
|
1004 | |
|
|
1005 | static MGVTBL vtbl_errno; |
|
|
1006 | |
|
|
1007 | // this wonderful hack :( patches perl's $! variable to support our errno values |
|
|
1008 | static void |
|
|
1009 | patch_errno (void) |
|
|
1010 | { |
|
|
1011 | SV *sv; |
|
|
1012 | MAGIC *mg; |
|
|
1013 | |
|
|
1014 | if (!(sv = get_sv ("!", 1))) |
|
|
1015 | return; |
|
|
1016 | |
|
|
1017 | if (!(mg = mg_find (sv, PERL_MAGIC_sv))) |
|
|
1018 | return; |
|
|
1019 | |
|
|
1020 | if (mg->mg_virtual != &PL_vtbl_sv) |
|
|
1021 | return; |
|
|
1022 | |
|
|
1023 | vtbl_errno = PL_vtbl_sv; |
|
|
1024 | vtbl_errno.svt_get = errno_get; |
|
|
1025 | mg->mg_virtual = &vtbl_errno; |
952 | } |
1026 | } |
953 | |
1027 | |
954 | MODULE = BDB PACKAGE = BDB |
1028 | MODULE = BDB PACKAGE = BDB |
955 | |
1029 | |
956 | PROTOTYPES: ENABLE |
1030 | PROTOTYPES: ENABLE |
… | |
… | |
1028 | const_iv (GET_BOTH_RANGE) |
1102 | const_iv (GET_BOTH_RANGE) |
1029 | //const_iv (SET_RECNO) |
1103 | //const_iv (SET_RECNO) |
1030 | //const_iv (MULTIPLE) |
1104 | //const_iv (MULTIPLE) |
1031 | const_iv (SNAPSHOT) |
1105 | const_iv (SNAPSHOT) |
1032 | const_iv (JOIN_ITEM) |
1106 | const_iv (JOIN_ITEM) |
|
|
1107 | const_iv (JOIN_NOSORT) |
1033 | const_iv (RMW) |
1108 | const_iv (RMW) |
1034 | |
1109 | |
1035 | const_iv (NOTFOUND) |
1110 | const_iv (NOTFOUND) |
1036 | const_iv (KEYEMPTY) |
1111 | const_iv (KEYEMPTY) |
1037 | const_iv (LOCK_DEADLOCK) |
1112 | const_iv (LOCK_DEADLOCK) |
… | |
… | |
1053 | const_iv (TXN_SYNC) |
1128 | const_iv (TXN_SYNC) |
1054 | |
1129 | |
1055 | const_iv (SET_LOCK_TIMEOUT) |
1130 | const_iv (SET_LOCK_TIMEOUT) |
1056 | const_iv (SET_TXN_TIMEOUT) |
1131 | const_iv (SET_TXN_TIMEOUT) |
1057 | |
1132 | |
1058 | const_iv (JOIN_ITEM) |
|
|
1059 | const_iv (FIRST) |
1133 | const_iv (FIRST) |
1060 | const_iv (NEXT) |
1134 | const_iv (NEXT) |
1061 | const_iv (NEXT_DUP) |
1135 | const_iv (NEXT_DUP) |
1062 | const_iv (NEXT_NODUP) |
1136 | const_iv (NEXT_NODUP) |
1063 | const_iv (PREV) |
1137 | const_iv (PREV) |
… | |
… | |
1129 | const_iv (MULTIVERSION) |
1203 | const_iv (MULTIVERSION) |
1130 | const_iv (TXN_SNAPSHOT) |
1204 | const_iv (TXN_SNAPSHOT) |
1131 | #endif |
1205 | #endif |
1132 | #if DB_VERSION_MINOR >= 6 |
1206 | #if DB_VERSION_MINOR >= 6 |
1133 | const_iv (PREV_DUP) |
1207 | const_iv (PREV_DUP) |
1134 | # if 0 |
|
|
1135 | const_iv (PRIORITY_UNCHANGED) |
1208 | const_iv (PRIORITY_UNCHANGED) |
1136 | const_iv (PRIORITY_VERY_LOW) |
1209 | const_iv (PRIORITY_VERY_LOW) |
1137 | const_iv (PRIORITY_LOW) |
1210 | const_iv (PRIORITY_LOW) |
1138 | const_iv (PRIORITY_DEFAULT) |
1211 | const_iv (PRIORITY_DEFAULT) |
1139 | const_iv (PRIORITY_HIGH) |
1212 | const_iv (PRIORITY_HIGH) |
1140 | const_iv (PRIORITY_VERY_HIGH) |
1213 | const_iv (PRIORITY_VERY_HIGH) |
1141 | # endif |
|
|
1142 | #endif |
1214 | #endif |
1143 | }; |
1215 | }; |
1144 | |
1216 | |
1145 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1217 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1146 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1218 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
… | |
… | |
1156 | X_MUTEX_CHECK (reslock); |
1228 | X_MUTEX_CHECK (reslock); |
1157 | X_MUTEX_CHECK (reqlock); |
1229 | X_MUTEX_CHECK (reqlock); |
1158 | |
1230 | |
1159 | X_COND_CHECK (reqwait); |
1231 | X_COND_CHECK (reqwait); |
1160 | #endif |
1232 | #endif |
|
|
1233 | patch_errno (); |
1161 | } |
1234 | } |
1162 | |
1235 | |
1163 | void |
1236 | void |
1164 | max_poll_reqs (int nreqs) |
1237 | max_poll_reqs (int nreqs) |
1165 | PROTOTYPE: $ |
1238 | PROTOTYPE: $ |
… | |
… | |
1323 | } |
1396 | } |
1324 | OUTPUT: |
1397 | OUTPUT: |
1325 | RETVAL |
1398 | RETVAL |
1326 | |
1399 | |
1327 | void |
1400 | void |
1328 | db_env_open (DB_ENV *env, octetstring db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef) |
1401 | db_env_open (DB_ENV *env, bdb_filename db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef) |
1329 | CODE: |
1402 | CODE: |
1330 | { |
1403 | { |
1331 | dREQ (REQ_ENV_OPEN); |
1404 | dREQ (REQ_ENV_OPEN); |
1332 | |
|
|
1333 | env->set_thread_count (env, wanted + 2); |
|
|
1334 | |
1405 | |
1335 | req->env = env; |
1406 | req->env = env; |
1336 | req->uint1 = open_flags | DB_THREAD; |
1407 | req->uint1 = open_flags | DB_THREAD; |
1337 | req->int1 = mode; |
1408 | req->int1 = mode; |
1338 | req->buf1 = strdup_ornull (db_home); |
1409 | req->buf1 = strdup_ornull (db_home); |
… | |
… | |
1406 | } |
1477 | } |
1407 | OUTPUT: |
1478 | OUTPUT: |
1408 | RETVAL |
1479 | RETVAL |
1409 | |
1480 | |
1410 | void |
1481 | 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) |
1482 | 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) |
1412 | CODE: |
1483 | CODE: |
1413 | { |
1484 | { |
1414 | dREQ (REQ_DB_OPEN); |
1485 | dREQ (REQ_DB_OPEN); |
1415 | req->db = db; |
1486 | req->db = db; |
1416 | req->txn = txnid; |
1487 | req->txn = txnid; |
… | |
… | |
1456 | req->uint1 = flags; |
1527 | req->uint1 = flags; |
1457 | REQ_SEND; |
1528 | REQ_SEND; |
1458 | } |
1529 | } |
1459 | |
1530 | |
1460 | void |
1531 | void |
1461 | db_upgrade (DB *db, octetstring file, U32 flags = 0, SV *callback = &PL_sv_undef) |
1532 | db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = &PL_sv_undef) |
1462 | CODE: |
1533 | CODE: |
1463 | { |
1534 | { |
1464 | dREQ (REQ_DB_SYNC); |
1535 | dREQ (REQ_DB_SYNC); |
1465 | req->db = db; |
1536 | req->db = db; |
1466 | req->buf1 = strdup (file); |
1537 | req->buf1 = strdup (file); |
… | |
… | |
1495 | } |
1566 | } |
1496 | |
1567 | |
1497 | void |
1568 | void |
1498 | db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1569 | db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1499 | CODE: |
1570 | CODE: |
|
|
1571 | if (SvREADONLY (data)) |
|
|
1572 | croak ("can't modify read-only data scalar in db_get"); |
1500 | { |
1573 | { |
1501 | dREQ (REQ_DB_GET); |
1574 | dREQ (REQ_DB_GET); |
1502 | req->db = db; |
1575 | req->db = db; |
1503 | req->txn = txn; |
1576 | req->txn = txn; |
1504 | req->uint1 = flags; |
1577 | req->uint1 = flags; |
… | |
… | |
1509 | } |
1582 | } |
1510 | |
1583 | |
1511 | void |
1584 | void |
1512 | db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1585 | db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1513 | CODE: |
1586 | CODE: |
|
|
1587 | if (SvREADONLY (data)) |
|
|
1588 | croak ("can't modify read-only data scalar in db_pget"); |
1514 | { |
1589 | { |
1515 | dREQ (REQ_DB_PGET); |
1590 | dREQ (REQ_DB_PGET); |
1516 | req->db = db; |
1591 | req->db = db; |
1517 | req->txn = txn; |
1592 | req->txn = txn; |
1518 | req->uint1 = flags; |
1593 | req->uint1 = flags; |
… | |
… | |
1712 | |
1787 | |
1713 | |
1788 | |
1714 | MODULE = BDB PACKAGE = BDB::Env |
1789 | MODULE = BDB PACKAGE = BDB::Env |
1715 | |
1790 | |
1716 | void |
1791 | void |
1717 | DESTROY (DB_ENV_ornull *env) |
1792 | DESTROY (DB_ENV_ornuked *env) |
1718 | CODE: |
1793 | CODE: |
1719 | if (env) |
1794 | if (env) |
1720 | env->close (env, 0); |
1795 | env->close (env, 0); |
1721 | |
1796 | |
1722 | int set_data_dir (DB_ENV *env, const char *dir) |
1797 | int set_data_dir (DB_ENV *env, const char *dir) |
… | |
… | |
1869 | RETVAL |
1944 | RETVAL |
1870 | |
1945 | |
1871 | MODULE = BDB PACKAGE = BDB::Db |
1946 | MODULE = BDB PACKAGE = BDB::Db |
1872 | |
1947 | |
1873 | void |
1948 | void |
1874 | DESTROY (DB_ornull *db) |
1949 | DESTROY (DB_ornuked *db) |
1875 | CODE: |
1950 | CODE: |
1876 | if (db) |
1951 | if (db) |
1877 | { |
1952 | { |
1878 | SV *env = (SV *)db->app_private; |
1953 | SV *env = (SV *)db->app_private; |
1879 | db->close (db, 0); |
1954 | db->close (db, 0); |
… | |
… | |
1974 | |
2049 | |
1975 | |
2050 | |
1976 | MODULE = BDB PACKAGE = BDB::Txn |
2051 | MODULE = BDB PACKAGE = BDB::Txn |
1977 | |
2052 | |
1978 | void |
2053 | void |
1979 | DESTROY (DB_TXN_ornull *txn) |
2054 | DESTROY (DB_TXN_ornuked *txn) |
1980 | CODE: |
2055 | CODE: |
1981 | if (txn) |
2056 | if (txn) |
1982 | txn->abort (txn); |
2057 | txn->abort (txn); |
1983 | |
2058 | |
1984 | int set_timeout (DB_TXN *txn, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT) |
2059 | int set_timeout (DB_TXN *txn, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT) |
… | |
… | |
1995 | |
2070 | |
1996 | |
2071 | |
1997 | MODULE = BDB PACKAGE = BDB::Cursor |
2072 | MODULE = BDB PACKAGE = BDB::Cursor |
1998 | |
2073 | |
1999 | void |
2074 | void |
2000 | DESTROY (DBC_ornull *dbc) |
2075 | DESTROY (DBC_ornuked *dbc) |
2001 | CODE: |
2076 | CODE: |
2002 | if (dbc) |
2077 | if (dbc) |
2003 | dbc->c_close (dbc); |
2078 | dbc->c_close (dbc); |
2004 | |
2079 | |
|
|
2080 | #if DB_VERSION_MINOR >= 6 |
|
|
2081 | |
|
|
2082 | int set_priority (DBC *dbc, int priority) |
|
|
2083 | CODE: |
|
|
2084 | dbc->set_priority (dbc, priority); |
|
|
2085 | |
|
|
2086 | #endif |
|
|
2087 | |
2005 | MODULE = BDB PACKAGE = BDB::Sequence |
2088 | MODULE = BDB PACKAGE = BDB::Sequence |
2006 | |
2089 | |
2007 | void |
2090 | void |
2008 | DESTROY (DB_SEQUENCE_ornull *seq) |
2091 | DESTROY (DB_SEQUENCE_ornuked *seq) |
2009 | CODE: |
2092 | CODE: |
2010 | if (seq) |
2093 | if (seq) |
2011 | seq->close (seq, 0); |
2094 | seq->close (seq, 0); |
2012 | |
2095 | |
2013 | int initial_value (DB_SEQUENCE *seq, db_seq_t value) |
2096 | int initial_value (DB_SEQUENCE *seq, db_seq_t value) |
… | |
… | |
2032 | CODE: |
2115 | CODE: |
2033 | RETVAL = seq->set_range (seq, min, max); |
2116 | RETVAL = seq->set_range (seq, min, max); |
2034 | OUTPUT: |
2117 | OUTPUT: |
2035 | RETVAL |
2118 | RETVAL |
2036 | |
2119 | |
|
|
2120 | |