… | |
… | |
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); |
… | |
… | |
91 | } |
137 | } |
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, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME, |
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; |
… | |
… | |
113 | DBC *dbc; |
159 | DBC *dbc; |
114 | |
160 | |
115 | UV uv1; |
161 | UV uv1; |
116 | int int1, int2; |
162 | int int1, int2; |
117 | U32 uint1, uint2; |
163 | U32 uint1, uint2; |
118 | char *buf1, *buf2; |
164 | char *buf1, *buf2, *buf3; |
119 | SV *sv1, *sv2, *sv3; |
165 | SV *sv1, *sv2, *sv3; |
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); |
|
|
418 | free (req->buf3); |
364 | Safefree (req); |
419 | Safefree (req); |
365 | } |
420 | } |
366 | |
421 | |
367 | #ifdef USE_SOCKETS_AS_HANDLES |
422 | #ifdef USE_SOCKETS_AS_HANDLES |
368 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
423 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
369 | #else |
424 | #else |
370 | # define TO_SOCKET(x) (x) |
425 | # define TO_SOCKET(x) (x) |
371 | #endif |
426 | #endif |
372 | |
427 | |
373 | static void |
428 | static void |
374 | create_pipe (int fd[2]) |
429 | create_respipe (void) |
375 | { |
430 | { |
376 | #ifdef _WIN32 |
431 | #ifdef _WIN32 |
377 | int arg = 1; |
432 | int arg; /* argg */ |
|
|
433 | #endif |
|
|
434 | int old_readfd = respipe [0]; |
|
|
435 | |
|
|
436 | if (respipe [1] >= 0) |
|
|
437 | respipe_close (TO_SOCKET (respipe [1])); |
|
|
438 | |
|
|
439 | #ifdef _WIN32 |
378 | if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, fd) |
440 | 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 |
441 | #else |
382 | if (pipe (fd) |
442 | if (pipe (respipe)) |
383 | || fcntl (fd [0], F_SETFL, O_NONBLOCK) |
|
|
384 | || fcntl (fd [1], F_SETFL, O_NONBLOCK)) |
|
|
385 | #endif |
443 | #endif |
386 | croak ("unable to initialize result pipe"); |
444 | croak ("unable to initialize result pipe"); |
|
|
445 | |
|
|
446 | if (old_readfd >= 0) |
|
|
447 | { |
|
|
448 | if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) |
|
|
449 | croak ("unable to initialize result pipe(2)"); |
|
|
450 | |
|
|
451 | respipe_close (respipe [0]); |
|
|
452 | respipe [0] = old_readfd; |
|
|
453 | } |
|
|
454 | |
|
|
455 | #ifdef _WIN32 |
|
|
456 | arg = 1; |
|
|
457 | if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) |
|
|
458 | || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) |
|
|
459 | #else |
|
|
460 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) |
|
|
461 | || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
462 | #endif |
|
|
463 | croak ("unable to initialize result pipe(3)"); |
387 | |
464 | |
388 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
465 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
389 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
466 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
390 | } |
467 | } |
391 | |
468 | |
… | |
… | |
411 | free (wrk); |
488 | free (wrk); |
412 | |
489 | |
413 | X_UNLOCK (wrklock); |
490 | X_UNLOCK (wrklock); |
414 | } |
491 | } |
415 | |
492 | |
416 | static void maybe_start_thread () |
493 | static void maybe_start_thread (void) |
417 | { |
494 | { |
418 | if (get_nthreads () >= wanted) |
495 | if (get_nthreads () >= wanted) |
419 | return; |
496 | return; |
420 | |
497 | |
421 | /* todo: maybe use idle here, but might be less exact */ |
498 | /* todo: maybe use idle here, but might be less exact */ |
… | |
… | |
423 | return; |
500 | return; |
424 | |
501 | |
425 | start_thread (); |
502 | start_thread (); |
426 | } |
503 | } |
427 | |
504 | |
428 | static void req_send (aio_req req) |
505 | static void req_send (bdb_req req) |
429 | { |
506 | { |
430 | SV *wait_callback = 0; |
507 | SV *wait_callback = 0; |
|
|
508 | |
|
|
509 | if (on_next_submit) |
|
|
510 | { |
|
|
511 | dSP; |
|
|
512 | SV *cb = sv_2mortal (on_next_submit); |
|
|
513 | |
|
|
514 | on_next_submit = 0; |
|
|
515 | |
|
|
516 | PUSHMARK (SP); |
|
|
517 | PUTBACK; |
|
|
518 | call_sv (cb, G_DISCARD | G_EVAL); |
|
|
519 | } |
431 | |
520 | |
432 | // synthesize callback if none given |
521 | // synthesize callback if none given |
433 | if (!SvOK (req->callback)) |
522 | if (!SvOK (req->callback)) |
434 | { |
523 | { |
435 | int count; |
524 | int count; |
… | |
… | |
441 | SPAGAIN; |
530 | SPAGAIN; |
442 | |
531 | |
443 | if (count != 2) |
532 | if (count != 2) |
444 | croak ("prepare callback must return exactly two values\n"); |
533 | croak ("prepare callback must return exactly two values\n"); |
445 | |
534 | |
446 | wait_callback = SvREFCNT_inc (POPs); |
535 | wait_callback = POPs; |
447 | SvREFCNT_dec (req->callback); |
536 | SvREFCNT_dec (req->callback); |
448 | req->callback = SvREFCNT_inc (POPs); |
537 | req->callback = SvREFCNT_inc (POPs); |
449 | } |
538 | } |
450 | |
539 | |
451 | ++nreqs; |
540 | ++nreqs; |
… | |
… | |
462 | { |
551 | { |
463 | dSP; |
552 | dSP; |
464 | PUSHMARK (SP); |
553 | PUSHMARK (SP); |
465 | PUTBACK; |
554 | PUTBACK; |
466 | call_sv (wait_callback, G_DISCARD); |
555 | call_sv (wait_callback, G_DISCARD); |
467 | SvREFCNT_dec (wait_callback); |
|
|
468 | } |
556 | } |
469 | } |
557 | } |
470 | |
558 | |
471 | static void end_thread (void) |
559 | static void end_thread (void) |
472 | { |
560 | { |
473 | aio_req req; |
561 | bdb_req req; |
474 | |
562 | |
475 | Newz (0, req, 1, aio_cb); |
563 | Newz (0, req, 1, bdb_cb); |
476 | |
564 | |
477 | req->type = REQ_QUIT; |
565 | req->type = REQ_QUIT; |
478 | req->pri = PRI_MAX + PRI_BIAS; |
566 | req->pri = PRI_MAX + PRI_BIAS; |
479 | |
567 | |
480 | X_LOCK (reqlock); |
568 | X_LOCK (reqlock); |
… | |
… | |
507 | |
595 | |
508 | while (started > wanted) |
596 | while (started > wanted) |
509 | end_thread (); |
597 | end_thread (); |
510 | } |
598 | } |
511 | |
599 | |
512 | static void poll_wait () |
600 | static void poll_wait (void) |
513 | { |
601 | { |
514 | fd_set rfd; |
602 | fd_set rfd; |
515 | |
603 | |
516 | while (nreqs) |
604 | while (nreqs) |
517 | { |
605 | { |
… | |
… | |
530 | |
618 | |
531 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
619 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
532 | } |
620 | } |
533 | } |
621 | } |
534 | |
622 | |
535 | static int poll_cb () |
623 | static int poll_cb (void) |
536 | { |
624 | { |
537 | dSP; |
625 | dSP; |
538 | int count = 0; |
626 | int count = 0; |
539 | int maxreqs = max_poll_reqs; |
627 | int maxreqs = max_poll_reqs; |
540 | int do_croak = 0; |
628 | int do_croak = 0; |
541 | struct timeval tv_start, tv_now; |
629 | struct timeval tv_start, tv_now; |
542 | aio_req req; |
630 | bdb_req req; |
543 | |
631 | |
544 | if (max_poll_time) |
632 | if (max_poll_time) |
545 | gettimeofday (&tv_start, 0); |
633 | gettimeofday (&tv_start, 0); |
546 | |
634 | |
547 | for (;;) |
635 | for (;;) |
… | |
… | |
608 | |
696 | |
609 | /*****************************************************************************/ |
697 | /*****************************************************************************/ |
610 | |
698 | |
611 | X_THREAD_PROC (bdb_proc) |
699 | X_THREAD_PROC (bdb_proc) |
612 | { |
700 | { |
613 | aio_req req; |
701 | bdb_req req; |
614 | struct timespec ts; |
702 | struct timespec ts; |
615 | worker *self = (worker *)thr_arg; |
703 | worker *self = (worker *)thr_arg; |
616 | |
704 | |
617 | /* try to distribute timeouts somewhat evenly */ |
705 | /* try to distribute timeouts somewhat evenly */ |
618 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
706 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
… | |
… | |
658 | X_UNLOCK (reqlock); |
746 | X_UNLOCK (reqlock); |
659 | |
747 | |
660 | switch (req->type) |
748 | switch (req->type) |
661 | { |
749 | { |
662 | case REQ_QUIT: |
750 | case REQ_QUIT: |
|
|
751 | req->result = ENOSYS; |
663 | goto quit; |
752 | goto quit; |
664 | |
753 | |
665 | case REQ_ENV_OPEN: |
754 | case REQ_ENV_OPEN: |
666 | req->result = req->env->open (req->env, req->buf1, req->uint1, req->int1); |
755 | req->result = req->env->open (req->env, req->buf1, req->uint1, req->int1); |
667 | break; |
756 | break; |
… | |
… | |
684 | |
773 | |
685 | case REQ_ENV_MEMP_TRICKLE: |
774 | case REQ_ENV_MEMP_TRICKLE: |
686 | req->result = req->env->memp_trickle (req->env, req->int1, &req->int2); |
775 | req->result = req->env->memp_trickle (req->env, req->int1, &req->int2); |
687 | break; |
776 | break; |
688 | |
777 | |
|
|
778 | case REQ_ENV_DBREMOVE: |
|
|
779 | req->result = req->env->dbremove (req->env, req->txn, req->buf1, req->buf2, req->uint1); |
|
|
780 | break; |
|
|
781 | |
|
|
782 | case REQ_ENV_DBRENAME: |
|
|
783 | req->result = req->env->dbrename (req->env, req->txn, req->buf1, req->buf2, req->buf3, req->uint1); |
|
|
784 | break; |
|
|
785 | |
689 | case REQ_DB_OPEN: |
786 | case REQ_DB_OPEN: |
690 | req->result = req->db->open (req->db, req->txn, req->buf1, req->buf2, req->int1, req->uint1, req->int2); |
787 | req->result = req->db->open (req->db, req->txn, req->buf1, req->buf2, req->int1, req->uint1, req->int2); |
691 | break; |
788 | break; |
692 | |
789 | |
693 | case REQ_DB_CLOSE: |
790 | case REQ_DB_CLOSE: |
… | |
… | |
700 | |
797 | |
701 | case REQ_DB_SYNC: |
798 | case REQ_DB_SYNC: |
702 | req->result = req->db->sync (req->db, req->uint1); |
799 | req->result = req->db->sync (req->db, req->uint1); |
703 | break; |
800 | break; |
704 | |
801 | |
|
|
802 | case REQ_DB_UPGRADE: |
|
|
803 | req->result = req->db->upgrade (req->db, req->buf1, req->uint1); |
|
|
804 | break; |
|
|
805 | |
705 | case REQ_DB_PUT: |
806 | case REQ_DB_PUT: |
706 | req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1); |
807 | req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1); |
707 | break; |
808 | break; |
708 | |
809 | |
709 | case REQ_DB_GET: |
810 | case REQ_DB_GET: |
… | |
… | |
726 | req->result = req->txn->commit (req->txn, req->uint1); |
827 | req->result = req->txn->commit (req->txn, req->uint1); |
727 | break; |
828 | break; |
728 | |
829 | |
729 | case REQ_TXN_ABORT: |
830 | case REQ_TXN_ABORT: |
730 | req->result = req->txn->abort (req->txn); |
831 | req->result = req->txn->abort (req->txn); |
|
|
832 | break; |
|
|
833 | |
|
|
834 | case REQ_TXN_FINISH: |
|
|
835 | if (req->txn->flags & TXN_DEADLOCK) |
|
|
836 | { |
|
|
837 | req->result = req->txn->abort (req->txn); |
|
|
838 | if (!req->result) |
|
|
839 | req->result = DB_LOCK_DEADLOCK; |
|
|
840 | } |
|
|
841 | else |
|
|
842 | req->result = req->txn->commit (req->txn, req->uint1); |
731 | break; |
843 | break; |
732 | |
844 | |
733 | case REQ_C_CLOSE: |
845 | case REQ_C_CLOSE: |
734 | req->result = req->dbc->c_close (req->dbc); |
846 | req->result = req->dbc->c_close (req->dbc); |
735 | break; |
847 | break; |
… | |
… | |
777 | default: |
889 | default: |
778 | req->result = ENOSYS; |
890 | req->result = ENOSYS; |
779 | break; |
891 | break; |
780 | } |
892 | } |
781 | |
893 | |
|
|
894 | if (req->txn && (req->result > 0 || req->result == DB_LOCK_NOTGRANTED)) |
|
|
895 | req->txn->flags |= TXN_DEADLOCK; |
|
|
896 | |
782 | X_LOCK (reslock); |
897 | X_LOCK (reslock); |
783 | |
898 | |
784 | ++npending; |
899 | ++npending; |
785 | |
900 | |
786 | if (!reqq_push (&res_queue, req)) |
901 | if (!reqq_push (&res_queue, req)) |
… | |
… | |
817 | X_UNLOCK (wrklock); |
932 | X_UNLOCK (wrklock); |
818 | } |
933 | } |
819 | |
934 | |
820 | static void atfork_child (void) |
935 | static void atfork_child (void) |
821 | { |
936 | { |
822 | aio_req prv; |
937 | bdb_req prv; |
823 | |
938 | |
824 | while (prv = reqq_shift (&req_queue)) |
939 | while (prv = reqq_shift (&req_queue)) |
825 | req_free (prv); |
940 | req_free (prv); |
826 | |
941 | |
827 | while (prv = reqq_shift (&res_queue)) |
942 | while (prv = reqq_shift (&res_queue)) |
… | |
… | |
842 | idle = 0; |
957 | idle = 0; |
843 | nreqs = 0; |
958 | nreqs = 0; |
844 | nready = 0; |
959 | nready = 0; |
845 | npending = 0; |
960 | npending = 0; |
846 | |
961 | |
847 | respipe_close (respipe [0]); |
|
|
848 | respipe_close (respipe [1]); |
|
|
849 | |
|
|
850 | create_pipe (respipe); |
962 | create_respipe (); |
851 | |
963 | |
852 | atfork_parent (); |
964 | atfork_parent (); |
853 | } |
965 | } |
854 | |
966 | |
855 | #define dREQ(reqtype) \ |
967 | #define dREQ(reqtype) \ |
856 | aio_req req; \ |
968 | bdb_req req; \ |
857 | int req_pri = next_pri; \ |
969 | int req_pri = next_pri; \ |
858 | next_pri = DEFAULT_PRI + PRI_BIAS; \ |
970 | next_pri = DEFAULT_PRI + PRI_BIAS; \ |
859 | \ |
971 | \ |
860 | if (SvOK (callback) && !SvROK (callback)) \ |
972 | if (SvOK (callback) && !SvROK (callback)) \ |
861 | croak ("callback must be undef or of reference type"); \ |
973 | croak ("callback must be undef or of reference type"); \ |
862 | \ |
974 | \ |
863 | Newz (0, req, 1, aio_cb); \ |
975 | Newz (0, req, 1, bdb_cb); \ |
864 | if (!req) \ |
976 | if (!req) \ |
865 | croak ("out of memory during aio_req allocation"); \ |
977 | croak ("out of memory during bdb_req allocation"); \ |
866 | \ |
978 | \ |
867 | req->callback = newSVsv (callback); \ |
979 | req->callback = newSVsv (callback); \ |
868 | req->type = (reqtype); \ |
980 | req->type = (reqtype); \ |
869 | req->pri = req_pri |
981 | req->pri = req_pri |
870 | |
982 | |
871 | #define REQ_SEND \ |
983 | #define REQ_SEND \ |
872 | req_send (req) |
984 | req_send (req) |
873 | |
985 | |
874 | #define SvPTR(var, arg, type, class, nullok) \ |
986 | #define SvPTR(var, arg, type, class, nullok) \ |
875 | if (!SvOK (arg)) \ |
987 | if (!SvOK (arg)) \ |
876 | { \ |
988 | { \ |
877 | if (!nullok) \ |
989 | if (nullok != 1) \ |
878 | croak (# var " must be a " # class " object, not undef"); \ |
990 | croak (# var " must be a " # class " object, not undef"); \ |
879 | \ |
991 | \ |
880 | (var) = 0; \ |
992 | (var) = 0; \ |
881 | } \ |
993 | } \ |
882 | else if (sv_derived_from ((arg), # class)) \ |
994 | else if (sv_derived_from ((arg), # class)) \ |
883 | { \ |
995 | { \ |
884 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
996 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
885 | (var) = INT2PTR (type, tmp); \ |
997 | (var) = INT2PTR (type, tmp); \ |
886 | if (!var) \ |
998 | if (!var && nullok != 2) \ |
887 | croak (# var " is not a valid " # class " object anymore"); \ |
999 | croak (# var " is not a valid " # class " object anymore"); \ |
888 | } \ |
1000 | } \ |
889 | else \ |
1001 | else \ |
890 | croak (# var " is not of type " # class); \ |
1002 | croak (# var " is not of type " # class); \ |
891 | \ |
1003 | \ |
… | |
… | |
893 | static void |
1005 | static void |
894 | ptr_nuke (SV *sv) |
1006 | ptr_nuke (SV *sv) |
895 | { |
1007 | { |
896 | assert (SvROK (sv)); |
1008 | assert (SvROK (sv)); |
897 | sv_setiv (SvRV (sv), 0); |
1009 | sv_setiv (SvRV (sv), 0); |
|
|
1010 | } |
|
|
1011 | |
|
|
1012 | static int |
|
|
1013 | errno_get (pTHX_ SV *sv, MAGIC *mg) |
|
|
1014 | { |
|
|
1015 | if (*mg->mg_ptr == '!') // should always be the case |
|
|
1016 | if (-30999 <= errno && errno <= -30800) |
|
|
1017 | { |
|
|
1018 | sv_setnv (sv, (NV)errno); |
|
|
1019 | sv_setpv (sv, db_strerror (errno)); |
|
|
1020 | SvNOK_on (sv); /* what a wonderful hack! */ |
|
|
1021 | // ^^^ copied from perl sources |
|
|
1022 | return 0; |
|
|
1023 | } |
|
|
1024 | |
|
|
1025 | return PL_vtbl_sv.svt_get (aTHX_ sv, mg); |
|
|
1026 | } |
|
|
1027 | |
|
|
1028 | static MGVTBL vtbl_errno; |
|
|
1029 | |
|
|
1030 | // this wonderful hack :( patches perl's $! variable to support our errno values |
|
|
1031 | static void |
|
|
1032 | patch_errno (void) |
|
|
1033 | { |
|
|
1034 | SV *sv; |
|
|
1035 | MAGIC *mg; |
|
|
1036 | |
|
|
1037 | if (!(sv = get_sv ("!", 1))) |
|
|
1038 | return; |
|
|
1039 | |
|
|
1040 | if (!(mg = mg_find (sv, PERL_MAGIC_sv))) |
|
|
1041 | return; |
|
|
1042 | |
|
|
1043 | if (mg->mg_virtual != &PL_vtbl_sv) |
|
|
1044 | return; |
|
|
1045 | |
|
|
1046 | vtbl_errno = PL_vtbl_sv; |
|
|
1047 | vtbl_errno.svt_get = errno_get; |
|
|
1048 | mg->mg_virtual = &vtbl_errno; |
898 | } |
1049 | } |
899 | |
1050 | |
900 | MODULE = BDB PACKAGE = BDB |
1051 | MODULE = BDB PACKAGE = BDB |
901 | |
1052 | |
902 | PROTOTYPES: ENABLE |
1053 | PROTOTYPES: ENABLE |
… | |
… | |
919 | const_iv (INIT_TXN) |
1070 | const_iv (INIT_TXN) |
920 | const_iv (RECOVER) |
1071 | const_iv (RECOVER) |
921 | const_iv (INIT_TXN) |
1072 | const_iv (INIT_TXN) |
922 | const_iv (RECOVER_FATAL) |
1073 | const_iv (RECOVER_FATAL) |
923 | const_iv (CREATE) |
1074 | const_iv (CREATE) |
|
|
1075 | const_iv (RDONLY) |
924 | const_iv (USE_ENVIRON) |
1076 | const_iv (USE_ENVIRON) |
925 | const_iv (USE_ENVIRON_ROOT) |
1077 | const_iv (USE_ENVIRON_ROOT) |
926 | const_iv (LOCKDOWN) |
1078 | const_iv (LOCKDOWN) |
927 | const_iv (PRIVATE) |
1079 | const_iv (PRIVATE) |
928 | const_iv (REGISTER) |
1080 | const_iv (REGISTER) |
929 | const_iv (SYSTEM_MEM) |
1081 | const_iv (SYSTEM_MEM) |
930 | const_iv (AUTO_COMMIT) |
1082 | const_iv (AUTO_COMMIT) |
931 | const_iv (CDB_ALLDB) |
1083 | const_iv (CDB_ALLDB) |
932 | const_iv (DIRECT_DB) |
1084 | const_iv (DIRECT_DB) |
933 | const_iv (DIRECT_LOG) |
|
|
934 | const_iv (DSYNC_DB) |
1085 | const_iv (DSYNC_DB) |
935 | const_iv (DSYNC_LOG) |
|
|
936 | const_iv (LOG_AUTOREMOVE) |
|
|
937 | const_iv (LOG_INMEMORY) |
|
|
938 | const_iv (NOLOCKING) |
1086 | const_iv (NOLOCKING) |
939 | const_iv (NOMMAP) |
1087 | const_iv (NOMMAP) |
940 | const_iv (NOPANIC) |
1088 | const_iv (NOPANIC) |
941 | const_iv (OVERWRITE) |
1089 | const_iv (OVERWRITE) |
942 | const_iv (PANIC_ENVIRONMENT) |
1090 | const_iv (PANIC_ENVIRONMENT) |
943 | const_iv (REGION_INIT) |
1091 | const_iv (REGION_INIT) |
944 | const_iv (TIME_NOTGRANTED) |
1092 | const_iv (TIME_NOTGRANTED) |
945 | const_iv (TXN_NOSYNC) |
1093 | const_iv (TXN_NOSYNC) |
|
|
1094 | const_iv (TXN_NOT_DURABLE) |
946 | const_iv (TXN_WRITE_NOSYNC) |
1095 | const_iv (TXN_WRITE_NOSYNC) |
947 | const_iv (WRITECURSOR) |
1096 | const_iv (WRITECURSOR) |
948 | const_iv (YIELDCPU) |
1097 | const_iv (YIELDCPU) |
949 | const_iv (ENCRYPT_AES) |
1098 | const_iv (ENCRYPT_AES) |
950 | const_iv (XA_CREATE) |
1099 | const_iv (XA_CREATE) |
… | |
… | |
958 | const_iv (READ_UNCOMMITTED) |
1107 | const_iv (READ_UNCOMMITTED) |
959 | const_iv (TRUNCATE) |
1108 | const_iv (TRUNCATE) |
960 | const_iv (NOSYNC) |
1109 | const_iv (NOSYNC) |
961 | const_iv (CHKSUM) |
1110 | const_iv (CHKSUM) |
962 | const_iv (ENCRYPT) |
1111 | const_iv (ENCRYPT) |
963 | const_iv (TXN_NOT_DURABLE) |
|
|
964 | const_iv (DUP) |
1112 | const_iv (DUP) |
965 | const_iv (DUPSORT) |
1113 | const_iv (DUPSORT) |
966 | const_iv (RECNUM) |
1114 | const_iv (RECNUM) |
967 | const_iv (RENUMBER) |
1115 | const_iv (RENUMBER) |
968 | const_iv (REVSPLITOFF) |
1116 | const_iv (REVSPLITOFF) |
… | |
… | |
973 | const_iv (GET_BOTH_RANGE) |
1121 | const_iv (GET_BOTH_RANGE) |
974 | //const_iv (SET_RECNO) |
1122 | //const_iv (SET_RECNO) |
975 | //const_iv (MULTIPLE) |
1123 | //const_iv (MULTIPLE) |
976 | const_iv (SNAPSHOT) |
1124 | const_iv (SNAPSHOT) |
977 | const_iv (JOIN_ITEM) |
1125 | const_iv (JOIN_ITEM) |
|
|
1126 | const_iv (JOIN_NOSORT) |
978 | const_iv (RMW) |
1127 | const_iv (RMW) |
979 | |
1128 | |
980 | const_iv (NOTFOUND) |
1129 | const_iv (NOTFOUND) |
981 | const_iv (KEYEMPTY) |
1130 | const_iv (KEYEMPTY) |
982 | const_iv (LOCK_DEADLOCK) |
1131 | const_iv (LOCK_DEADLOCK) |
… | |
… | |
998 | const_iv (TXN_SYNC) |
1147 | const_iv (TXN_SYNC) |
999 | |
1148 | |
1000 | const_iv (SET_LOCK_TIMEOUT) |
1149 | const_iv (SET_LOCK_TIMEOUT) |
1001 | const_iv (SET_TXN_TIMEOUT) |
1150 | const_iv (SET_TXN_TIMEOUT) |
1002 | |
1151 | |
1003 | const_iv (JOIN_ITEM) |
|
|
1004 | const_iv (FIRST) |
1152 | const_iv (FIRST) |
1005 | const_iv (NEXT) |
1153 | const_iv (NEXT) |
1006 | const_iv (NEXT_DUP) |
1154 | const_iv (NEXT_DUP) |
1007 | const_iv (NEXT_NODUP) |
1155 | const_iv (NEXT_NODUP) |
1008 | const_iv (PREV) |
1156 | const_iv (PREV) |
… | |
… | |
1042 | const_iv (LOG_BUFFER_FULL) |
1190 | const_iv (LOG_BUFFER_FULL) |
1043 | const_iv (NOSERVER) |
1191 | const_iv (NOSERVER) |
1044 | const_iv (NOSERVER_HOME) |
1192 | const_iv (NOSERVER_HOME) |
1045 | const_iv (NOSERVER_ID) |
1193 | const_iv (NOSERVER_ID) |
1046 | const_iv (NOTFOUND) |
1194 | const_iv (NOTFOUND) |
1047 | const_iv (OLD_VERSION) |
|
|
1048 | const_iv (PAGE_NOTFOUND) |
1195 | const_iv (PAGE_NOTFOUND) |
1049 | const_iv (REP_DUPMASTER) |
1196 | const_iv (REP_DUPMASTER) |
1050 | const_iv (REP_HANDLE_DEAD) |
1197 | const_iv (REP_HANDLE_DEAD) |
1051 | const_iv (REP_HOLDELECTION) |
1198 | const_iv (REP_HOLDELECTION) |
1052 | const_iv (REP_IGNORE) |
1199 | const_iv (REP_IGNORE) |
… | |
… | |
1073 | const_iv (VERSION_PATCH) |
1220 | const_iv (VERSION_PATCH) |
1074 | #if DB_VERSION_MINOR >= 5 |
1221 | #if DB_VERSION_MINOR >= 5 |
1075 | const_iv (MULTIVERSION) |
1222 | const_iv (MULTIVERSION) |
1076 | const_iv (TXN_SNAPSHOT) |
1223 | const_iv (TXN_SNAPSHOT) |
1077 | #endif |
1224 | #endif |
|
|
1225 | #if DB_VERSION_MINOR >= 6 |
|
|
1226 | const_iv (PREV_DUP) |
|
|
1227 | const_iv (PRIORITY_UNCHANGED) |
|
|
1228 | const_iv (PRIORITY_VERY_LOW) |
|
|
1229 | const_iv (PRIORITY_LOW) |
|
|
1230 | const_iv (PRIORITY_DEFAULT) |
|
|
1231 | const_iv (PRIORITY_HIGH) |
|
|
1232 | const_iv (PRIORITY_VERY_HIGH) |
|
|
1233 | #endif |
|
|
1234 | #if DB_VERSION_MINOR >= 7 |
|
|
1235 | const_iv (LOG_DIRECT) |
|
|
1236 | const_iv (LOG_DSYNC) |
|
|
1237 | const_iv (LOG_AUTO_REMOVE) |
|
|
1238 | const_iv (LOG_IN_MEMORY) |
|
|
1239 | const_iv (LOG_ZERO) |
|
|
1240 | #else |
|
|
1241 | const_iv (DIRECT_LOG) |
|
|
1242 | const_iv (DSYNC_LOG) |
|
|
1243 | const_iv (LOG_AUTOREMOVE) |
|
|
1244 | const_iv (LOG_INMEMORY) |
|
|
1245 | #endif |
1078 | }; |
1246 | }; |
1079 | |
1247 | |
1080 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1248 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1081 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1249 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1082 | |
1250 | |
1083 | newCONSTSUB (stash, "DB_VERSION", newSVnv (DB_VERSION_MAJOR + DB_VERSION_MINOR * .1)); |
1251 | { |
|
|
1252 | /* we currently only allow version, minor-version and patchlevel to go up to 255 */ |
|
|
1253 | char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; |
|
|
1254 | |
|
|
1255 | newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); |
|
|
1256 | } |
|
|
1257 | |
1084 | newCONSTSUB (stash, "DB_VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1258 | newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1085 | |
1259 | |
1086 | create_pipe (respipe); |
1260 | create_respipe (); |
1087 | |
1261 | |
1088 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1262 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1089 | #ifdef _WIN32 |
1263 | patch_errno (); |
1090 | X_MUTEX_CHECK (wrklock); |
|
|
1091 | X_MUTEX_CHECK (reslock); |
|
|
1092 | X_MUTEX_CHECK (reqlock); |
|
|
1093 | |
|
|
1094 | X_COND_CHECK (reqwait); |
|
|
1095 | #endif |
|
|
1096 | } |
1264 | } |
1097 | |
1265 | |
1098 | void |
1266 | void |
1099 | max_poll_reqs (int nreqs) |
1267 | max_poll_reqs (int nreqs) |
1100 | PROTOTYPE: $ |
1268 | PROTOTYPE: $ |
… | |
… | |
1240 | CODE: |
1408 | CODE: |
1241 | RETVAL = db_strerror (errorno); |
1409 | RETVAL = db_strerror (errorno); |
1242 | OUTPUT: |
1410 | OUTPUT: |
1243 | RETVAL |
1411 | RETVAL |
1244 | |
1412 | |
|
|
1413 | void _on_next_submit (SV *cb) |
|
|
1414 | CODE: |
|
|
1415 | SvREFCNT_dec (on_next_submit); |
|
|
1416 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
|
|
1417 | |
1245 | DB_ENV * |
1418 | DB_ENV * |
1246 | db_env_create (U32 env_flags = 0) |
1419 | db_env_create (U32 env_flags = 0) |
1247 | CODE: |
1420 | CODE: |
1248 | { |
1421 | { |
1249 | errno = db_env_create (&RETVAL, env_flags); |
1422 | errno = db_env_create (&RETVAL, env_flags); |
… | |
… | |
1258 | } |
1431 | } |
1259 | OUTPUT: |
1432 | OUTPUT: |
1260 | RETVAL |
1433 | RETVAL |
1261 | |
1434 | |
1262 | void |
1435 | void |
1263 | db_env_open (DB_ENV *env, octetstring db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef) |
1436 | db_env_open (DB_ENV *env, bdb_filename db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef) |
1264 | CODE: |
1437 | CODE: |
1265 | { |
1438 | { |
1266 | dREQ (REQ_ENV_OPEN); |
1439 | dREQ (REQ_ENV_OPEN); |
1267 | |
|
|
1268 | env->set_thread_count (env, wanted + 2); |
|
|
1269 | |
1440 | |
1270 | req->env = env; |
1441 | req->env = env; |
1271 | req->uint1 = open_flags | DB_THREAD; |
1442 | req->uint1 = open_flags | DB_THREAD; |
1272 | req->int1 = mode; |
1443 | req->int1 = mode; |
1273 | req->buf1 = strdup_ornull (db_home); |
1444 | req->buf1 = strdup_ornull (db_home); |
… | |
… | |
1325 | req->env = env; |
1496 | req->env = env; |
1326 | req->int1 = percent; |
1497 | req->int1 = percent; |
1327 | REQ_SEND; |
1498 | REQ_SEND; |
1328 | } |
1499 | } |
1329 | |
1500 | |
|
|
1501 | void |
|
|
1502 | db_env_dbremove (DB_ENV *env, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, U32 flags = 0, SV *callback = &PL_sv_undef) |
|
|
1503 | CODE: |
|
|
1504 | { |
|
|
1505 | dREQ (REQ_ENV_DBREMOVE); |
|
|
1506 | req->env = env; |
|
|
1507 | req->buf1 = strdup_ornull (file); |
|
|
1508 | req->buf2 = strdup_ornull (database); |
|
|
1509 | req->uint1 = flags; |
|
|
1510 | REQ_SEND; |
|
|
1511 | } |
|
|
1512 | |
|
|
1513 | void |
|
|
1514 | db_env_dbrename (DB_ENV *env, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, bdb_filename newname, U32 flags = 0, SV *callback = &PL_sv_undef) |
|
|
1515 | CODE: |
|
|
1516 | { |
|
|
1517 | dREQ (REQ_ENV_DBRENAME); |
|
|
1518 | req->env = env; |
|
|
1519 | req->buf1 = strdup_ornull (file); |
|
|
1520 | req->buf2 = strdup_ornull (database); |
|
|
1521 | req->buf3 = strdup_ornull (newname); |
|
|
1522 | req->uint1 = flags; |
|
|
1523 | REQ_SEND; |
|
|
1524 | } |
1330 | |
1525 | |
1331 | DB * |
1526 | DB * |
1332 | db_create (DB_ENV *env = 0, U32 flags = 0) |
1527 | db_create (DB_ENV *env = 0, U32 flags = 0) |
1333 | CODE: |
1528 | CODE: |
1334 | { |
1529 | { |
… | |
… | |
1341 | } |
1536 | } |
1342 | OUTPUT: |
1537 | OUTPUT: |
1343 | RETVAL |
1538 | RETVAL |
1344 | |
1539 | |
1345 | void |
1540 | void |
1346 | db_open (DB *db, DB_TXN_ornull *txnid, octetstring file, octetstring database, int type, U32 flags, int mode, SV *callback = &PL_sv_undef) |
1541 | 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) |
1347 | CODE: |
1542 | CODE: |
1348 | { |
1543 | { |
1349 | dREQ (REQ_DB_OPEN); |
1544 | dREQ (REQ_DB_OPEN); |
1350 | req->db = db; |
1545 | req->db = db; |
1351 | req->txn = txnid; |
1546 | req->txn = txnid; |
… | |
… | |
1391 | req->uint1 = flags; |
1586 | req->uint1 = flags; |
1392 | REQ_SEND; |
1587 | REQ_SEND; |
1393 | } |
1588 | } |
1394 | |
1589 | |
1395 | void |
1590 | void |
|
|
1591 | db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = &PL_sv_undef) |
|
|
1592 | CODE: |
|
|
1593 | { |
|
|
1594 | dREQ (REQ_DB_SYNC); |
|
|
1595 | req->db = db; |
|
|
1596 | req->buf1 = strdup (file); |
|
|
1597 | req->uint1 = flags; |
|
|
1598 | REQ_SEND; |
|
|
1599 | } |
|
|
1600 | |
|
|
1601 | void |
1396 | db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = &PL_sv_undef) |
1602 | db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = &PL_sv_undef) |
1397 | CODE: |
1603 | CODE: |
1398 | { |
1604 | { |
1399 | dREQ (REQ_DB_KEY_RANGE); |
1605 | dREQ (REQ_DB_KEY_RANGE); |
1400 | req->db = db; |
1606 | req->db = db; |
… | |
… | |
1419 | } |
1625 | } |
1420 | |
1626 | |
1421 | void |
1627 | void |
1422 | db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1628 | db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1423 | CODE: |
1629 | CODE: |
|
|
1630 | if (SvREADONLY (data)) |
|
|
1631 | croak ("can't modify read-only data scalar in db_get"); |
1424 | { |
1632 | { |
1425 | dREQ (REQ_DB_GET); |
1633 | dREQ (REQ_DB_GET); |
1426 | req->db = db; |
1634 | req->db = db; |
1427 | req->txn = txn; |
1635 | req->txn = txn; |
1428 | req->uint1 = flags; |
1636 | req->uint1 = flags; |
… | |
… | |
1433 | } |
1641 | } |
1434 | |
1642 | |
1435 | void |
1643 | void |
1436 | db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1644 | db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
1437 | CODE: |
1645 | CODE: |
|
|
1646 | if (SvREADONLY (data)) |
|
|
1647 | croak ("can't modify read-only data scalar in db_pget"); |
1438 | { |
1648 | { |
1439 | dREQ (REQ_DB_PGET); |
1649 | dREQ (REQ_DB_PGET); |
1440 | req->db = db; |
1650 | req->db = db; |
1441 | req->txn = txn; |
1651 | req->txn = txn; |
1442 | req->uint1 = flags; |
1652 | req->uint1 = flags; |
… | |
… | |
1479 | REQ_SEND; |
1689 | REQ_SEND; |
1480 | ptr_nuke (ST (0)); |
1690 | ptr_nuke (ST (0)); |
1481 | } |
1691 | } |
1482 | |
1692 | |
1483 | void |
1693 | void |
|
|
1694 | db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = &PL_sv_undef) |
|
|
1695 | CODE: |
|
|
1696 | { |
|
|
1697 | dREQ (REQ_TXN_FINISH); |
|
|
1698 | req->txn = txn; |
|
|
1699 | req->uint1 = flags; |
|
|
1700 | REQ_SEND; |
|
|
1701 | ptr_nuke (ST (0)); |
|
|
1702 | } |
|
|
1703 | |
|
|
1704 | void |
1484 | db_c_close (DBC *dbc, SV *callback = &PL_sv_undef) |
1705 | db_c_close (DBC *dbc, SV *callback = &PL_sv_undef) |
1485 | CODE: |
1706 | CODE: |
1486 | { |
1707 | { |
1487 | dREQ (REQ_C_CLOSE); |
1708 | dREQ (REQ_C_CLOSE); |
1488 | req->dbc = dbc; |
1709 | req->dbc = dbc; |
… | |
… | |
1625 | |
1846 | |
1626 | |
1847 | |
1627 | MODULE = BDB PACKAGE = BDB::Env |
1848 | MODULE = BDB PACKAGE = BDB::Env |
1628 | |
1849 | |
1629 | void |
1850 | void |
1630 | DESTROY (DB_ENV_ornull *env) |
1851 | DESTROY (DB_ENV_ornuked *env) |
1631 | CODE: |
1852 | CODE: |
1632 | if (env) |
1853 | if (env) |
1633 | env->close (env, 0); |
1854 | env->close (env, 0); |
1634 | |
1855 | |
1635 | int set_data_dir (DB_ENV *env, const char *dir) |
1856 | int set_data_dir (DB_ENV *env, const char *dir) |
… | |
… | |
1660 | CODE: |
1881 | CODE: |
1661 | RETVAL = env->set_cachesize (env, gbytes, bytes, ncache); |
1882 | RETVAL = env->set_cachesize (env, gbytes, bytes, ncache); |
1662 | OUTPUT: |
1883 | OUTPUT: |
1663 | RETVAL |
1884 | RETVAL |
1664 | |
1885 | |
1665 | int set_flags (DB_ENV *env, U32 flags, int onoff) |
1886 | int set_flags (DB_ENV *env, U32 flags, int onoff = 1) |
1666 | CODE: |
1887 | CODE: |
1667 | RETVAL = env->set_flags (env, flags, onoff); |
1888 | RETVAL = env->set_flags (env, flags, onoff); |
1668 | OUTPUT: |
1889 | OUTPUT: |
1669 | RETVAL |
1890 | RETVAL |
1670 | |
1891 | |
|
|
1892 | #if DB_VERSION_MINOR >= 7 |
|
|
1893 | |
|
|
1894 | int set_intermediate_dir_mode (DB_ENV *env, const char *mode) |
|
|
1895 | CODE: |
|
|
1896 | RETVAL = env->set_intermediate_dir_mode (env, mode); |
|
|
1897 | OUTPUT: |
|
|
1898 | RETVAL |
|
|
1899 | |
|
|
1900 | int log_set_config (DB_ENV *env, U32 flags, int onoff = 1) |
|
|
1901 | CODE: |
|
|
1902 | RETVAL = env->log_set_config (env, flags, onoff); |
|
|
1903 | OUTPUT: |
|
|
1904 | RETVAL |
|
|
1905 | |
|
|
1906 | #endif |
|
|
1907 | |
|
|
1908 | |
1671 | void set_errfile (DB_ENV *env, FILE *errfile) |
1909 | void set_errfile (DB_ENV *env, FILE *errfile = 0) |
1672 | CODE: |
1910 | CODE: |
1673 | env->set_errfile (env, errfile); |
1911 | env->set_errfile (env, errfile); |
1674 | |
1912 | |
1675 | void set_msgfile (DB_ENV *env, FILE *msgfile) |
1913 | void set_msgfile (DB_ENV *env, FILE *msgfile = 0) |
1676 | CODE: |
1914 | CODE: |
1677 | env->set_msgfile (env, msgfile); |
1915 | env->set_msgfile (env, msgfile); |
1678 | |
1916 | |
1679 | int set_verbose (DB_ENV *env, U32 which, int onoff = 1) |
1917 | int set_verbose (DB_ENV *env, U32 which = -1, int onoff = 1) |
1680 | CODE: |
1918 | CODE: |
1681 | RETVAL = env->set_verbose (env, which, onoff); |
1919 | RETVAL = env->set_verbose (env, which, onoff); |
1682 | OUTPUT: |
1920 | OUTPUT: |
1683 | RETVAL |
1921 | RETVAL |
1684 | |
1922 | |
… | |
… | |
1686 | CODE: |
1924 | CODE: |
1687 | RETVAL = env->set_encrypt (env, password, flags); |
1925 | RETVAL = env->set_encrypt (env, password, flags); |
1688 | OUTPUT: |
1926 | OUTPUT: |
1689 | RETVAL |
1927 | RETVAL |
1690 | |
1928 | |
1691 | int set_timeout (DB_ENV *env, NV timeout, U32 flags) |
1929 | int set_timeout (DB_ENV *env, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT) |
1692 | CODE: |
1930 | CODE: |
1693 | RETVAL = env->set_timeout (env, timeout * 1000000, flags); |
1931 | RETVAL = env->set_timeout (env, timeout * 1000000, flags); |
1694 | OUTPUT: |
1932 | OUTPUT: |
1695 | RETVAL |
1933 | RETVAL |
1696 | |
1934 | |
… | |
… | |
1744 | |
1982 | |
1745 | int set_lg_max (DB_ENV *env, U32 max) |
1983 | int set_lg_max (DB_ENV *env, U32 max) |
1746 | CODE: |
1984 | CODE: |
1747 | RETVAL = env->set_lg_max (env, max); |
1985 | RETVAL = env->set_lg_max (env, max); |
1748 | OUTPUT: |
1986 | OUTPUT: |
|
|
1987 | RETVAL |
|
|
1988 | |
|
|
1989 | int mutex_set_max (DB_ENV *env, U32 max) |
|
|
1990 | CODE: |
|
|
1991 | RETVAL = env->mutex_set_max (env, max); |
|
|
1992 | OUTPUT: |
|
|
1993 | RETVAL |
|
|
1994 | |
|
|
1995 | int mutex_set_increment (DB_ENV *env, U32 increment) |
|
|
1996 | CODE: |
|
|
1997 | RETVAL = env->mutex_set_increment (env, increment); |
|
|
1998 | OUTPUT: |
|
|
1999 | RETVAL |
|
|
2000 | |
|
|
2001 | int mutex_set_tas_spins (DB_ENV *env, U32 tas_spins) |
|
|
2002 | CODE: |
|
|
2003 | RETVAL = env->mutex_set_tas_spins (env, tas_spins); |
|
|
2004 | OUTPUT: |
|
|
2005 | RETVAL |
|
|
2006 | |
|
|
2007 | int mutex_set_align (DB_ENV *env, U32 align) |
|
|
2008 | CODE: |
|
|
2009 | RETVAL = env->mutex_set_align (env, align); |
|
|
2010 | OUTPUT: |
1749 | RETVAL |
2011 | RETVAL |
1750 | |
2012 | |
1751 | DB_TXN * |
2013 | DB_TXN * |
1752 | txn_begin (DB_ENV *env, DB_TXN_ornull *parent = 0, U32 flags = 0) |
2014 | txn_begin (DB_ENV *env, DB_TXN_ornull *parent = 0, U32 flags = 0) |
1753 | CODE: |
2015 | CODE: |
… | |
… | |
1758 | RETVAL |
2020 | RETVAL |
1759 | |
2021 | |
1760 | MODULE = BDB PACKAGE = BDB::Db |
2022 | MODULE = BDB PACKAGE = BDB::Db |
1761 | |
2023 | |
1762 | void |
2024 | void |
1763 | DESTROY (DB_ornull *db) |
2025 | DESTROY (DB_ornuked *db) |
1764 | CODE: |
2026 | CODE: |
1765 | if (db) |
2027 | if (db) |
1766 | { |
2028 | { |
1767 | SV *env = (SV *)db->app_private; |
2029 | SV *env = (SV *)db->app_private; |
1768 | db->close (db, 0); |
2030 | db->close (db, 0); |
… | |
… | |
1773 | CODE: |
2035 | CODE: |
1774 | RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); |
2036 | RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); |
1775 | OUTPUT: |
2037 | OUTPUT: |
1776 | RETVAL |
2038 | RETVAL |
1777 | |
2039 | |
1778 | int set_flags (DB *db, U32 flags); |
2040 | int set_flags (DB *db, U32 flags) |
1779 | CODE: |
2041 | CODE: |
1780 | RETVAL = db->set_flags (db, flags); |
2042 | RETVAL = db->set_flags (db, flags); |
1781 | OUTPUT: |
2043 | OUTPUT: |
1782 | RETVAL |
2044 | RETVAL |
1783 | |
2045 | |
… | |
… | |
1797 | CODE: |
2059 | CODE: |
1798 | RETVAL = db->set_bt_minkey (db, minkey); |
2060 | RETVAL = db->set_bt_minkey (db, minkey); |
1799 | OUTPUT: |
2061 | OUTPUT: |
1800 | RETVAL |
2062 | RETVAL |
1801 | |
2063 | |
1802 | int set_re_delim(DB *db, int delim); |
2064 | int set_re_delim (DB *db, int delim) |
1803 | CODE: |
2065 | CODE: |
1804 | RETVAL = db->set_re_delim (db, delim); |
2066 | RETVAL = db->set_re_delim (db, delim); |
1805 | OUTPUT: |
2067 | OUTPUT: |
1806 | RETVAL |
2068 | RETVAL |
1807 | |
2069 | |
… | |
… | |
1863 | |
2125 | |
1864 | |
2126 | |
1865 | MODULE = BDB PACKAGE = BDB::Txn |
2127 | MODULE = BDB PACKAGE = BDB::Txn |
1866 | |
2128 | |
1867 | void |
2129 | void |
1868 | DESTROY (DB_TXN_ornull *txn) |
2130 | DESTROY (DB_TXN_ornuked *txn) |
1869 | CODE: |
2131 | CODE: |
1870 | if (txn) |
2132 | if (txn) |
1871 | txn->abort (txn); |
2133 | txn->abort (txn); |
1872 | |
2134 | |
1873 | int set_timeout (DB_TXN *txn, NV timeout, U32 flags) |
2135 | int set_timeout (DB_TXN *txn, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT) |
1874 | CODE: |
2136 | CODE: |
1875 | RETVAL = txn->set_timeout (txn, timeout * 1000000, flags); |
2137 | RETVAL = txn->set_timeout (txn, timeout * 1000000, flags); |
1876 | OUTPUT: |
2138 | OUTPUT: |
1877 | RETVAL |
2139 | RETVAL |
1878 | |
2140 | |
|
|
2141 | int failed (DB_TXN *txn) |
|
|
2142 | CODE: |
|
|
2143 | RETVAL = !!(txn->flags & TXN_DEADLOCK); |
|
|
2144 | OUTPUT: |
|
|
2145 | RETVAL |
|
|
2146 | |
1879 | |
2147 | |
1880 | MODULE = BDB PACKAGE = BDB::Cursor |
2148 | MODULE = BDB PACKAGE = BDB::Cursor |
1881 | |
2149 | |
1882 | void |
2150 | void |
1883 | DESTROY (DBC_ornull *dbc) |
2151 | DESTROY (DBC_ornuked *dbc) |
1884 | CODE: |
2152 | CODE: |
1885 | if (dbc) |
2153 | if (dbc) |
1886 | dbc->c_close (dbc); |
2154 | dbc->c_close (dbc); |
1887 | |
2155 | |
|
|
2156 | #if DB_VERSION_MINOR >= 6 |
|
|
2157 | |
|
|
2158 | int set_priority (DBC *dbc, int priority) |
|
|
2159 | CODE: |
|
|
2160 | dbc->set_priority (dbc, priority); |
|
|
2161 | |
|
|
2162 | #endif |
|
|
2163 | |
1888 | MODULE = BDB PACKAGE = BDB::Sequence |
2164 | MODULE = BDB PACKAGE = BDB::Sequence |
1889 | |
2165 | |
1890 | void |
2166 | void |
1891 | DESTROY (DB_SEQUENCE_ornull *seq) |
2167 | DESTROY (DB_SEQUENCE_ornuked *seq) |
1892 | CODE: |
2168 | CODE: |
1893 | if (seq) |
2169 | if (seq) |
1894 | seq->close (seq, 0); |
2170 | seq->close (seq, 0); |
1895 | |
2171 | |
1896 | int initial_value (DB_SEQUENCE *seq, db_seq_t value) |
2172 | int initial_value (DB_SEQUENCE *seq, db_seq_t value) |
… | |
… | |
1915 | CODE: |
2191 | CODE: |
1916 | RETVAL = seq->set_range (seq, min, max); |
2192 | RETVAL = seq->set_range (seq, min, max); |
1917 | OUTPUT: |
2193 | OUTPUT: |
1918 | RETVAL |
2194 | RETVAL |
1919 | |
2195 | |
|
|
2196 | |