From 9804d993e4bb3f32a249b0f9281899948423a90f Mon Sep 17 00:00:00 2001 From: krangelov Date: Wed, 10 Nov 2021 17:27:45 +0100 Subject: [PATCH] remove the dependency to pthread on Windows --- src/runtime/c/pgf/db.cxx | 8 +++----- src/runtime/c/pgf/db.h | 4 +++- src/runtime/c/pgf/ipc.cxx | 34 ++++++++++++++++++++++++++-------- src/runtime/c/pgf/ipc.h | 18 +++++++++++++++--- 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/src/runtime/c/pgf/db.cxx b/src/runtime/c/pgf/db.cxx index b929eb9b0..1bbb77748 100644 --- a/src/runtime/c/pgf/db.cxx +++ b/src/runtime/c/pgf/db.cxx @@ -24,8 +24,6 @@ size_t getpagesize() #define ftruncate _chsize #endif -#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; PGF_INTERNAL __thread DB_scope *last_db_scope __attribute__((tls_model("initial-exec"))) = NULL; @@ -1254,8 +1252,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) ? ipc_rwlock_rdlock(db->rwlock) + : ipc_rwlock_wrlock(db->rwlock); if (res != 0) throw pgf_systemerror(res); @@ -1271,7 +1269,7 @@ DB_scope::~DB_scope() { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wterminate" - pthread_rwlock_unlock(current_db->rwlock); + ipc_rwlock_unlock(current_db->rwlock); current_db = save_db; current_base = current_db ? (unsigned char*) current_db->ms diff --git a/src/runtime/c/pgf/db.h b/src/runtime/c/pgf/db.h index 375c3655f..0cee719b5 100644 --- a/src/runtime/c/pgf/db.h +++ b/src/runtime/c/pgf/db.h @@ -54,13 +54,15 @@ public: } }; +#include "ipc.h" + class PgfDB { private: int fd; const char *filepath; malloc_state* ms; - pthread_rwlock_t *rwlock; + ipc_rwlock_t *rwlock; #ifdef _WIN32 HANDLE hMap; diff --git a/src/runtime/c/pgf/ipc.cxx b/src/runtime/c/pgf/ipc.cxx index 911c63c4b..f09be8741 100644 --- a/src/runtime/c/pgf/ipc.cxx +++ b/src/runtime/c/pgf/ipc.cxx @@ -107,8 +107,8 @@ next: } PGF_INTERNAL -pthread_rwlock_t *ipc_new_file_rwlock(const char* file_path, - bool *is_first) +ipc_rwlock_t *ipc_new_file_rwlock(const char* file_path, + bool *is_first) { if (file_path == NULL) { *is_first = true; @@ -258,7 +258,7 @@ pthread_rwlock_t *ipc_new_file_rwlock(const char* file_path, PGF_INTERNAL void ipc_release_file_rwlock(const char* file_path, - pthread_rwlock_t *rwlock) + ipc_rwlock_t *rwlock) { if (file_path == NULL) { pthread_rwlock_destroy(rwlock); @@ -323,16 +323,34 @@ void ipc_release_file_rwlock(const char* file_path, pthread_mutex_unlock(&locks->mutex); } #else -PGF_INTERNAL_DECL -pthread_rwlock_t *ipc_new_file_rwlock(const char* file_path, - bool *is_first) +PGF_INTERNAL +int ipc_rwlock_rdlock(ipc_rwlock_t *rwlock) +{ + return 0; +} + +PGF_INTERNAL +int ipc_rwlock_wrlock(ipc_rwlock_t *rwlock) +{ + return 0; +} + +PGF_INTERNAL +int ipc_rwlock_unlock(ipc_rwlock_t *rwlock) +{ + return 0; +} + +PGF_INTERNAL +ipc_rwlock_t *ipc_new_file_rwlock(const char* file_path, + bool *is_first) { return NULL; } -PGF_INTERNAL_DECL +PGF_INTERNAL void ipc_release_file_rwlock(const char* file_path, - pthread_rwlock_t *rwlock) + ipc_rwlock_t *rwlock) { } #endif diff --git a/src/runtime/c/pgf/ipc.h b/src/runtime/c/pgf/ipc.h index 6afa34ff4..e6643e138 100644 --- a/src/runtime/c/pgf/ipc.h +++ b/src/runtime/c/pgf/ipc.h @@ -1,12 +1,24 @@ #ifndef IPC_H #define IPC_H +#ifndef _WIN32 +#define ipc_rwlock_t pthread_rwlock_t +#define ipc_rwlock_rdlock pthread_rwlock_rdlock +#define ipc_rwlock_wrlock pthread_rwlock_wrlock +#define ipc_rwlock_unlock pthread_rwlock_unlock +#else +typedef struct ipc_rwlock_t ipc_rwlock_t; +int ipc_rwlock_rdlock(ipc_rwlock_t *rwlock); +int ipc_rwlock_wrlock(ipc_rwlock_t *rwlock); +int ipc_rwlock_unlock(ipc_rwlock_t *rwlock); +#endif + PGF_INTERNAL_DECL -pthread_rwlock_t *ipc_new_file_rwlock(const char* file_path, - bool *is_first); +ipc_rwlock_t *ipc_new_file_rwlock(const char* file_path, + bool *is_first); PGF_INTERNAL_DECL void ipc_release_file_rwlock(const char* file_path, - pthread_rwlock_t *rwlock); + ipc_rwlock_t *rwlock); #endif