now we use inter-process locking

This commit is contained in:
krangelov
2021-10-25 19:14:25 +02:00
parent d061403ba2
commit 157574763f
4 changed files with 76 additions and 26 deletions

View File

@@ -7,6 +7,7 @@
#include <pthread.h>
#include "data.h"
#include "ipc.h"
PGF_INTERNAL __thread unsigned char* current_base __attribute__((tls_model("initial-exec"))) = NULL;
PGF_INTERNAL __thread PgfDB* current_db __attribute__((tls_model("initial-exec"))) = NULL;
@@ -344,12 +345,12 @@ PgfDB::PgfDB(const char* filepath, int flags, int mode) {
throw pgf_systemerror(code, filepath);
}
int res = pthread_rwlock_init(&rwlock, NULL);
if (res != 0) {
try {
rwlock = ipc_new_file_rwlock(this->filepath);
} catch (pgf_systemerror e) {
::free((void *) this->filepath);
int code = errno;
close(fd);
throw pgf_systemerror(code);
throw e;
}
if (is_new) {
@@ -389,7 +390,7 @@ PgfDB::~PgfDB() {
if (fd >= 0)
close(fd);
pthread_rwlock_destroy(&rwlock);
ipc_release_file_rwlock(filepath, rwlock);
::free((void*) filepath);
}
@@ -1108,8 +1109,8 @@ void PgfDB::sync()
DB_scope::DB_scope(PgfDB *db, DB_scope_mode m)
{
int res =
(m == READER_SCOPE) ? pthread_rwlock_rdlock(&db->rwlock)
: pthread_rwlock_wrlock(&db->rwlock);
(m == READER_SCOPE) ? pthread_rwlock_rdlock(db->rwlock)
: pthread_rwlock_wrlock(db->rwlock);
if (res != 0)
throw pgf_systemerror(res);
@@ -1125,9 +1126,7 @@ DB_scope::~DB_scope()
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wterminate"
int res = pthread_rwlock_unlock(&current_db->rwlock);
if (res != 0)
throw pgf_systemerror(res);
pthread_rwlock_unlock(current_db->rwlock);
current_db = save_db;
current_base = current_db ? (unsigned char*) current_db->ms