mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
remove the dependency to pthread on Windows
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user