mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-09-17 07:46:00 -06:00
revert the RW lock before throwing an exception
This commit is contained in:
@@ -1839,32 +1839,44 @@ void PgfDB::resize_map(size_t new_size, bool writeable)
|
|||||||
// OSX does not implement mremap or MREMAP_MAYMOVE
|
// OSX does not implement mremap or MREMAP_MAYMOVE
|
||||||
#ifndef MREMAP_MAYMOVE
|
#ifndef MREMAP_MAYMOVE
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
if (munmap(base, mmap_size) == -1)
|
if (munmap(base, mmap_size) == -1) {
|
||||||
|
pthread_rwlock_unlock(&ms->rwlock);
|
||||||
throw pgf_systemerror(errno);
|
throw pgf_systemerror(errno);
|
||||||
|
}
|
||||||
base = NULL;
|
base = NULL;
|
||||||
if (ms->file_size != new_size) {
|
if (ms->file_size != new_size) {
|
||||||
if (ftruncate(fd, page_size+new_size) < 0)
|
if (ftruncate(fd, page_size+new_size) < 0) {
|
||||||
|
pthread_rwlock_unlock(&ms->rwlock);
|
||||||
throw pgf_systemerror(errno, filepath);
|
throw pgf_systemerror(errno, filepath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
int prot = writeable ? PROT_READ | PROT_WRITE : PROT_READ;
|
int prot = writeable ? PROT_READ | PROT_WRITE : PROT_READ;
|
||||||
new_base =
|
new_base =
|
||||||
(unsigned char *) mmap(0, new_size, prot, MAP_SHARED, fd, page_size);
|
(unsigned char *) mmap(0, new_size, prot, MAP_SHARED, fd, page_size);
|
||||||
if (new_base == MAP_FAILED)
|
if (new_base == MAP_FAILED) {
|
||||||
|
pthread_rwlock_unlock(&ms->rwlock);
|
||||||
throw pgf_systemerror(errno);
|
throw pgf_systemerror(errno);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
new_base = (unsigned char *) ::realloc(base, new_size);
|
new_base = (unsigned char *) ::realloc(base, new_size);
|
||||||
if (new_base == NULL)
|
if (new_base == NULL) {
|
||||||
|
pthread_rwlock_unlock(&ms->rwlock);
|
||||||
throw pgf_systemerror(ENOMEM);
|
throw pgf_systemerror(ENOMEM);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (fd >= 0 && ms->file_size != new_size) {
|
if (fd >= 0 && ms->file_size != new_size) {
|
||||||
if (ftruncate(fd, page_size+new_size) < 0)
|
if (ftruncate(fd, page_size+new_size) < 0) {
|
||||||
|
pthread_rwlock_unlock(&ms->rwlock);
|
||||||
throw pgf_systemerror(errno, filepath);
|
throw pgf_systemerror(errno, filepath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
new_base =
|
new_base =
|
||||||
(unsigned char *) mremap(base, mmap_size, new_size, MREMAP_MAYMOVE);
|
(unsigned char *) mremap(base, mmap_size, new_size, MREMAP_MAYMOVE);
|
||||||
if (new_base == MAP_FAILED)
|
if (new_base == MAP_FAILED) {
|
||||||
|
pthread_rwlock_unlock(&ms->rwlock);
|
||||||
throw pgf_systemerror(errno);
|
throw pgf_systemerror(errno);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
base = new_base;
|
base = new_base;
|
||||||
|
|||||||
Reference in New Issue
Block a user