static bool tcfdbcopyimpl(TCFDB *fdb, const char *path);
static bool tcfdbiterjumpimpl(TCFDB *fdb, int64_t id);
static bool tcfdbforeachimpl(TCFDB *fdb, TCITER iter, void *op);
-static bool tcfdbftruncate(TCFDB *fdb, off_t length) __attribute__ ((unused));
+static bool tcfdbftruncate(TCFDB *fdb, off_t length) __attribute__((unused));
static bool tcfdbftruncate2(TCFDB *fdb, off_t length, int opts);
EJDB_INLINE bool tcfdblockmethod(TCFDB *fdb, bool wr);
if (vsiz > (int64_t) fdb->width) vsiz = fdb->width;
TCDODEBUG(fdb->cnt_readrec++);
uint64_t nsiz = FDBHEADSIZ + id * fdb->rsiz;
+
if (nsiz > fdb->fsiz) {
if (nsiz > fdb->limsiz) {
tcfdbsetecode(fdb, TCEINVALID, __FILE__, __LINE__, __func__);
fdb->max = id;
}
}
+ FDBUNLOCKATTR(fdb);
+ FDBUNLOCKSMEM(fdb);
+ return !err;
}
FDBUNLOCKATTR(fdb);
FDBUNLOCKSMEM(fdb);
- return !err;
}
//Take a read lock on shared mem because
static bool tcfdbftruncate2(TCFDB *fdb, off_t length, int opts) {
#ifndef _WIN32
+ bool err = false;
length = length ? tcpagealign(length) : 0;
if (!(fdb->omode & FDBOWRITER) || (length <= fdb->fsiz && !(opts & FDBTRALLOWSHRINK))) {
return true;
}
+ if (!(opts & FDBWRITENOLOCK) && !FDBLOCKSMEM2(fdb, true)) {
+ return false;
+ }
if (length > fdb->fsiz && !(opts & FDBTRALLOWSHRINK)) {
off_t o1 = tcpagealign((_maxof(off_t) - length < FDBXFSIZINC) ? length : length + FDBXFSIZINC);
off_t o2 = tcpagealign((((uint64_t) length) * 3) >> 1);
}
if (ftruncate(fdb->fd, length) == 0) {
fdb->fsiz = length;
- return true;
} else {
- return false;
+ err = true;
}
+ if (!(opts & FDBWRITENOLOCK)) FDBUNLOCKSMEM(fdb);
+ return !err;
#else
bool err = false;
LARGE_INTEGER size;
time_t mtime; /* modification time */
uint64_t limsiz; /* limit size of the file */
uint64_t rnum; /* number of the records */
- uint64_t fsiz; /* size of the database file */
+ volatile uint64_t fsiz; /* size of the database file */
uint64_t min; /* minimum ID number */
uint64_t max; /* maximum ID number */
uint64_t iter; /* ID number of the iterator */
int base = id * rnum;
for (int i = 1; i <= rnum; i++) {
char buf[RECBUFSIZ];
+
+
int len = sprintf(buf, "%08d", base + (rnd ? myrand(i) + 1 : i));
if (!tcfdbput2(fdb, buf, len, buf, len)) {
eprint(fdb, __LINE__, "tcfdbput2");
err = true;
break;
}
+
if (id == 0 && rnum > 250 && i % (rnum / 250) == 0) {
iputchar('.');
if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);