mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-23 09:52:55 -06:00
fix the compilation on Windows
This commit is contained in:
@@ -200,7 +200,8 @@ PgfDB::PgfDB(const char* filepath, int flags, int mode) {
|
|||||||
base = ((unsigned char *) ms) + page_size;
|
base = ((unsigned char *) ms) + page_size;
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
char *name;
|
char *mutex_name;
|
||||||
|
char *event_name;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
@@ -211,11 +212,18 @@ PgfDB::PgfDB(const char* filepath, int flags, int mode) {
|
|||||||
close(fd);
|
close(fd);
|
||||||
throw pgf_systemerror(code);
|
throw pgf_systemerror(code);
|
||||||
}
|
}
|
||||||
sprintf(buf, "gf-rwevent-%lx-%lx-%lx",
|
mutex_name = buf;
|
||||||
|
sprintf(mutex_name,
|
||||||
|
"gf-mutex-%lx-%lx-%lx",
|
||||||
|
hInfo.dwVolumeSerialNumber,
|
||||||
|
hInfo.nFileIndexHigh,
|
||||||
|
hInfo.nFileIndexLow);
|
||||||
|
event_name = buf+strlen(mutex_name+1);
|
||||||
|
sprintf(event_name,
|
||||||
|
"gf-rwevent-%lx-%lx-%lx",
|
||||||
hInfo.dwVolumeSerialNumber,
|
hInfo.dwVolumeSerialNumber,
|
||||||
hInfo.nFileIndexHigh,
|
hInfo.nFileIndexHigh,
|
||||||
hInfo.nFileIndexLow);
|
hInfo.nFileIndexLow);
|
||||||
name = buf;
|
|
||||||
|
|
||||||
hMap = CreateFileMapping((HANDLE) _get_osfhandle(fd),
|
hMap = CreateFileMapping((HANDLE) _get_osfhandle(fd),
|
||||||
NULL,
|
NULL,
|
||||||
@@ -242,7 +250,8 @@ PgfDB::PgfDB(const char* filepath, int flags, int mode) {
|
|||||||
throw pgf_systemerror(code, filepath);
|
throw pgf_systemerror(code, filepath);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
name = NULL;
|
mutex_name = NULL;
|
||||||
|
event_name = NULL;
|
||||||
hMap = INVALID_HANDLE_VALUE;
|
hMap = INVALID_HANDLE_VALUE;
|
||||||
ms = (malloc_state*) ::malloc(mmap_size);
|
ms = (malloc_state*) ::malloc(mmap_size);
|
||||||
if (ms == NULL)
|
if (ms == NULL)
|
||||||
@@ -251,8 +260,22 @@ PgfDB::PgfDB(const char* filepath, int flags, int mode) {
|
|||||||
base = ((unsigned char *) ms) + page_size;
|
base = ((unsigned char *) ms) + page_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
hRWEvent = CreateEvent(NULL, FALSE, FALSE, name);
|
hМutex = CreateMutex(NULL, FALSE, mutex_name);
|
||||||
|
if (hМutex == NULL) {
|
||||||
|
if (fd < 0) {
|
||||||
|
::free(ms);
|
||||||
|
} else {
|
||||||
|
UnmapViewOfFile(ms);
|
||||||
|
CloseHandle(hMap);
|
||||||
|
}
|
||||||
|
::free((void *) this->filepath);
|
||||||
|
close(fd);
|
||||||
|
throw pgf_systemerror(code, filepath);
|
||||||
|
}
|
||||||
|
|
||||||
|
hRWEvent = CreateEvent(NULL, FALSE, FALSE, event_name);
|
||||||
if (hRWEvent == NULL) {
|
if (hRWEvent == NULL) {
|
||||||
|
CloseHandle(hMutex);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
::free(ms);
|
::free(ms);
|
||||||
} else {
|
} else {
|
||||||
@@ -284,6 +307,7 @@ PgfDB::PgfDB(const char* filepath, int flags, int mode) {
|
|||||||
CloseHandle(hMap);
|
CloseHandle(hMap);
|
||||||
}
|
}
|
||||||
CloseHandle(hRWEvent);
|
CloseHandle(hRWEvent);
|
||||||
|
CloseHandle(hMutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
::free((void *) this->filepath);
|
::free((void *) this->filepath);
|
||||||
@@ -309,6 +333,7 @@ PgfDB::PgfDB(const char* filepath, int flags, int mode) {
|
|||||||
CloseHandle(hMap);
|
CloseHandle(hMap);
|
||||||
}
|
}
|
||||||
CloseHandle(hRWEvent);
|
CloseHandle(hRWEvent);
|
||||||
|
CloseHandle(hMutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
::free((void *) this->filepath);
|
::free((void *) this->filepath);
|
||||||
@@ -351,6 +376,7 @@ PgfDB::~PgfDB()
|
|||||||
CloseHandle(hMap);
|
CloseHandle(hMap);
|
||||||
}
|
}
|
||||||
CloseHandle(hRWEvent);
|
CloseHandle(hRWEvent);
|
||||||
|
CloseHandle(hMutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
@@ -367,7 +393,11 @@ txn_t PgfDB::get_txn_id() {
|
|||||||
PGF_INTERNAL
|
PGF_INTERNAL
|
||||||
void PgfDB::register_revision(object o)
|
void PgfDB::register_revision(object o)
|
||||||
{
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
pthread_mutex_lock(&ms->mutex);
|
pthread_mutex_lock(&ms->mutex);
|
||||||
|
#else
|
||||||
|
WaitForSingleObject(hMutex, INFINITE);
|
||||||
|
#endif
|
||||||
|
|
||||||
revision_entry *free_entry = NULL;
|
revision_entry *free_entry = NULL;
|
||||||
|
|
||||||
@@ -397,13 +427,21 @@ void PgfDB::register_revision(object o)
|
|||||||
free_entry->txn_id = ms->curr_txn_id;
|
free_entry->txn_id = ms->curr_txn_id;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
#ifndef _WIN32
|
||||||
pthread_mutex_unlock(&ms->mutex);
|
pthread_mutex_unlock(&ms->mutex);
|
||||||
|
#else
|
||||||
|
ReleaseMutex(hMutex);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
PGF_INTERNAL
|
PGF_INTERNAL
|
||||||
void PgfDB::unregister_revision(object o)
|
void PgfDB::unregister_revision(object o)
|
||||||
{
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
pthread_mutex_lock(&ms->mutex);
|
pthread_mutex_lock(&ms->mutex);
|
||||||
|
#else
|
||||||
|
WaitForSingleObject(hMutex, INFINITE);
|
||||||
|
#endif
|
||||||
|
|
||||||
revision_entry *free_entry = NULL;
|
revision_entry *free_entry = NULL;
|
||||||
|
|
||||||
@@ -427,7 +465,11 @@ void PgfDB::unregister_revision(object o)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
pthread_mutex_unlock(&ms->mutex);
|
pthread_mutex_unlock(&ms->mutex);
|
||||||
|
#else
|
||||||
|
ReleaseMutex(hMutex);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void PgfDB::cleanup_revisions()
|
void PgfDB::cleanup_revisions()
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ private:
|
|||||||
#else
|
#else
|
||||||
DWORD pid;
|
DWORD pid;
|
||||||
HANDLE hMap;
|
HANDLE hMap;
|
||||||
|
HANDLE hMutex;
|
||||||
HANDLE hRWEvent;
|
HANDLE hRWEvent;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -140,7 +141,6 @@ private:
|
|||||||
PGF_INTERNAL_DECL void dump_free_blocks(object map);
|
PGF_INTERNAL_DECL void dump_free_blocks(object map);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
PGF_INTERNAL_DECL object malloc_internal(size_t bytes);
|
PGF_INTERNAL_DECL object malloc_internal(size_t bytes);
|
||||||
|
|
||||||
PGF_INTERNAL_DECL object realloc_internal(object oldo, size_t old_bytes, size_t new_bytes);
|
PGF_INTERNAL_DECL object realloc_internal(object oldo, size_t old_bytes, size_t new_bytes);
|
||||||
|
|||||||
Reference in New Issue
Block a user