… | |
… | |
137 | } |
137 | } |
138 | |
138 | |
139 | enum { |
139 | enum { |
140 | REQ_QUIT, |
140 | REQ_QUIT, |
141 | 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, |
142 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, |
142 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME, |
143 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE, |
143 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE, |
144 | 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, |
145 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
145 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
146 | 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, |
147 | 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, |
… | |
… | |
159 | DBC *dbc; |
159 | DBC *dbc; |
160 | |
160 | |
161 | UV uv1; |
161 | UV uv1; |
162 | int int1, int2; |
162 | int int1, int2; |
163 | U32 uint1, uint2; |
163 | U32 uint1, uint2; |
164 | char *buf1, *buf2; |
164 | char *buf1, *buf2, *buf3; |
165 | SV *sv1, *sv2, *sv3; |
165 | SV *sv1, *sv2, *sv3; |
166 | |
166 | |
167 | DBT dbt1, dbt2, dbt3; |
167 | DBT dbt1, dbt2, dbt3; |
168 | DB_KEY_RANGE key_range; |
168 | DB_KEY_RANGE key_range; |
169 | DB_SEQUENCE *seq; |
169 | DB_SEQUENCE *seq; |
… | |
… | |
180 | PRI_BIAS = -PRI_MIN, |
180 | PRI_BIAS = -PRI_MIN, |
181 | NUM_PRI = PRI_MAX + PRI_BIAS + 1, |
181 | NUM_PRI = PRI_MAX + PRI_BIAS + 1, |
182 | }; |
182 | }; |
183 | |
183 | |
184 | #define AIO_TICKS ((1000000 + 1023) >> 10) |
184 | #define AIO_TICKS ((1000000 + 1023) >> 10) |
|
|
185 | |
|
|
186 | static SV *on_next_submit; |
185 | |
187 | |
186 | static unsigned int max_poll_time = 0; |
188 | static unsigned int max_poll_time = 0; |
187 | static unsigned int max_poll_reqs = 0; |
189 | static unsigned int max_poll_reqs = 0; |
188 | |
190 | |
189 | /* calculcate time difference in ~1/AIO_TICKS of a second */ |
191 | /* calculcate time difference in ~1/AIO_TICKS of a second */ |
… | |
… | |
411 | |
413 | |
412 | static void req_free (bdb_req req) |
414 | static void req_free (bdb_req req) |
413 | { |
415 | { |
414 | free (req->buf1); |
416 | free (req->buf1); |
415 | free (req->buf2); |
417 | free (req->buf2); |
|
|
418 | free (req->buf3); |
416 | Safefree (req); |
419 | Safefree (req); |
417 | } |
420 | } |
418 | |
421 | |
419 | #ifdef USE_SOCKETS_AS_HANDLES |
422 | #ifdef USE_SOCKETS_AS_HANDLES |
420 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
423 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
… | |
… | |
500 | } |
503 | } |
501 | |
504 | |
502 | static void req_send (bdb_req req) |
505 | static void req_send (bdb_req req) |
503 | { |
506 | { |
504 | 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 | } |
505 | |
520 | |
506 | // synthesize callback if none given |
521 | // synthesize callback if none given |
507 | if (!SvOK (req->callback)) |
522 | if (!SvOK (req->callback)) |
508 | { |
523 | { |
509 | int count; |
524 | int count; |
… | |
… | |
756 | req->result = req->env->memp_sync (req->env, 0); |
771 | req->result = req->env->memp_sync (req->env, 0); |
757 | break; |
772 | break; |
758 | |
773 | |
759 | case REQ_ENV_MEMP_TRICKLE: |
774 | case REQ_ENV_MEMP_TRICKLE: |
760 | 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); |
|
|
776 | break; |
|
|
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); |
761 | break; |
784 | break; |
762 | |
785 | |
763 | case REQ_DB_OPEN: |
786 | case REQ_DB_OPEN: |
764 | 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); |
765 | break; |
788 | break; |
… | |
… | |
1057 | const_iv (REGISTER) |
1080 | const_iv (REGISTER) |
1058 | const_iv (SYSTEM_MEM) |
1081 | const_iv (SYSTEM_MEM) |
1059 | const_iv (AUTO_COMMIT) |
1082 | const_iv (AUTO_COMMIT) |
1060 | const_iv (CDB_ALLDB) |
1083 | const_iv (CDB_ALLDB) |
1061 | const_iv (DIRECT_DB) |
1084 | const_iv (DIRECT_DB) |
1062 | const_iv (DIRECT_LOG) |
|
|
1063 | const_iv (DSYNC_DB) |
1085 | const_iv (DSYNC_DB) |
1064 | const_iv (DSYNC_LOG) |
|
|
1065 | const_iv (LOG_AUTOREMOVE) |
|
|
1066 | const_iv (LOG_INMEMORY) |
|
|
1067 | const_iv (NOLOCKING) |
1086 | const_iv (NOLOCKING) |
1068 | const_iv (NOMMAP) |
1087 | const_iv (NOMMAP) |
1069 | const_iv (NOPANIC) |
1088 | const_iv (NOPANIC) |
1070 | const_iv (OVERWRITE) |
1089 | const_iv (OVERWRITE) |
1071 | const_iv (PANIC_ENVIRONMENT) |
1090 | const_iv (PANIC_ENVIRONMENT) |
… | |
… | |
1210 | const_iv (PRIORITY_LOW) |
1229 | const_iv (PRIORITY_LOW) |
1211 | const_iv (PRIORITY_DEFAULT) |
1230 | const_iv (PRIORITY_DEFAULT) |
1212 | const_iv (PRIORITY_HIGH) |
1231 | const_iv (PRIORITY_HIGH) |
1213 | const_iv (PRIORITY_VERY_HIGH) |
1232 | const_iv (PRIORITY_VERY_HIGH) |
1214 | #endif |
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 |
1215 | }; |
1246 | }; |
1216 | |
1247 | |
1217 | 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; ) |
1218 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1249 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1219 | |
1250 | |
1220 | newCONSTSUB (stash, "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 | |
1221 | newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1258 | newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1222 | |
1259 | |
1223 | create_respipe (); |
1260 | create_respipe (); |
1224 | |
1261 | |
1225 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1262 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1226 | #ifdef _WIN32 |
|
|
1227 | X_MUTEX_CHECK (wrklock); |
|
|
1228 | X_MUTEX_CHECK (reslock); |
|
|
1229 | X_MUTEX_CHECK (reqlock); |
|
|
1230 | |
|
|
1231 | X_COND_CHECK (reqwait); |
|
|
1232 | #endif |
|
|
1233 | patch_errno (); |
1263 | patch_errno (); |
1234 | } |
1264 | } |
1235 | |
1265 | |
1236 | void |
1266 | void |
1237 | max_poll_reqs (int nreqs) |
1267 | max_poll_reqs (int nreqs) |
… | |
… | |
1378 | CODE: |
1408 | CODE: |
1379 | RETVAL = db_strerror (errorno); |
1409 | RETVAL = db_strerror (errorno); |
1380 | OUTPUT: |
1410 | OUTPUT: |
1381 | RETVAL |
1411 | RETVAL |
1382 | |
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 | |
1383 | DB_ENV * |
1418 | DB_ENV * |
1384 | db_env_create (U32 env_flags = 0) |
1419 | db_env_create (U32 env_flags = 0) |
1385 | CODE: |
1420 | CODE: |
1386 | { |
1421 | { |
1387 | errno = db_env_create (&RETVAL, env_flags); |
1422 | errno = db_env_create (&RETVAL, env_flags); |
… | |
… | |
1461 | req->env = env; |
1496 | req->env = env; |
1462 | req->int1 = percent; |
1497 | req->int1 = percent; |
1463 | REQ_SEND; |
1498 | REQ_SEND; |
1464 | } |
1499 | } |
1465 | |
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 | } |
1466 | |
1525 | |
1467 | DB * |
1526 | DB * |
1468 | db_create (DB_ENV *env = 0, U32 flags = 0) |
1527 | db_create (DB_ENV *env = 0, U32 flags = 0) |
1469 | CODE: |
1528 | CODE: |
1470 | { |
1529 | { |
… | |
… | |
1828 | CODE: |
1887 | CODE: |
1829 | RETVAL = env->set_flags (env, flags, onoff); |
1888 | RETVAL = env->set_flags (env, flags, onoff); |
1830 | OUTPUT: |
1889 | OUTPUT: |
1831 | RETVAL |
1890 | RETVAL |
1832 | |
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 | |
1833 | void set_errfile (DB_ENV *env, FILE *errfile = 0) |
1909 | void set_errfile (DB_ENV *env, FILE *errfile = 0) |
1834 | CODE: |
1910 | CODE: |
1835 | env->set_errfile (env, errfile); |
1911 | env->set_errfile (env, errfile); |
1836 | |
1912 | |
1837 | void set_msgfile (DB_ENV *env, FILE *msgfile = 0) |
1913 | void set_msgfile (DB_ENV *env, FILE *msgfile = 0) |