static bool OpenTokyoDatabase(const char *filename, TCHDB **hdb) { *hdb = tchdbnew(); if (!tchdbsetmutex(*hdb)) { return false; } if (!tchdbopen(*hdb, filename, HDBOWRITER | HDBOCREAT)) { return false; } static int threshold = -1; /* GLOBAL_X */ if (threshold == -1) { /** Optimize always if TCDB_OPTIMIZE_PERCENT is equal to 100 Never optimize if TCDB_OPTIMIZE_PERCENT is equal to 0 */ const char *perc = getenv("TCDB_OPTIMIZE_PERCENT"); if (perc != NULL) { /* Environment variable exists */ char *end; long result = strtol(perc, &end, 10); /* Environment variable is a number and in 0..100 range */ if (!*end && result >-1 && result < 101) { threshold = 100 - (int)result; } else { /* This corresponds to 1% */ threshold = 99; } } else { /* This corresponds to 1% */ threshold = 99; } } if ((threshold != 100) && (threshold == 0 || (int)(rand()%threshold) == 0)) { if (!tchdboptimize(*hdb, -1, -1, -1, false)) { tchdbclose(*hdb); return false; } } return true; }
static bool OpenTokyoDatabase(const char *filename, TCHDB **hdb) { *hdb = tchdbnew(); if (!tchdbsetmutex(*hdb)) { return false; } if (!tchdbopen(*hdb, filename, HDBOWRITER | HDBOCREAT)) { return false; } return true; }
bool db_obj_local::dbsetmutex() { return tchdbsetmutex(_hdb); }
/* initialize */ JNIEXPORT void JNICALL Java_tokyocabinet_HDB_initialize(JNIEnv *env, jobject self){ TCHDB *hdb = tchdbnew(); tchdbsetmutex(hdb); (*env)->SetLongField(env, self, hdb_fid_ptr, (intptr_t)hdb); }