mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
remove the dependency to pthread on Windows
This commit is contained in:
@@ -24,8 +24,6 @@ size_t getpagesize()
|
|||||||
#define ftruncate _chsize
|
#define ftruncate _chsize
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "ipc.h"
|
|
||||||
|
|
||||||
PGF_INTERNAL __thread unsigned char* current_base __attribute__((tls_model("initial-exec"))) = NULL;
|
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 PgfDB* current_db __attribute__((tls_model("initial-exec"))) = NULL;
|
||||||
PGF_INTERNAL __thread DB_scope *last_db_scope __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)
|
DB_scope::DB_scope(PgfDB *db, DB_scope_mode m)
|
||||||
{
|
{
|
||||||
int res =
|
int res =
|
||||||
(m == READER_SCOPE) ? pthread_rwlock_rdlock(db->rwlock)
|
(m == READER_SCOPE) ? ipc_rwlock_rdlock(db->rwlock)
|
||||||
: pthread_rwlock_wrlock(db->rwlock);
|
: ipc_rwlock_wrlock(db->rwlock);
|
||||||
if (res != 0)
|
if (res != 0)
|
||||||
throw pgf_systemerror(res);
|
throw pgf_systemerror(res);
|
||||||
|
|
||||||
@@ -1271,7 +1269,7 @@ DB_scope::~DB_scope()
|
|||||||
{
|
{
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wterminate"
|
#pragma GCC diagnostic ignored "-Wterminate"
|
||||||
pthread_rwlock_unlock(current_db->rwlock);
|
ipc_rwlock_unlock(current_db->rwlock);
|
||||||
|
|
||||||
current_db = save_db;
|
current_db = save_db;
|
||||||
current_base = current_db ? (unsigned char*) current_db->ms
|
current_base = current_db ? (unsigned char*) current_db->ms
|
||||||
|
|||||||
@@ -54,13 +54,15 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include "ipc.h"
|
||||||
|
|
||||||
class PgfDB {
|
class PgfDB {
|
||||||
private:
|
private:
|
||||||
int fd;
|
int fd;
|
||||||
const char *filepath;
|
const char *filepath;
|
||||||
malloc_state* ms;
|
malloc_state* ms;
|
||||||
|
|
||||||
pthread_rwlock_t *rwlock;
|
ipc_rwlock_t *rwlock;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
HANDLE hMap;
|
HANDLE hMap;
|
||||||
|
|||||||
@@ -107,8 +107,8 @@ next:
|
|||||||
}
|
}
|
||||||
|
|
||||||
PGF_INTERNAL
|
PGF_INTERNAL
|
||||||
pthread_rwlock_t *ipc_new_file_rwlock(const char* file_path,
|
ipc_rwlock_t *ipc_new_file_rwlock(const char* file_path,
|
||||||
bool *is_first)
|
bool *is_first)
|
||||||
{
|
{
|
||||||
if (file_path == NULL) {
|
if (file_path == NULL) {
|
||||||
*is_first = true;
|
*is_first = true;
|
||||||
@@ -258,7 +258,7 @@ pthread_rwlock_t *ipc_new_file_rwlock(const char* file_path,
|
|||||||
|
|
||||||
PGF_INTERNAL
|
PGF_INTERNAL
|
||||||
void ipc_release_file_rwlock(const char* file_path,
|
void ipc_release_file_rwlock(const char* file_path,
|
||||||
pthread_rwlock_t *rwlock)
|
ipc_rwlock_t *rwlock)
|
||||||
{
|
{
|
||||||
if (file_path == NULL) {
|
if (file_path == NULL) {
|
||||||
pthread_rwlock_destroy(rwlock);
|
pthread_rwlock_destroy(rwlock);
|
||||||
@@ -323,16 +323,34 @@ void ipc_release_file_rwlock(const char* file_path,
|
|||||||
pthread_mutex_unlock(&locks->mutex);
|
pthread_mutex_unlock(&locks->mutex);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
PGF_INTERNAL_DECL
|
PGF_INTERNAL
|
||||||
pthread_rwlock_t *ipc_new_file_rwlock(const char* file_path,
|
int ipc_rwlock_rdlock(ipc_rwlock_t *rwlock)
|
||||||
bool *is_first)
|
{
|
||||||
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PGF_INTERNAL_DECL
|
PGF_INTERNAL
|
||||||
void ipc_release_file_rwlock(const char* file_path,
|
void ipc_release_file_rwlock(const char* file_path,
|
||||||
pthread_rwlock_t *rwlock)
|
ipc_rwlock_t *rwlock)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,12 +1,24 @@
|
|||||||
#ifndef IPC_H
|
#ifndef IPC_H
|
||||||
#define 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
|
PGF_INTERNAL_DECL
|
||||||
pthread_rwlock_t *ipc_new_file_rwlock(const char* file_path,
|
ipc_rwlock_t *ipc_new_file_rwlock(const char* file_path,
|
||||||
bool *is_first);
|
bool *is_first);
|
||||||
|
|
||||||
PGF_INTERNAL_DECL
|
PGF_INTERNAL_DECL
|
||||||
void ipc_release_file_rwlock(const char* file_path,
|
void ipc_release_file_rwlock(const char* file_path,
|
||||||
pthread_rwlock_t *rwlock);
|
ipc_rwlock_t *rwlock);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user