8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 03:23:04 +01:00

Fixed CORE-1671: atexit() calls in client libraries cause segfaults

and CORE-1079: Every attach of fbclient/fbembed library leaks 64KB of memory

To do it:
- created new template GlobalPtr, controlling access to destructors of global objects.
- applied it to global objects.

Also some related cleanup.
This commit is contained in:
alexpeshkoff 2008-01-23 15:52:40 +00:00
parent d00ceba75e
commit 39896cb955
127 changed files with 635 additions and 507 deletions

View File

@ -60,12 +60,12 @@ CREATEDB_Objects = $(addprefix $(OBJ)/, $(addsuffix .o, $(basename $(CREATEDB_So
DROP_Other_Sources = common/utils.cpp lock/lock.cpp jrd/isc_sync.cpp jrd/isc_ipc.cpp jrd/isc.cpp \
common/classes/fb_string.cpp common/classes/alloc.cpp common/fb_exception.cpp \
common/config/config.cpp common/config/config_file.cpp $(OS_SPECIFIC_Sources)
DROP_Files= drop.cpp
DROP_Sources = $(addprefix utilities/, $(DROP_Files)) $(DROP_Other_Sources)
DROP_Objects = $(addprefix $(OBJ)/, $(addsuffix .o, $(basename $(DROP_Sources))))
DROP_Objects = $(addprefix $(OBJ)/, $(addsuffix .o, $(basename $(DROP_Sources)))) \
$(FBCOMMON_ClientObjects) $(FBCLASSES_ClientObjects)
GSTAT_Other_Sources = jrd/btn.cpp jrd/db_alias.cpp jrd/ods.cpp common/utils.cpp \
@ -81,7 +81,7 @@ common/fb_exception.cpp common/utils.cpp
FBSVCMGR_Sources = $(addprefix utilities/, $(FBSVCMGR_Files)) $(FBSVCMGR_Other_Sources)
FBSVCMGR_Objects = $(addprefix $(OBJ)/, $(addsuffix .o, $(basename $(FBSVCMGR_Sources)))) \
$(FBCLASSES_MsgObjects) $(CLUMPLETS_Objects)
$(FBCLASSES_MsgObjects) $(CLUMPLETS_Objects) $(FBCOMMON_ClientObjects)
FBGUARD_Other_Sources = jrd/isc.cpp jrd/divorce.cpp jrd/path_utils.cpp

View File

@ -67,7 +67,7 @@ common/config/config.cpp common/config/config_file.cpp $(OS_SPECIFIC_Sources)
DROP_Files= drop.cpp
DROP_Sources = $(addprefix utilities/, $(DROP_Files)) $(DROP_Other_Sources)
DROP_Objects = $(addprefix $(OBJ)/, $(addsuffix .o, $(basename $(DROP_Sources))))
DROP_Objects = $(addprefix $(OBJ)/, $(addsuffix .o, $(basename $(DROP_Sources)))) $(FBCOMMON_ClientObjects)
GSEC_Other_Sources = jrd/enc.cpp jrd/sha.cpp jrd/guid.cpp \
@ -95,7 +95,7 @@ common/fb_exception.cpp common/utils.cpp
FBSVCMGR_Sources = $(addprefix utilities/, $(FBSVCMGR_Files)) $(FBSVCMGR_Other_Sources)
FBSVCMGR_Objects = $(addprefix $(OBJ)/, $(addsuffix .o, $(basename $(FBSVCMGR_Sources)))) \
$(FBCLASSES_MsgObjects) $(CLUMPLETS_Objects)
$(FBCLASSES_MsgObjects) $(CLUMPLETS_Objects) $(FBCOMMON_ClientObjects)
IBGUARD_Files = guard.cpp util.cpp

View File

@ -17,7 +17,7 @@ WHY_Sources = why.cpp
JRD_ClientFiles = alt.cpp cvt.cpp db_alias.cpp dsc.cpp \
enc.cpp gds.cpp isc.cpp isc_file.cpp isc_ipc.cpp \
isc_sync.cpp perf.cpp sch.cpp sdl.cpp status.cpp \
thd.cpp ThreadData.cpp ThreadStart.cpp utl.cpp \
ThreadData.cpp ThreadStart.cpp utl.cpp \
$(WHY_Sources)
# These are in the win32 release but not unix one for super?
@ -240,7 +240,7 @@ VULCAN_Objects = $(addprefix $(OBJ)/, $(addsuffix .o, $(basename $(VULCAN_Source
#
# common
FBCOMMON_ClientFiles = fb_exception.cpp classes/MetaName.cpp StatusHolder.cpp
FBCOMMON_ClientFiles = fb_exception.cpp thd.cpp classes/MetaName.cpp StatusHolder.cpp classes/init.cpp
FBCOMMON_ServerFiles = utils.cpp
FBCOMMON_ClientObjects = $(addprefix $(OBJ)/common/, $(addsuffix .o, $(basename $(FBCOMMON_ClientFiles))))

View File

@ -52,7 +52,6 @@
#include "../jrd/gds_proto.h"
#include "../jrd/svc.h"
#include "../jrd/svc_proto.h"
#include "../jrd/thd.h"
#include "../alice/alice_proto.h"
#include "../common/utils_proto.h"

View File

@ -38,7 +38,6 @@
#include "../alice/all.h"
#include "../alice/alice_meta.h"
#include "../jrd/gds_proto.h"
#include "../jrd/thd.h"
#include "../include/fb_exception.h"
#include "../common/classes/alloc.h"
#include "../alice/alice_proto.h"

View File

@ -24,14 +24,13 @@
//
//____________________________________________________________
//
// $Id: all.cpp,v 1.29 2004-09-01 14:51:33 alexpeshkoff Exp $
// $Id: all.cpp,v 1.30 2008-01-23 15:51:31 alexpeshkoff Exp $
//
#include "firebird.h"
#include "../jrd/common.h"
#include "../alice/all.h"
#include "../alice/alice.h"
#include "../jrd/thd.h"
#include "../common/classes/alloc.h"
AliceMemoryPool* AliceMemoryPool::createPool() {

View File

@ -46,7 +46,6 @@
#include "../alice/alice_meta.h"
#include "../alice/tdr_proto.h"
#include "../jrd/gds_proto.h"
#include "../jrd/thd.h"
#include "../jrd/constants.h"
#include "../common/classes/ClumpletWriter.h"

View File

@ -46,7 +46,6 @@
#include "../jrd/gds_proto.h"
#include "../jrd/isc_proto.h"
#include "../jrd/svc_proto.h"
#include "../jrd/thd.h"
#include "../jrd/constants.h"
#include "../common/classes/ClumpletWriter.h"

View File

@ -46,7 +46,6 @@
#include "../jrd/ods.h"
#include "../jrd/align.h"
#include "../jrd/gdsassert.h"
#include "../jrd/thd.h"
#include "../jrd/constants.h"
#include "../common/stuff.h"
#include "../burp/backu_proto.h"

View File

@ -40,7 +40,6 @@
#include <stdarg.h>
#include "../jrd/ibsetjmp.h"
#include "../jrd/msg_encode.h"
#include "../jrd/thd.h"
#include "../jrd/ods.h" // to get MAX_PAGE_SIZE
#include "../jrd/svc.h"
#include "../jrd/constants.h"

View File

@ -44,7 +44,6 @@
#include "../burp/mvol_proto.h"
#include "../jrd/gds_proto.h"
#include "../jrd/gdsassert.h"
#include "../jrd/thd.h"
#include <fcntl.h>
#include <sys/types.h>

View File

@ -37,7 +37,6 @@
#include "../jrd/license.h"
#include "../jrd/obj.h"
#include "../jrd/ods.h"
#include "../jrd/thd.h"
#include "../common/stuff.h"
#include "../burp/burp_proto.h"
#include "../burp/canon_proto.h"

View File

@ -48,10 +48,15 @@
#define FREE_PATTERN 0xDEADBEEF
#define ALLOC_PATTERN 0xFEEDABED
#ifdef DEBUG_GDS_ALLOC
# define PATTERN_FILL(ptr, size, pattern) for (size_t _i = 0; _i < size / sizeof(unsigned int); _i++) \
((unsigned int*)(ptr))[_i] = (pattern)
inline void PATTERN_FILL(void *ptr, size_t size, unsigned int pattern)
{
for (size_t i = 0; i < size / sizeof(unsigned int); i++)
{
((unsigned int*)ptr)[i] = pattern;
}
}
#else
# define PATTERN_FILL(ptr, size, pattern) ((void)0)
inline void PATTERN_FILL(void *, size_t, unsigned int) { }
#endif
// TODO (in order of importance):
@ -158,8 +163,8 @@ int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */
// Extents cache is not used when DEBUG_GDS_ALLOC or USE_VALGRIND is enabled.
// This slows down things a little due to frequent syscalls mapping/unmapping
// memory but allows to detect more allocation errors
Firebird::Vector<void*, MAP_CACHE_SIZE> extents_cache;
Mutex cache_mutex;
Vector<void*, MAP_CACHE_SIZE> extents_cache;
Mutex* cache_mutex; // Will be initialized manually in MemoryPool::init
// avoid races during initialization
size_t map_page_size = 0;
@ -240,28 +245,48 @@ MemoryPool* MemoryPool::getContextPool()
return TLS_GET(contextPool);
}
// Initialize default stats group
// Default stats group and default pool
MemoryStats* MemoryPool::default_stats_group = 0;
MemoryPool* MemoryPool::processMemoryPool = 0;
// Initialize process memory pool to avoid possible race conditions.
// At this point also set contextMemoryPool for main thread (or all
// process in case of no threading).
namespace {
char msBuffer[sizeof(MemoryStats) + ALLOC_ALIGNMENT];
MemoryPool* createProcessMemoryPool()
{
MemoryPool::default_stats_group =
new((void*)(IPTR) MEM_ALIGN((size_t)(IPTR) msBuffer)) MemoryStats;
MemoryPool* p = MemoryPool::createPool();
fb_assert(p);
#ifndef SUPERCLIENT
MemoryPool::setContextPool(p);
// Initialize process memory pool (called from InstanceControl).
// At this point also set contextMemoryPool for main thread
// (or all process in case of no threading).
void MemoryPool::init()
{
#if defined(WIN_NT) || defined(HAVE_MMAP)
static char mtxBuffer[sizeof(Mutex) + ALLOC_ALIGNMENT];
cache_mutex =
new((void*)(IPTR) MEM_ALIGN((size_t)(IPTR) mtxBuffer)) Mutex;
#endif
return p;
}
} // anonymous namespace
MemoryPool* MemoryPool::processMemoryPool = createProcessMemoryPool();
static char msBuffer[sizeof(MemoryStats) + ALLOC_ALIGNMENT];
MemoryPool::default_stats_group =
new((void*)(IPTR) MEM_ALIGN((size_t)(IPTR) msBuffer)) MemoryStats;
// Now it's safe to actually create MemoryPool
processMemoryPool = MemoryPool::createPool();
fb_assert(processMemoryPool);
#ifndef SUPERCLIENT
MemoryPool::setContextPool(processMemoryPool);
#endif
}
// Should be last routine, called by InstanceControl,
// being therefore the very last routine in firebird module.
void MemoryPool::cleanup()
{
deletePool(processMemoryPool);
processMemoryPool = 0;
default_stats_group = 0;
#if defined(WIN_NT) || defined(HAVE_MMAP)
cache_mutex->~Mutex();
#endif
}
void MemoryPool::setStatsGroup(MemoryStats& statsL)
{
@ -374,7 +399,7 @@ void MemoryPool::external_free(void *blk, size_t &size, bool pool_destroying)
// In normal case all blocks pass through queue of sufficent length by themselves
if (pool_destroying) {
// Synchronize delayed free queue using extents mutex
cache_mutex.enter();
MutexLockGuard guard(*cache_mutex);
// Extend circular buffer if possible
if (delayedExtentCount < FB_NELEM(delayedExtents)) {
@ -383,7 +408,6 @@ void MemoryPool::external_free(void *blk, size_t &size, bool pool_destroying)
item->size = size;
item->handle = handle;
delayedExtentCount++;
cache_mutex.leave();
return;
}
@ -405,8 +429,6 @@ void MemoryPool::external_free(void *blk, size_t &size, bool pool_destroying)
delayedExtentsPos++;
if (delayedExtentsPos >= FB_NELEM(delayedExtents))
delayedExtentsPos = 0;
cache_mutex.leave();
}
else {
// Let Valgrind forget about unmapped block
@ -424,14 +446,13 @@ void* MemoryPool::external_alloc(size_t &size)
// This method is assumed to return NULL in case it cannot alloc
# if !defined(DEBUG_GDS_ALLOC) && (defined(WIN_NT) || defined(HAVE_MMAP))
if (size == EXTENT_SIZE) {
cache_mutex.enter();
MutexLockGuard guard(cache_mutex);
void *result = NULL;
if (extents_cache.getCount()) {
// Use most recently used object to encourage caching
result = extents_cache[extents_cache.getCount() - 1];
extents_cache.shrink(extents_cache.getCount() - 1);
}
cache_mutex.leave();
if (result) {
return result;
}
@ -494,13 +515,11 @@ void* MemoryPool::external_alloc(size_t &size)
void MemoryPool::external_free(void *blk, size_t &size, bool pool_destroying) {
# if !defined(DEBUG_GDS_ALLOC) && (defined(WIN_NT) || defined(HAVE_MMAP))
if (size == EXTENT_SIZE) {
cache_mutex.enter();
MutexLockGuard guard(cache_mutex);
if (extents_cache.getCount() < extents_cache.getCapacity()) {
extents_cache.add(blk);
cache_mutex.leave();
return;
}
cache_mutex.leave();
}
# endif
# if defined WIN_NT

View File

@ -262,7 +262,7 @@ private:
void removeFreeBlock(MemoryBlock* blk);
void free_blk_extent(MemoryBlock* blk);
// Allocates small block from this pool. Pool must be locked during call
void* internal_alloc(size_t size, SSHORT type = 0
#ifdef DEBUG_GDS_ALLOC
@ -370,6 +370,10 @@ public:
return result;
}
// Initialize and finalize global memory pool
static void init();
static void cleanup();
/// Returns the type associated with the allocated memory.
static SSHORT blk_type(const void* mem) {
return ((MemoryBlock*)((char *)mem - MEM_ALIGN(sizeof(MemoryBlock))))->mbk_type;

View File

@ -1,5 +1,5 @@
/*
* PROGRAM: JRD Access Method
* PROGRAM: Common Access Method
* MODULE: init.h
* DESCRIPTION: InitMutex, InitInstance - templates to help with initialization
*
@ -27,46 +27,118 @@
#ifndef CLASSES_INIT_INSTANCE_H
#define CLASSES_INIT_INSTANCE_H
#include "fb_types.h"
#include "../common/classes/alloc.h"
namespace Firebird {
// InstanceControl - interface for almost all global variables
class InstanceControl
{
public:
InstanceControl();
static void destructors();
static void registerGdsCleanup(FPTR_VOID cleanup);
protected:
virtual void dtor() = 0;
private:
static InstanceControl* instanceList;
static FPTR_VOID gdsCleanup;
InstanceControl* next;
};
// GlobalPtr - template to help declaring global varables
template <typename T>
class GlobalPtr : private InstanceControl
{
private:
T* instance;
void dtor()
{
delete instance;
instance = 0;
}
public:
GlobalPtr()
: InstanceControl()
{
instance = FB_NEW(*getDefaultMemoryPool()) T(*getDefaultMemoryPool());
// This means - for objects with ctors/dtors that want to ;be global,
// provide ctor with MemoryPool& parameter. Even if it is ignored!
}
T* operator->() const throw()
{
return instance;
}
operator T&() const throw()
{
return *instance;
}
T* operator&() const throw()
{
return instance;
}
bool operator!() const throw()
{
return instance ? false : true;
}
};
// Support for common mutex for various inits
class StaticMutex
{
protected:
static RecursiveMutex* mutex;
public:
static void create();
static void release();
};
// InitMutex - executes static void C::init() once and only once
template <typename C>
class InitMutex : private Mutex {
class InitMutex : private StaticMutex
{
private:
volatile bool flag;
public:
InitMutex() : flag(false) { }
void init() {
InitMutex()
: flag(false) { }
void init()
{
if (!flag) {
try {
enter();
mutex->enter();
if (!flag) {
C::init();
flag = true;
}
}
catch (const Firebird::Exception&) {
leave();
mutex->leave();
throw;
}
leave();
mutex->leave();
}
}
void cleanup() {
void cleanup()
{
if (flag) {
try {
enter();
mutex->enter();
if (flag) {
C::cleanup();
flag = false;
}
}
catch (const Firebird::Exception&) {
leave();
mutex->leave();
throw;
}
leave();
mutex->leave();
}
}
};
@ -75,35 +147,40 @@ public:
// DefaultInit uses default memory pool for it.
template <typename T>
class DefaultInit {
class DefaultInit
{
public:
static T* init() {
static T* init()
{
return FB_NEW(*getDefaultMemoryPool()) T(*getDefaultMemoryPool());
}
};
template <typename T,
typename C = DefaultInit<T> >
class InitInstance : private Mutex {
typename I = DefaultInit<T> >
class InitInstance : private StaticMutex
{
private:
T* instance;
volatile bool flag;
public:
InitInstance<T, C>() : flag(false) { }
T& operator()() {
InitInstance()
: flag(false) { }
T& operator()()
{
if (!flag) {
try {
enter();
mutex->enter();
if (!flag) {
instance = C::init();
instance = I::init();
flag = true;
}
}
catch (const Firebird::Exception&) {
leave();
mutex->leave();
throw;
}
leave();
mutex->leave();
}
return *instance;
}

View File

@ -27,6 +27,8 @@
#include "../../include/firebird.h"
#include "../../common/classes/locks.h"
#include "../../common/thd.h"
#include "../../jrd/common.h"
namespace Firebird {
@ -38,7 +40,7 @@ namespace Firebird {
tSetCriticalSectionSpinCount*
Spinlock::SetCriticalSectionSpinCount = INIT_SPIN_COUNT;
Spinlock::Spinlock() {
Spinlock::init() {
if (SetCriticalSectionSpinCount == MISS_SPIN_COUNT)
return;
if (SetCriticalSectionSpinCount == INIT_SPIN_COUNT) {
@ -60,4 +62,54 @@ Spinlock::Spinlock() {
#endif // WIN_NT
// in some cases recursive mutex's are not protected by try/catch
// therefore keep old (return value) logic
int RecursiveMutex::enter()
{
if (threadId == getThreadId())
{
++count;
}
else
{
try
{
mutex.enter();
}
catch (const Firebird::system_call_failed& e)
{
return e.getErrorCode();
}
threadId = getThreadId();
count = 1;
}
return 0;
}
int RecursiveMutex::leave()
{
if (threadId != getThreadId())
{
return FB_FAILURE;
}
if (--count == 0)
{
threadId = 0;
try
{
mutex.leave();
}
catch (const Firebird::system_call_failed& e)
{
return e.getErrorCode();
}
}
return 0;
}
} // namespace Firebird

View File

@ -46,6 +46,8 @@
namespace Firebird {
class MemoryPool; // Needed for ctors that must always ignaore it
#ifdef WIN_NT
// Generic process-local mutex and spinlock. The latter
@ -60,6 +62,9 @@ public:
Mutex() {
InitializeCriticalSection(&spinlock);
}
explicit Mutex(MemoryPool&) {
InitializeCriticalSection(&spinlock);
}
~Mutex() {
DeleteCriticalSection(&spinlock);
}
@ -79,8 +84,16 @@ typedef WINBASEAPI DWORD WINAPI tSetCriticalSectionSpinCount (
class Spinlock : public Mutex {
private:
static tSetCriticalSectionSpinCount* SetCriticalSectionSpinCount;
init();
public:
Spinlock();
Spinlock()
{
init();
}
explicit Spinlock(MemoryPool&)
{
init();
}
};
#else //WIN_NT
@ -95,6 +108,10 @@ public:
if (mutex_init(&mlock, USYNC_PROCESS, NULL))
system_call_failed::raise("mutex_init");
}
explicit Mutex(MemoryPool&) {
if (mutex_init(&mlock, USYNC_PROCESS, NULL))
system_call_failed::raise("mutex_init");
}
~Mutex() {
if (mutex_destroy(&mlock))
system_call_failed::raise("mutex_destroy");
@ -122,6 +139,10 @@ public:
if (pthread_mutex_init(&mlock, 0))
system_call_failed::raise("pthread_mutex_init");
}
explicit Mutex(MemoryPool&) {
if (pthread_mutex_init(&mlock, 0))
system_call_failed::raise("pthread_mutex_init");
}
~Mutex() {
if (pthread_mutex_destroy(&mlock))
system_call_failed::raise("pthread_mutex_destroy");
@ -145,6 +166,10 @@ public:
if (pthread_spin_init(&spinlock, false))
system_call_failed::raise("pthread_spin_init");
}
explicit Spinlock(MemoryPool&) {
if (pthread_spin_init(&spinlock, false))
system_call_failed::raise("pthread_spin_init");
}
~Spinlock() {
if (pthread_spin_destroy(&spinlock))
system_call_failed::raise("pthread_spin_destroy");
@ -176,6 +201,25 @@ private:
Mutex *lock;
};
// Recursive mutex
class RecursiveMutex {
Firebird::Mutex mutex;
FB_THREAD_ID threadId;
int count;
public:
RecursiveMutex()
: mutex(), threadId(0), count(0)
{}
RecursiveMutex(class Firebird::MemoryPool&)
: mutex(), threadId(0), count(0)
{}
int enter();
int leave();
};
} //namespace Firebird
#endif // CLASSES_LOCKS_H

View File

@ -56,12 +56,11 @@ private:
Mutex blockedReadersLock;
HANDLE writers_event, readers_semaphore;
// Forbid copy constructor
RWLock(const RWLock& source);
public:
RWLock() : lock(0), blockedReaders(0), blockedWriters(0)
void init()
{
lock = 0;
blockedReaders = 0;
blockedWriters = 0;
readers_semaphore = CreateSemaphore(NULL, 0 /*initial count*/,
INT_MAX, NULL);
if (readers_semaphore == NULL)
@ -70,6 +69,13 @@ public:
if (writers_event == NULL)
system_call_failed::raise("CreateEvent");
}
// Forbid copy constructor
RWLock(const RWLock& source);
public:
RWLock() { init(); }
RWLock(Firebird::MemoryPool&) { init(); }
~RWLock()
{
if (readers_semaphore && !CloseHandle(readers_semaphore))
@ -179,14 +185,18 @@ private:
rwlock_t lock;
// Forbid copy constructor
RWLock(const RWLock& source);
public:
RWLock()
{
void init()
{
if (rwlock_init(&lock, USYNC_PROCESS, NULL))
{
system_call_failed::raise("rwlock_init");
}
}
public:
RWLock() { init(); }
RWLock(Firebird::MemoryPool&) { init(); }
~RWLock()
{
if (rwlock_destroy(&lock))
@ -245,14 +255,17 @@ public:
namespace Firebird
{
class MemoryPool;
class RWLock
{
private:
pthread_rwlock_t lock;
// Forbid copy constructor
RWLock(const RWLock& source);
public:
RWLock() {
void init()
{
#if defined(LINUX) && !defined(USE_VALGRIND)
pthread_rwlockattr_t attr;
if (pthread_rwlockattr_init(&attr))
@ -268,6 +281,10 @@ public:
system_call_failed::raise("pthread_rwlock_init");
#endif
}
public:
RWLock() { init(); }
RWLock(class MemoryPool&) { init(); }
~RWLock()
{
if (pthread_rwlock_destroy(&lock))

View File

@ -40,27 +40,34 @@
namespace Firebird
{
class MemoryPool;
class Semaphore
{
private:
HANDLE hSemaphore;
public:
Semaphore()
void init()
{
hSemaphore = CreateSemaphore(NULL, 0 /*initial count*/, INT_MAX, NULL);
if (hSemaphore == NULL)
system_call_failed::raise("CreateSemaphore");
}
public:
Semaphore() { init(); }
explicit Semaphore(class MemoryPool&) { init(); }
~Semaphore()
{
if (hSemaphore && !CloseHandle(hSemaphore))
system_call_failed::raise("CloseHandle");
}
bool tryEnter(int seconds = 0)
bool tryEnter(int seconds = 0, int milliseconds = 0)
{
milliseconds += seconds * 1000;
DWORD result = WaitForSingleObject(
hSemaphore, seconds >= 0 ? seconds * 1000 : INFINITE);
hSemaphore, milliseconds >= 0 ? milliseconds : INFINITE);
if (result == WAIT_FAILED)
system_call_failed::raise("WaitForSingleObject");
return result != WAIT_TIMEOUT;
@ -111,13 +118,8 @@ private:
SignalSafeSemaphore* next;
#endif
#endif // WORKING_SEM_INIT
bool init;
public:
#ifdef MIXED_SEMAPHORE_AND_FILE_HANDLE
static bool checkHandle(int n);
#endif
SignalSafeSemaphore()
: init(false)
void init()
{
#ifdef WORKING_SEM_INIT
if (sem_init(sem, 0, 0) == -1) {
@ -137,12 +139,18 @@ public:
linkToInitialList();
#endif
#endif
init = true;
}
public:
SignalSafeSemaphore() { init(); }
explicit SignalSafeSemaphore(class MemoryPool&) { init(); }
#ifdef MIXED_SEMAPHORE_AND_FILE_HANDLE
static bool checkHandle(int n);
#endif
~SignalSafeSemaphore()
{
fb_assert(init == true);
#ifdef WORKING_SEM_INIT
if (sem_destroy(sem) == -1) {
system_call_failed::raise("sem_destroy");
@ -152,13 +160,10 @@ public:
system_call_failed::raise("sem_close");
}
#endif
init = false;
}
void enter()
{
fb_assert(init == true);
do {
if (sem_wait(sem) != -1)
return;
@ -168,7 +173,6 @@ public:
void release(SLONG count = 1)
{
fb_assert(init == true);
for (int i = 0; i < count; i++)
{
if (sem_post(sem) == -1)
@ -181,11 +185,11 @@ public:
#ifdef HAVE_SEM_TIMEDWAIT
// In case when sem_timedwait() is implemented by host OS,
// class SignalSafeSemaphore may have this function:
bool tryEnter(int seconds = 0)
bool tryEnter(int seconds = 0, int milliseconds = 0)
{
milliseconds += seconds * 1000;
// Return true in case of success
fb_assert(init == true);
if (seconds == 0)
if (milliseconds == 0)
{
// Instant try
do {
@ -196,7 +200,7 @@ public:
return false;
system_call_failed::raise("sem_trywait");
}
if (seconds < 0)
if (milliseconds < 0)
{
// Unlimited wait, like enter()
do {
@ -207,8 +211,8 @@ public:
}
// Wait with timeout
struct timespec timeout;
timeout.tv_sec = time(NULL) + seconds;
timeout.tv_nsec = 0;
timeout.tv_sec = time(NULL) + milliseconds / 1000;
timeout.tv_nsec = (milliseconds % 1000) * 1000;
int errcode = 0;
do {
int rc = sem_timedwait(sem, &timeout);
@ -260,10 +264,10 @@ private:
struct semid_ds* buf;
unsigned short* array;
};
public:
Semaphore()
: semId(semget(IPC_PRIVATE, 1, 0600))
void init()
{
semId = semget(IPC_PRIVATE, 1, 0600);
if (semId < 0)
system_call_failed::raise("semaphore.h: Semaphore: semget()");
semun arg;
@ -272,6 +276,10 @@ public:
system_call_failed::raise("semaphore.h: Semaphore: semctl()");
}
public:
Semaphore() { init(); }
explicit Semaphore(class MemoryPool&) { init(); }
~Semaphore()
{
semun arg;
@ -279,11 +287,12 @@ public:
system_call_failed::raise("semaphore.h: ~Semaphore: semctl()");
}
bool tryEnter(int seconds = 0) // Returns true in case of success
bool tryEnter(int seconds = 0, int milliseconds = 0) // Returns true in case of success
{
milliseconds += seconds * 1000;
timespec timeout;
timeout.tv_sec = time(NULL) + seconds;
timeout.tv_nsec = 0;
timeout.tv_sec = time(NULL) + milliseconds / 1000;
timeout.tv_nsec = (milliseconds % 1000) * 1000;
timespec* t = &timeout;
sembuf sb;
@ -291,11 +300,11 @@ public:
sb.sem_op = -1;
sb.sem_flg = 0;
if (seconds < 0) {
if (milliseconds < 0) {
// Unlimited wait
t = 0;
}
else if (seconds == 0) {
else if (milliseconds == 0) {
// just try
t = 0;
sb.sem_flg = IPC_NOWAIT;
@ -358,10 +367,8 @@ class Semaphore
private:
pthread_mutex_t mu;
pthread_cond_t cv;
bool init;
public:
Semaphore()
: init(false)
void init()
{
int err = pthread_mutex_init(&mu, NULL);
if (err != 0) {
@ -373,12 +380,14 @@ public:
//gds__log("Error on semaphore.h: constructor");
system_call_failed::raise("pthread_cond_init", err);
}
init = true;
}
public:
Semaphore() { init(); }
explicit Semaphore(class MemoryPool&) { init(); }
~Semaphore()
{
fb_assert(init == true);
int err = pthread_mutex_destroy(&mu);
if (err != 0) {
//gds__log("Error on semaphore.h: destructor");
@ -389,21 +398,19 @@ public:
//gds__log("Error on semaphore.h: destructor");
//system_call_failed::raise("pthread_cond_destroy", err);
}
init = false;
}
bool tryEnter(int seconds = 0)
bool tryEnter(int seconds = 0, int milliseconds = 0)
{
bool rt = false;
// Return true in case of success
int err2 = 0;
int err = 0;
// Return true in case of success
fb_assert(init == true);
if (seconds == 0)
milliseconds += seconds * 1000;
if (milliseconds == 0)
{
// Instant try
err2 = pthread_mutex_trylock(&mu);
if (err2 == 0)
{
@ -427,7 +434,7 @@ public:
system_call_failed::raise("pthread_mutex_trylock", err2);
}
if (seconds < 0)
if (milliseconds < 0)
{
// Unlimited wait, like enter()
err2 = pthread_mutex_lock(&mu);
@ -451,12 +458,12 @@ public:
return false;
system_call_failed::raise("pthread_mutex_lock", err2);
} //seconds < 0
}
// Wait with timeout
timespec timeout;
timeout.tv_sec = time(NULL) + seconds;
timeout.tv_nsec = 0;
timeout.tv_sec = time(NULL) + milliseconds / 1000;
timeout.tv_nsec = (milliseconds % 1000) * 1000;
err2 = pthread_mutex_lock(&mu);
if (err2 == 0)
@ -485,7 +492,6 @@ public:
void enter()
{
fb_assert(init == true);
int err = 0;
int err2 = pthread_mutex_lock(&mu);
if (err2 == 0)
@ -506,7 +512,6 @@ public:
void release(SLONG count = 1)
{
int err = 0;
fb_assert(init == true);
for (int i = 0; i < count; i++)
{
err = pthread_mutex_lock(&mu) ;

View File

@ -109,6 +109,10 @@ public:
: pool(_pool), level(0), root(NULL), defaultAccessor(this)
{ }
BePlusTree(Allocator& _pool)
: pool(&_pool), level(0), root(NULL), defaultAccessor(this)
{ }
BePlusTree(Allocator *_pool, const BePlusTree& from)
: pool(_pool), level(0), root(NULL), defaultAccessor(this)
{

View File

@ -25,6 +25,7 @@
#include "../../common/config/config.h"
#include "../../common/config/config_impl.h"
#include "../../common/config/config_file.h"
#include "../../common/classes/init.h"
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
@ -123,31 +124,7 @@ const ConfigImpl::ConfigEntry ConfigImpl::entries[] =
* Static instance of the system configuration file
*/
// was: const static ConfigImpl sysConfig;
static ConfigImpl *sys_config = NULL;
static Firebird::Mutex config_init_lock;
const ConfigImpl& ConfigImpl::instance()
{
if (!sys_config)
{
try {
config_init_lock.enter();
if (!sys_config) {
sys_config = FB_NEW(*getDefaultMemoryPool()) ConfigImpl(*getDefaultMemoryPool());
}
}
catch (const Firebird::Exception&) {
config_init_lock.leave();
throw;
}
config_init_lock.leave();
}
return *sys_config;
}
#define sysConfig ConfigImpl::instance()
static Firebird::InitInstance<ConfigImpl> sysConfig;
/******************************************************************************
*
@ -255,7 +232,7 @@ const char* ConfigImpl::asString(const string &value)
const char* Config::getInstallDirectory()
{
return sysConfig.getInstallDirectory();
return sysConfig().getInstallDirectory();
}
static Firebird::PathName* rootFromCommandLine = 0;
@ -280,44 +257,44 @@ const char* Config::getRootDirectory()
return rootFromCommandLine->c_str();
}
const char* result = (char*) sysConfig.values[KEY_ROOT_DIRECTORY];
return result ? result : sysConfig.root_dir;
const char* result = (char*) sysConfig().values[KEY_ROOT_DIRECTORY];
return result ? result : sysConfig().root_dir;
}
int Config::getTempBlockSize()
{
return (int) sysConfig.values[KEY_TEMP_BLOCK_SIZE];
return (int) sysConfig().values[KEY_TEMP_BLOCK_SIZE];
}
int Config::getTempCacheLimit()
{
int v = (int) sysConfig.values[KEY_TEMP_CACHE_LIMIT];
int v = (int) sysConfig().values[KEY_TEMP_CACHE_LIMIT];
return v < 0 ? 0 : v;
}
bool Config::getRemoteFileOpenAbility()
{
return (bool) sysConfig.values[KEY_REMOTE_FILE_OPEN_ABILITY];
return (bool) sysConfig().values[KEY_REMOTE_FILE_OPEN_ABILITY];
}
int Config::getGuardianOption()
{
return (int) sysConfig.values[KEY_GUARDIAN_OPTION];
return (int) sysConfig().values[KEY_GUARDIAN_OPTION];
}
int Config::getCpuAffinityMask()
{
return (int) sysConfig.values[KEY_CPU_AFFINITY_MASK];
return (int) sysConfig().values[KEY_CPU_AFFINITY_MASK];
}
bool Config::getOldParameterOrdering()
{
return (bool) sysConfig.values[KEY_OLD_PARAMETER_ORDERING];
return (bool) sysConfig().values[KEY_OLD_PARAMETER_ORDERING];
}
int Config::getTcpRemoteBufferSize()
{
int rc = (int) sysConfig.values[KEY_TCP_REMOTE_BUFFER_SIZE];
int rc = (int) sysConfig().values[KEY_TCP_REMOTE_BUFFER_SIZE];
if (rc < 1448)
rc = 1448;
if (rc > MAX_SSHORT)
@ -327,57 +304,57 @@ int Config::getTcpRemoteBufferSize()
bool Config::getTcpNoNagle()
{
return (bool) sysConfig.values[KEY_TCP_NO_NAGLE];
return (bool) sysConfig().values[KEY_TCP_NO_NAGLE];
}
int Config::getDefaultDbCachePages()
{
return (int) sysConfig.values[KEY_DEFAULT_DB_CACHE_PAGES];
return (int) sysConfig().values[KEY_DEFAULT_DB_CACHE_PAGES];
}
int Config::getConnectionTimeout()
{
return (int) sysConfig.values[KEY_CONNECTION_TIMEOUT];
return (int) sysConfig().values[KEY_CONNECTION_TIMEOUT];
}
int Config::getDummyPacketInterval()
{
return (int) sysConfig.values[KEY_DUMMY_PACKET_INTERVAL];
return (int) sysConfig().values[KEY_DUMMY_PACKET_INTERVAL];
}
int Config::getLockMemSize()
{
return (int) sysConfig.values[KEY_LOCK_MEM_SIZE];
return (int) sysConfig().values[KEY_LOCK_MEM_SIZE];
}
bool Config::getLockGrantOrder()
{
return (bool) sysConfig.values[KEY_LOCK_GRANT_ORDER];
return (bool) sysConfig().values[KEY_LOCK_GRANT_ORDER];
}
int Config::getLockHashSlots()
{
return (int) sysConfig.values[KEY_LOCK_HASH_SLOTS];
return (int) sysConfig().values[KEY_LOCK_HASH_SLOTS];
}
int Config::getLockAcquireSpins()
{
return (int) sysConfig.values[KEY_LOCK_ACQUIRE_SPINS];
return (int) sysConfig().values[KEY_LOCK_ACQUIRE_SPINS];
}
int Config::getEventMemSize()
{
return (int) sysConfig.values[KEY_EVENT_MEM_SIZE];
return (int) sysConfig().values[KEY_EVENT_MEM_SIZE];
}
int Config::getDeadlockTimeout()
{
return (int) sysConfig.values[KEY_DEADLOCK_TIMEOUT];
return (int) sysConfig().values[KEY_DEADLOCK_TIMEOUT];
}
int Config::getPrioritySwitchDelay()
{
int rc = (int) sysConfig.values[KEY_PRIORITY_SWITCH_DELAY];
int rc = (int) sysConfig().values[KEY_PRIORITY_SWITCH_DELAY];
if (rc < 1)
rc = 1;
return rc;
@ -385,7 +362,7 @@ int Config::getPrioritySwitchDelay()
int Config::getPriorityBoost()
{
int rc = (int) sysConfig.values[KEY_PRIORITY_BOOST];
int rc = (int) sysConfig().values[KEY_PRIORITY_BOOST];
if (rc < 1)
rc = 1;
if (rc > 1000)
@ -395,53 +372,53 @@ int Config::getPriorityBoost()
bool Config::getUsePriorityScheduler()
{
return (bool) sysConfig.values[KEY_USE_PRIORITY_SCHEDULER];
return (bool) sysConfig().values[KEY_USE_PRIORITY_SCHEDULER];
}
const char *Config::getRemoteServiceName()
{
return (const char*) sysConfig.values[KEY_REMOTE_SERVICE_NAME];
return (const char*) sysConfig().values[KEY_REMOTE_SERVICE_NAME];
}
unsigned short Config::getRemoteServicePort()
{
return (unsigned short) sysConfig.values[KEY_REMOTE_SERVICE_PORT];
return (unsigned short) sysConfig().values[KEY_REMOTE_SERVICE_PORT];
}
const char *Config::getRemotePipeName()
{
return (const char*) sysConfig.values[KEY_REMOTE_PIPE_NAME];
return (const char*) sysConfig().values[KEY_REMOTE_PIPE_NAME];
}
const char *Config::getIpcName()
{
return (const char*) sysConfig.values[KEY_IPC_NAME];
return (const char*) sysConfig().values[KEY_IPC_NAME];
}
int Config::getMaxUnflushedWrites()
{
return (int) sysConfig.values[KEY_MAX_UNFLUSHED_WRITES];
return (int) sysConfig().values[KEY_MAX_UNFLUSHED_WRITES];
}
int Config::getMaxUnflushedWriteTime()
{
return (int) sysConfig.values[KEY_MAX_UNFLUSHED_WRITE_TIME];
return (int) sysConfig().values[KEY_MAX_UNFLUSHED_WRITE_TIME];
}
int Config::getProcessPriorityLevel()
{
return (int) sysConfig.values[KEY_PROCESS_PRIORITY_LEVEL];
return (int) sysConfig().values[KEY_PROCESS_PRIORITY_LEVEL];
}
bool Config::getCompleteBooleanEvaluation()
{
return (bool) sysConfig.values[KEY_COMPLETE_BOOLEAN_EVALUATION];
return (bool) sysConfig().values[KEY_COMPLETE_BOOLEAN_EVALUATION];
}
int Config::getRemoteAuxPort()
{
#ifdef SUPERSERVER
return (int) sysConfig.values[KEY_REMOTE_AUX_PORT];
return (int) sysConfig().values[KEY_REMOTE_AUX_PORT];
#else
return 0;
#endif
@ -449,70 +426,70 @@ int Config::getRemoteAuxPort()
const char *Config::getRemoteBindAddress()
{
return (const char*) sysConfig.values[KEY_REMOTE_BIND_ADDRESS];
return (const char*) sysConfig().values[KEY_REMOTE_BIND_ADDRESS];
}
const char *Config::getExternalFileAccess()
{
return (const char*) sysConfig.values[KEY_EXTERNAL_FILE_ACCESS];
return (const char*) sysConfig().values[KEY_EXTERNAL_FILE_ACCESS];
}
const char *Config::getDatabaseAccess()
{
return (const char*) sysConfig.values[KEY_DATABASE_ACCESS];
return (const char*) sysConfig().values[KEY_DATABASE_ACCESS];
}
const char *Config::getUdfAccess()
{
return (const char*) sysConfig.values[KEY_UDF_ACCESS];
return (const char*) sysConfig().values[KEY_UDF_ACCESS];
}
const char *Config::getTempDirectories()
{
return (const char*) sysConfig.values[KEY_TEMP_DIRECTORIES];
return (const char*) sysConfig().values[KEY_TEMP_DIRECTORIES];
}
bool Config::getBugcheckAbort()
{
return (bool) sysConfig.values[KEY_BUGCHECK_ABORT];
return (bool) sysConfig().values[KEY_BUGCHECK_ABORT];
}
bool Config::getLegacyHash()
{
return (bool) sysConfig.values[KEY_LEGACY_HASH];
return (bool) sysConfig().values[KEY_LEGACY_HASH];
}
const char *Config::getGCPolicy()
{
return (const char *) sysConfig.values[KEY_GC_POLICY];
return (const char *) sysConfig().values[KEY_GC_POLICY];
}
bool Config::getRedirection()
{
return (bool) sysConfig.values[KEY_REDIRECTION];
return (bool) sysConfig().values[KEY_REDIRECTION];
}
bool Config::getOldColumnNaming()
{
return (bool) sysConfig.values[KEY_OLD_COLUMN_NAMING];
return (bool) sysConfig().values[KEY_OLD_COLUMN_NAMING];
}
const char *Config::getAuthMethod()
{
return (const char *) sysConfig.values[KEY_AUTH_METHOD];
return (const char *) sysConfig().values[KEY_AUTH_METHOD];
}
int Config::getDatabaseGrowthIncrement()
{
return (int) sysConfig.values[KEY_DATABASE_GROWTH_INCREMENT];
return (int) sysConfig().values[KEY_DATABASE_GROWTH_INCREMENT];
}
int Config::getMaxFileSystemCache()
{
return (int) sysConfig.values[KEY_MAX_FILESYSTEM_CACHE];
return (int) sysConfig().values[KEY_MAX_FILESYSTEM_CACHE];
}
bool Config::getRelaxedAliasChecking()
{
return (bool) sysConfig.values[KEY_RELAXED_ALIAS_CHECKING];
return (bool) sysConfig().values[KEY_RELAXED_ALIAS_CHECKING];
}

View File

@ -65,6 +65,7 @@ public:
};
public:
explicit ConfigImpl(MemoryPool& p);
~ConfigImpl();
static string getValue(ConfigFile&, const ConfigKey);
@ -73,11 +74,7 @@ public:
static bool asBoolean(const string&);
static const char* asString(const string&);
inline static const ConfigImpl& instance();
private:
explicit ConfigImpl(MemoryPool& p);
static const ConfigEntry entries[];
const char *root_dir;
ConfigValue *values;

View File

@ -7,6 +7,7 @@
#include <stdarg.h>
#include "gen/iberror.h"
#include "../common/classes/alloc.h"
#include "../common/classes/init.h"
namespace {
@ -18,12 +19,12 @@ typedef Firebird::CircularStringsBuffer<ENGINE_FAILURE_SPACE> CircularBuffer;
class InterlockedStringsBuffer : public CircularBuffer {
public:
InterlockedStringsBuffer(Firebird::MemoryPool&)
: CircularBuffer() { }
virtual char* alloc(const char* string, size_t length)
{
buffer_lock.enter();
char* new_string = CircularBuffer::alloc(string, length);
buffer_lock.leave();
return new_string;
Firebird::MutexLockGuard guard(buffer_lock);
return CircularBuffer::alloc(string, length);
}
private:
Firebird::Mutex buffer_lock;
@ -71,7 +72,7 @@ void fill_status(ISC_STATUS *ptr, ISC_STATUS status, va_list status_args)
}
}
InterlockedStringsBuffer engine_failures;
Firebird::GlobalPtr<InterlockedStringsBuffer> engine_failures;
} // namespace
@ -353,7 +354,7 @@ const char* status_string(const char* string)
const char* status_nstring(const char* string, size_t length)
{
return engine_failures.alloc(string, length);
return engine_failures->alloc(string, length);
}
// Serialize exception into status_vector, put transient strings from exception into given StringsBuffer

View File

@ -58,7 +58,6 @@ nested FOR loops are added.
#include "../dsql/alld_proto.h"
#include "../dsql/errd_proto.h"
#include "../jrd/gds_proto.h"
#include "../jrd/thd.h"
#include "../jrd/thread_proto.h"
#include "../common/classes/array.h"

View File

@ -75,7 +75,6 @@
#include "../common/classes/MetaName.h"
#include "../dsql/dsql.h"
#include "../jrd/ibase.h"
#include "../jrd/thd.h"
#include "../jrd/intl.h"
#include "../jrd/flags.h"
#include "../jrd/constants.h"

View File

@ -66,7 +66,6 @@ nested FOR loops are added.
#include <string.h>
#include "../dsql/dsql.h"
#include "../jrd/ibase.h"
#include "../jrd/thd.h"
#include "../jrd/align.h"
#include "../jrd/intl.h"
#include "../jrd/iberr.h"
@ -88,6 +87,7 @@ nested FOR loops are added.
#include "../jrd/y_handle.h"
#include "../common/config/config.h"
#include "../common/utils_proto.h"
#include "../common/classes/init.h"
#include "../jrd/scroll_cursors.h"
#ifdef SCROLLABLE_CURSORS
@ -158,8 +158,8 @@ static const UCHAR sql_records_info[] = {
isc_info_sql_records
};
static Firebird::Mutex databases_mutex;
static Firebird::Mutex cursors_mutex;
static Firebird::GlobalPtr<Firebird::Mutex> databases_mutex;
static Firebird::GlobalPtr<Firebird::Mutex> cursors_mutex;
#ifdef DSQL_DEBUG
@ -588,10 +588,10 @@ ISC_STATUS GDS_DSQL_EXECUTE_CPP(
request->req_open_cursor = open_cursor;
open_cursor->opn_request = request;
open_cursor->opn_transaction = *trans_handle;
cursors_mutex.enter();
cursors_mutex->enter();
open_cursor->opn_next = open_cursors;
open_cursors = open_cursor;
cursors_mutex.leave();
cursors_mutex->leave();
THREAD_EXIT();
ISC_STATUS_ARRAY local_status;
gds__transaction_cleanup(local_status,
@ -841,7 +841,7 @@ ISC_STATUS callback_execute_immediate( ISC_STATUS* status,
dsql_dbb* database = 0;
THREAD_EXIT();
databases_mutex.enter();
databases_mutex->enter();
try
{
// 1. Locate why_db_handle, corresponding to jrd_database_handle
@ -864,14 +864,14 @@ ISC_STATUS callback_execute_immediate( ISC_STATUS* status,
}
catch (const Firebird::Exception& e)
{
databases_mutex.leave();
databases_mutex->leave();
THREAD_ENTER();
return e.stuff_exception(status);
}
// 3. Call execute... function
databases_mutex.leave();
databases_mutex->leave();
THREAD_ENTER();
const ISC_STATUS rc = dsql8_execute_immediate_common(status,
&database->dbb_database_handle, &why_trans_handle->public_handle,
@ -887,7 +887,7 @@ YValve::Attachment* GetWhyAttachment(ISC_STATUS* status,
Jrd::Attachment* jrd_attachment_handle)
{
THREAD_EXIT();
databases_mutex.enter();
databases_mutex->enter();
dsql_dbb* database;
YValve::Attachment* db_handle = 0;
for (database = databases; database; database = database->dbb_next)
@ -913,7 +913,7 @@ YValve::Attachment* GetWhyAttachment(ISC_STATUS* status,
status[1] = isc_bad_db_handle;
status[2] = isc_arg_end;
}
databases_mutex.leave();
databases_mutex->leave();
THREAD_ENTER();
return database ? db_handle : 0;
}
@ -2964,7 +2964,7 @@ static void cleanup_database(FB_API_HANDLE* db_handle, void* flag)
/* if (flag)
THREAD_EXIT();*/
databases_mutex.enter();
databases_mutex->enter();
dsql_dbb* dbb;
for (dsql_dbb** dbb_ptr = &databases; dbb = *dbb_ptr; dbb_ptr = &dbb->dbb_next)
@ -2997,7 +2997,7 @@ static void cleanup_database(FB_API_HANDLE* db_handle, void* flag)
cleanup(0);
gds__unregister_cleanup(cleanup, 0);
}
databases_mutex.leave();
databases_mutex->leave();
}
@ -3019,7 +3019,7 @@ static void cleanup_transaction (FB_API_HANDLE tra_handle, void* arg)
// find this transaction/request pair in the list of pairs
cursors_mutex.enter();
cursors_mutex->enter();
dsql_opn** open_cursor_ptr = &open_cursors;
dsql_opn* open_cursor;
while (open_cursor = *open_cursor_ptr)
@ -3028,7 +3028,7 @@ static void cleanup_transaction (FB_API_HANDLE tra_handle, void* arg)
/* Found it, close the cursor but don't remove it from the list.
The close routine will have done that. */
cursors_mutex.leave();
cursors_mutex->leave();
/*
* we are expected to be within the subsystem when we do this
* cleanup, for now do a thread_enter/thread_exit here.
@ -3041,14 +3041,14 @@ static void cleanup_transaction (FB_API_HANDLE tra_handle, void* arg)
&open_cursor->opn_request,
DSQL_close);
THREAD_EXIT();
cursors_mutex.enter();
cursors_mutex->enter();
open_cursor_ptr = &open_cursors;
}
else
open_cursor_ptr = &open_cursor->opn_next;
}
cursors_mutex.leave();
cursors_mutex->leave();
}
@ -3082,7 +3082,7 @@ static void close_cursor( dsql_req* request)
// Remove the open cursor from the list
cursors_mutex.enter();
cursors_mutex->enter();
dsql_opn** open_cursor_ptr = &open_cursors;
dsql_opn* open_cursor;
for (; open_cursor = *open_cursor_ptr;
@ -3094,7 +3094,7 @@ static void close_cursor( dsql_req* request)
}
}
cursors_mutex.leave();
cursors_mutex->leave();
if (open_cursor) {
delete open_cursor;
@ -4228,7 +4228,7 @@ static bool get_rsb_item(SSHORT* explain_length_ptr,
static dsql_dbb* init(FB_API_HANDLE* db_handle)
{
THREAD_EXIT();
databases_mutex.enter();
databases_mutex->enter();
THREAD_ENTER();
if (!init_flag)
@ -4247,7 +4247,7 @@ static dsql_dbb* init(FB_API_HANDLE* db_handle)
}
if (!db_handle) {
databases_mutex.leave();
databases_mutex->leave();
return NULL;
}
@ -4257,7 +4257,7 @@ static dsql_dbb* init(FB_API_HANDLE* db_handle)
for (database = databases; database; database = database->dbb_next)
{
if (database->dbb_database_handle == *db_handle) {
databases_mutex.leave();
databases_mutex->leave();
return database;
}
}
@ -4268,7 +4268,7 @@ static dsql_dbb* init(FB_API_HANDLE* db_handle)
database->dbb_next = databases;
databases = database;
database->dbb_database_handle = *db_handle;
databases_mutex.leave();
databases_mutex->leave();
ISC_STATUS_ARRAY user_status;

View File

@ -58,7 +58,6 @@
//#undef IBERROR
#include "../jrd/gds_proto.h"
#include "../jrd/thd.h"
#include "../common/utils_proto.h"

View File

@ -50,7 +50,6 @@
#include "../dsql/metd_proto.h"
#include "../dsql/misc_func.h"
#include "../dsql/utld_proto.h"
#include "../jrd/thd.h"
#include "../jrd/thread_proto.h"
#include "../jrd/dsc_proto.h"
#include "../jrd/why_proto.h"

View File

@ -30,7 +30,7 @@
#include "../dsql/errd_proto.h"
#include "../dsql/hsh_proto.h"
#include "../jrd/sch_proto.h"
#include "../jrd/thd.h"
#include "../common/classes/init.h"
const int HASH_SIZE = 1021;
@ -39,7 +39,7 @@ static bool remove_symbol(dsql_sym**, dsql_sym*);
static bool scompare(const TEXT*, USHORT, const TEXT*, const USHORT);
static DSQL_SYM* hash_table;
static Firebird::Mutex hash_mutex;
static Firebird::GlobalPtr<Firebird::Mutex> hash_mutex;
/**

View File

@ -56,7 +56,6 @@
#include "../jrd/DataTypeUtil.h"
#include "../jrd/ods.h"
#include "../jrd/ini.h"
#include "../jrd/thd.h"
#include "../jrd/dsc_proto.h"
#include "../jrd/cvt_proto.h"
#include "../jrd/thread_proto.h"

View File

@ -38,7 +38,6 @@
#include "../jrd/ibase.h"
#include "../jrd/align.h"
#include "../jrd/intl.h"
#include "../jrd/thd.h"
#include "../dsql/alld_proto.h"
#include "../dsql/ddl_proto.h"
#include "../dsql/metd_proto.h"
@ -103,17 +102,17 @@ static dsql_sym* lookup_symbol(dsql_dbb*, const dsql_str*, SYM_TYPE, USHORT = 0)
namespace {
#ifdef SUPERSERVER
REC_MUTX_T rec_mutex; // Recursive metadata mutex
Firebird::GlobalPtr<Firebird::RecursiveMutex> rec_mutex; // Recursive metadata mutex
class RecMutexHolder {
public:
RecMutexHolder() {
THREAD_EXIT();
THD_rec_mutex_lock(&rec_mutex);
rec_mutex->enter();
THREAD_ENTER();
}
~RecMutexHolder() {
THD_rec_mutex_unlock(&rec_mutex);
rec_mutex->leave();
}
};
#else

View File

@ -33,7 +33,6 @@
#include "../dsql/errd_proto.h"
#include "../dsql/movd_proto.h"
#include "../jrd/cvt_proto.h"
#include "../jrd/thd.h"
static void post_error(ISC_STATUS, ...);

View File

@ -91,7 +91,6 @@
#include "../dsql/keywords.h"
#include "../dsql/misc_func.h"
#include "../jrd/gds_proto.h"
#include "../jrd/thd.h"
#include "../jrd/err_proto.h"
#include "../jrd/intlobj_new.h"

View File

@ -143,7 +143,6 @@
#include <stdio.h>
#include "../jrd/ibase.h"
#include "../dsql/dsql.h"
#include "../jrd/thd.h"
#include "../jrd/intl.h"
#include "../jrd/blr.h"
#include "../jrd/constants.h"

View File

@ -25,7 +25,7 @@
//
//____________________________________________________________
//
// $Id: movg.cpp,v 1.8 2004-06-08 13:41:00 alexpeshkoff Exp $
// $Id: movg.cpp,v 1.9 2008-01-23 15:51:51 alexpeshkoff Exp $
//
#include "firebird.h"
@ -43,7 +43,6 @@
#include "../gpre/gpre.h"
#include "../gpre/gpre_proto.h"
#include "../jrd/cvt_proto.h"
#include "../jrd/thd.h"
static void post_error(ISC_STATUS, ...);

View File

@ -36,7 +36,10 @@
namespace Firebird {
class StringsBuffer {
class MemoryPool;
class StringsBuffer
{
public:
virtual char* alloc(const char* string, size_t length) = 0;
virtual ~StringsBuffer() {}
@ -45,13 +48,12 @@ public:
};
template <size_t BUFFER_SIZE>
class CircularStringsBuffer : public StringsBuffer {
class CircularStringsBuffer : public StringsBuffer
{
public:
CircularStringsBuffer() throw() {
// This is to ensure we have zero at the end of buffer in case of buffer overflow
memset(buffer, 0, BUFFER_SIZE);
buffer_ptr = buffer;
}
CircularStringsBuffer() throw() { init(); }
CircularStringsBuffer(MemoryPool&) throw() { init(); }
virtual char* alloc(const char* string, size_t length) {
// fb_assert(length + 1 < BUFFER_SIZE);
// If there isn't any more room in the buffer, start at the beginning again
@ -63,7 +65,15 @@ public:
buffer_ptr += length + 1;
return new_string;
}
private:
void init() throw()
{
// This is to ensure we have zero at the end of buffer in case of buffer overflow
memset(buffer, 0, BUFFER_SIZE);
buffer_ptr = buffer;
}
char buffer[BUFFER_SIZE];
char *buffer_ptr;
};

View File

@ -48,8 +48,8 @@ static USHORT report_status(DWORD, DWORD, DWORD, DWORD);
static DWORD current_state;
static ThreadEntryPoint* main_handler;
static SERVICE_STATUS_HANDLE service_handle;
static Firebird::string* service_name = NULL;
static Firebird::string* remote_name = NULL;
static Firebird::GlobalPtr<Firebird::string> service_name;
static Firebird::GlobalPtr<Firebird::string> remote_name;
static HANDLE stop_event_handle;
@ -67,9 +67,7 @@ void CNTL_init(ThreadEntryPoint* handler, const TEXT* name)
main_handler = handler;
MemoryPool& pool = *getDefaultMemoryPool();
service_name = FB_NEW(pool) Firebird::string(pool);
service_name->printf(ISCGUARD_SERVICE, name);
remote_name = FB_NEW(pool) Firebird::string(pool);
remote_name->printf(REMOTE_SERVICE, name);
}

View File

@ -89,9 +89,9 @@ HWND hPSDlg, hWndGbl;
static int nRestarts = 0; /* the number of times the server was restarted */
static bool service_flag = true;
static TEXT instance[MAXPATHLEN];
static Firebird::string* service_name = NULL;
static Firebird::string* remote_name = NULL;
static Firebird::string* mutex_name = NULL;
static Firebird::GlobalPtr<Firebird::string> service_name;
static Firebird::GlobalPtr<Firebird::string> remote_name;
static Firebird::GlobalPtr<Firebird::string> mutex_name;
/* unsigned short shutdown_flag = FALSE; */
static log_info* log_entry;
@ -124,12 +124,8 @@ int WINAPI WinMain(
if (service_flag) {
strcpy(instance, FB_DEFAULT_INSTANCE);
service_flag = parse_args(lpszCmdLine);
MemoryPool& pool = *getDefaultMemoryPool();
service_name = FB_NEW(pool) Firebird::string(pool);
service_name->printf(ISCGUARD_SERVICE, instance);
remote_name = FB_NEW(pool) Firebird::string(pool);
remote_name->printf(REMOTE_SERVICE, instance);
mutex_name = FB_NEW(pool) Firebird::string(pool);
mutex_name->printf(GUARDIAN_MUTEX, instance);
}

View File

@ -312,7 +312,7 @@ void DatabaseSnapshot::SharedMemory::init(void* arg, SH_MEM_T* shmemData, bool i
// DatabaseSnapshot class
Mutex DatabaseSnapshot::initMutex;
GlobalPtr<Mutex> DatabaseSnapshot::initMutex;
DatabaseSnapshot::SharedMemory* DatabaseSnapshot::dump = NULL;
int DatabaseSnapshot::pid = getpid();

View File

@ -127,7 +127,7 @@ private:
static void putCall(const jrd_req*, Firebird::ClumpletWriter&, int);
static void putStatistics(const RuntimeStatistics*, Firebird::ClumpletWriter&, int, int);
static Firebird::Mutex initMutex;
static Firebird::GlobalPtr<Firebird::Mutex> initMutex;
static SharedMemory* dump;
static int pid;

View File

@ -33,7 +33,7 @@
// Static definitions/initializations
Firebird::Mutex TempSpace::initMutex;
Firebird::GlobalPtr<Firebird::Mutex> TempSpace::initMutex;
Firebird::TempDirectoryList* TempSpace::tempDirs = NULL;
size_t TempSpace::minBlockSize = 0;
offset_t TempSpace::globalCacheUsage = 0;

View File

@ -28,6 +28,7 @@
#include "../common/classes/array.h"
#include "../common/classes/TempFile.h"
#include "../common/config/dir_list.h"
#include "../common/classes/init.h"
class TempSpace : public Firebird::File {
public:
@ -167,7 +168,7 @@ private:
Segment* freeSegments;
Segment* notUsedSegments;
static Firebird::Mutex initMutex;
static Firebird::GlobalPtr<Firebird::Mutex> initMutex;
static Firebird::TempDirectoryList* tempDirs;
static size_t minBlockSize;
static offset_t globalCacheUsage;

View File

@ -34,6 +34,7 @@
#include <string.h>
#include <stdio.h>
#include "../jrd/common.h"
#include "../common/classes/init.h"
#include <stdarg.h>
#include "../jrd/ibase.h"
@ -1217,13 +1218,15 @@ static ISC_STATUS executeSecurityCommand(
input_user_data->server);
if (handle)
{
static Firebird::GlobalPtr<Firebird::Mutex> secExecMutex;
static Firebird::GlobalPtr<Firebird::CircularStringsBuffer<1024> > secExecBuf;
callRemoteServiceManager(status, handle, userInfo, 0, 0);
static Firebird::CircularStringsBuffer<1024> secExecBuf;
static Firebird::Mutex secExecMutex;
{
Firebird::MutexLockGuard lockMutex(secExecMutex);
secExecBuf.makePermanentVector(status, status);
secExecBuf->makePermanentVector(status, status);
}
ISC_STATUS_ARRAY user_status;
detachRemoteServiceManager(user_status, handle);
}

View File

@ -69,7 +69,6 @@
#include "../jrd/mov_proto.h"
#include "../jrd/pag_proto.h"
#include "../jrd/sdl_proto.h"
#include "../jrd/thd.h"
#include "../jrd/dsc_proto.h"
#include "../common/classes/array.h"

View File

@ -50,7 +50,6 @@
#include "../jrd/err_proto.h"
#include "../jrd/common.h"
#include "../jrd/ibsetjmp.h"
#include "../jrd/thd.h"
#include "../jrd/isc_s_proto.h"
#include "gen/iberror.h"

View File

@ -61,7 +61,6 @@
#include "../jrd/pag_proto.h"
#include "../jrd/pcmet_proto.h"
#include "../jrd/sort_proto.h"
#include "../jrd/thd.h"
#include "../jrd/tra_proto.h"
using namespace Jrd;

View File

@ -75,7 +75,6 @@
#include "../jrd/opt_proto.h"
#include "../jrd/par_proto.h"
#include "../jrd/scl_proto.h"
#include "../jrd/thd.h"
#include "../jrd/met_proto.h"
#include "../jrd/mov_proto.h"
#include "../jrd/dsc_proto.h"

View File

@ -50,7 +50,6 @@
#include "../jrd/err_proto.h"
#include "../jrd/gds_proto.h"
#include "../jrd/intl_proto.h"
#include "../jrd/thd.h"
#include "../common/classes/timestamp.h"

View File

@ -40,7 +40,6 @@
#include "../jrd/cvt2_proto.h"
#include "../jrd/err_proto.h"
#include "../jrd/intl_proto.h"
#include "../jrd/thd.h"
#include "../jrd/intl_classes.h"
#include "../jrd/gds_proto.h"
/* CVC: I needed them here. */

View File

@ -44,7 +44,6 @@
#include "../jrd/err_proto.h"
#ifdef SUPERSERVER
#include "../jrd/thd.h"
#include "../jrd/err_proto.h"
#endif

View File

@ -103,7 +103,6 @@
#include "../jrd/sch_proto.h"
#include "../jrd/scl_proto.h"
#include "../jrd/sdw_proto.h"
#include "../jrd/thd.h"
#include "../jrd/thread_proto.h"
#include "../jrd/event_proto.h"
#include "../jrd/nbak.h"
@ -4676,7 +4675,7 @@ static bool modify_procedure( thread_db* tdbb,
try {
THREAD_EXIT();
if (THD_rec_mutex_lock(&tdbb->getDatabase()->dbb_sp_rec_mutex))
if (tdbb->getDatabase()->dbb_sp_rec_mutex.enter())
{
THREAD_ENTER();
return false;
@ -4717,7 +4716,7 @@ static bool modify_procedure( thread_db* tdbb,
true,
PRC_being_altered)))
{
THD_rec_mutex_unlock(&tdbb->getDatabase()->dbb_sp_rec_mutex);
tdbb->getDatabase()->dbb_sp_rec_mutex.leave();
return false;
}
procedure->prc_alter_count = ++prc_alter_count;
@ -4771,11 +4770,11 @@ static bool modify_procedure( thread_db* tdbb,
catch (const Firebird::Exception& ex)
{
Firebird::stuff_exception(tdbb->tdbb_status_vector, ex);
THD_rec_mutex_unlock(&tdbb->getDatabase()->dbb_sp_rec_mutex);
tdbb->getDatabase()->dbb_sp_rec_mutex.leave();
ERR_punt();
}
THD_rec_mutex_unlock(&tdbb->getDatabase()->dbb_sp_rec_mutex);
tdbb->getDatabase()->dbb_sp_rec_mutex.leave();
return true;
case 5:

View File

@ -41,7 +41,6 @@
#include "../jrd/err_proto.h"
#include "../jrd/gds_proto.h"
#include "../jrd/sqz_proto.h"
#include "../jrd/thd.h"

View File

@ -64,7 +64,6 @@
#include "../jrd/mov_proto.h"
#include "../jrd/pag_proto.h"
#include "../jrd/sqz_proto.h"
#include "../jrd/thd.h"
#ifdef DEV_BUILD
#include "../jrd/dbg_proto.h"

View File

@ -71,7 +71,6 @@
#include "../jrd/intl_proto.h"
#include "../jrd/isc_f_proto.h"
#include "../jrd/met_proto.h"
#include "../jrd/thd.h"
#include "../jrd/vio_proto.h"
#include "../jrd/sch_proto.h"
#include "../jrd/thread_proto.h"

View File

@ -73,7 +73,6 @@
#include "../jrd/intl_proto.h"
#include "../jrd/isc_f_proto.h"
#include "../jrd/met_proto.h"
#include "../jrd/thd.h"
#include "../jrd/vio_proto.h"
#include "../jrd/scl_proto.h"
#include "../jrd/gdsassert.h"

View File

@ -57,7 +57,6 @@
#include "../jrd/intl_proto.h"
#include "../jrd/isc_f_proto.h"
#include "../jrd/met_proto.h"
#include "../jrd/thd.h"
#include "../jrd/vio_proto.h"
#include "../common/utils_proto.h"

View File

@ -69,7 +69,6 @@
#include "../jrd/intl_proto.h"
#include "../jrd/isc_f_proto.h"
#include "../jrd/met_proto.h"
#include "../jrd/thd.h"
#include "../jrd/vio_proto.h"
#include "../jrd/dsc_proto.h"
#include "../common/utils_proto.h"

View File

@ -54,7 +54,6 @@
#include "../jrd/inf_proto.h"
#include "../jrd/intl_proto.h"
#include "../jrd/isc_f_proto.h"
#include "../jrd/thd.h"
#include "../jrd/vio_proto.h"
#include "../common/utils_proto.h"

View File

@ -10,6 +10,8 @@
#include "../jrd/enc_proto.h"
#include "../jrd/gdsassert.h"
#include "../common/classes/locks.h"
#include "../common/classes/alloc.h"
#include "../common/classes/init.h"
/*
#ifdef HAVE_UNISTD_H
@ -427,7 +429,7 @@ static C_block CF6464[64 / CHUNKBITS][1 << CHUNKBITS];
/* ==================================== */
static Firebird::Mutex cryptMutex;
static Firebird::GlobalPtr<Firebird::Mutex> cryptMutex;
static C_block constdatablock; /* encryption constant */
const static size_t RESULT_SIZE = (1 + 4 + 4 + 11 + 1);

View File

@ -47,7 +47,6 @@
#include "../jrd/cch_proto.h"
#include "../jrd/met_proto.h"
#endif
#include "../jrd/thd.h"
#include "../jrd/dbg_proto.h"
#include "../jrd/err_proto.h"
#include "../jrd/gds_proto.h"

View File

@ -31,7 +31,6 @@
#define JRD_EVENT_H
#include "../jrd/isc.h"
#include "../jrd/thd.h"
#include "../jrd/file_params.h"
#include "../jrd/que.h"

View File

@ -104,7 +104,6 @@
#include "../jrd/rlck_proto.h"
#include "../jrd/rse_proto.h"
#include "../jrd/scl_proto.h"
#include "../jrd/thd.h"
#include "../jrd/sort_proto.h"
#include "../jrd/gds_proto.h"
#include "../jrd/align.h"

View File

@ -94,7 +94,6 @@
#include "../jrd/rlck_proto.h"
#include "../jrd/rse_proto.h"
#include "../jrd/thd.h"
#include "../jrd/tra_proto.h"
#include "../jrd/vio_proto.h"
#include "../jrd/isc_s_proto.h"

View File

@ -35,7 +35,6 @@
#include "../jrd/jrd.h"
#include "../jrd/tra.h"
#include "../jrd/dsc.h"
#include "../jrd/thd.h"
#include "../jrd/err_proto.h"
#include "../jrd/mov_proto.h"
#include "../jrd/evl_proto.h"

View File

@ -52,7 +52,6 @@
#include "../jrd/gds_proto.h"
#include "../jrd/met_proto.h"
#include "../jrd/mov_proto.h"
#include "../jrd/thd.h"
#include "../jrd/vio_proto.h"
#include "../common/config/config.h"
#include "../common/config/dir_list.h"

View File

@ -31,8 +31,6 @@
#ifndef JRD_FIL_H
#define JRD_FIL_H
#include "../jrd/thd.h"
/* Defined the directory list structures. */
/* Temporary workfile directory list. */

View File

@ -39,7 +39,6 @@
#include "../jrd/filte_proto.h"
#include "../jrd/gds_proto.h"
#include "../jrd/intl_proto.h"
#include "../jrd/thd.h"
using namespace Jrd;

View File

@ -72,7 +72,7 @@
namespace {
Firebird::InitInstance<Jrd::Module::LoadedModules> loadedModules;
Firebird::Mutex modulesMutex;
Firebird::GlobalPtr<Firebird::Mutex> modulesMutex;
template <typename S>
void terminate_at_space(S& s, const char* psz)

View File

@ -57,7 +57,6 @@
#include "../jrd/fun_proto.h"
#include "../jrd/gds_proto.h"
#include "../jrd/mov_proto.h"
#include "../jrd/thd.h"
#include "../jrd/sch_proto.h"
#include "../jrd/thread_proto.h"
#include "../jrd/isc_s_proto.h"

View File

@ -106,7 +106,6 @@ static const TEXT gdslogid[] = "";
static const char* FB_PID_FILE = "fb_%d";
#include "gen/sql_code.h"
#include "../jrd/thd.h"
#include "gen/iberror.h"
#include "../jrd/ibase.h"
@ -226,7 +225,7 @@ typedef clean *CLEAN;
static CLEAN cleanup_handlers = NULL;
static gds_msg* global_default_msg = NULL;
static bool initialized = false;
static bool volatile initialized = false;
void* API_ROUTINE gds__alloc_debug(SLONG size_request,
const TEXT* filename,
@ -3226,10 +3225,10 @@ void gds__cleanup(void)
(*routine)(arg);
}
Firebird::InstanceControl::registerGdsCleanup(0);
initialized = false;
}
static void init(void)
{
/**************************************
@ -3245,6 +3244,12 @@ static void init(void)
if (initialized)
return;
static Firebird::GlobalPtr<Firebird::Mutex> gdsInitMutex;
Firebird::MutexLockGuard guard(gdsInitMutex);
if (initialized)
return;
#ifdef UNIX
gds_pid = getpid();
#ifdef SUPERSERVER
@ -3278,7 +3283,7 @@ static void init(void)
initialized = true;
atexit(gds__cleanup);
Firebird::InstanceControl::registerGdsCleanup(gds__cleanup);
gdsPrefixInit();

View File

@ -36,20 +36,20 @@
* 1996-Feb-09 David Schnepper
*/
#define FB_GDS_ASSERT_FAILURE_STRING "GDS Assertion failure: %s %"LINEFORMAT"\n"
#define FB_GDS_ASSERT_FAILURE_STRING "GDS Assertion (%s) failure: %s %"LINEFORMAT"\n"
#ifdef SUPERSERVER
#if !defined(fb_assert)
#define fb_assert(ex) {if (!(ex)) {gds__log (FB_GDS_ASSERT_FAILURE_STRING, __FILE__, __LINE__); abort();}}
#define fb_assert_continue(ex) {if (!(ex)) {gds__log (FB_GDS_ASSERT_FAILURE_STRING, __FILE__, __LINE__);}}
#define fb_assert(ex) {if (!(ex)) {gds__log (FB_GDS_ASSERT_FAILURE_STRING, #ex, __FILE__, __LINE__); abort();}}
#define fb_assert_continue(ex) {if (!(ex)) {gds__log (FB_GDS_ASSERT_FAILURE_STRING, #ex, __FILE__, __LINE__);}}
#endif
#else // !SUPERSERVER
#if !defined(fb_assert)
#define fb_assert(ex) {if (!(ex)) {fprintf (stderr, FB_GDS_ASSERT_FAILURE_STRING, __FILE__, __LINE__); abort();}}
#define fb_assert_continue(ex) {if (!(ex)) {fprintf (stderr, FB_GDS_ASSERT_FAILURE_STRING, __FILE__, __LINE__);}}
#define fb_assert(ex) {if (!(ex)) {fprintf (stderr, FB_GDS_ASSERT_FAILURE_STRING, #ex, __FILE__, __LINE__); abort();}}
#define fb_assert_continue(ex) {if (!(ex)) {fprintf (stderr, FB_GDS_ASSERT_FAILURE_STRING, #ex, __FILE__, __LINE__);}}
#endif
#endif // SUPERSERVER

View File

@ -52,7 +52,6 @@
#include "../jrd/jrd_proto.h"
#include "../jrd/met_proto.h"
#include "../jrd/scl_proto.h"
#include "../jrd/thd.h"
#include "../common/utils_proto.h"
#include "../common/classes/array.h"

View File

@ -63,7 +63,6 @@
#include "../jrd/met_proto.h"
#include "../jrd/mov_proto.h"
#include "../jrd/sort_proto.h"
#include "../jrd/thd.h"
#include "../jrd/vio_proto.h"
#include "../jrd/tra_proto.h"

View File

@ -57,7 +57,6 @@
#include "../jrd/opt_proto.h"
#include "../jrd/pag_proto.h"
#include "../jrd/os/pio_proto.h"
#include "../jrd/thd.h"
#include "../jrd/tra_proto.h"
#include "../jrd/gds_proto.h"
#include "../jrd/err_proto.h"

View File

@ -51,7 +51,6 @@
#include "../jrd/ini_proto.h"
#include "../jrd/jrd_proto.h"
#include "../jrd/met_proto.h"
#include "../jrd/thd.h"
#include "../jrd/obj.h"
#include "../jrd/acl.h"
#include "../jrd/irq.h"

View File

@ -118,7 +118,6 @@
#include "../jrd/isc_proto.h"
#include "../jrd/lck_proto.h"
#include "../jrd/met_proto.h"
#include "../jrd/thd.h"
#include "../jrd/intlobj_new.h"
#include "../jrd/jrd.h"
#include "../jrd/mov_proto.h"

View File

@ -66,7 +66,6 @@
#include "../jrd/jrd.h"
#include "../jrd/sch_proto.h"
#include "../jrd/err_proto.h"
#include "../jrd/thd.h"
#include "../jrd/thread_proto.h"
#include "../jrd/jrd_pwd.h"
#include "../common/config/config.h"

View File

@ -143,7 +143,7 @@ int debug;
namespace
{
REC_MUTX_T databases_rec_mutex;
Firebird::GlobalPtr<Firebird::RecursiveMutex> databases_rec_mutex;
Database* databases = NULL;
class EngineStartup
@ -164,16 +164,18 @@ namespace
Firebird::InitMutex<EngineStartup> engineStartup;
// Here we always ignore mutex errors, Possibly not good.
inline void dbMutexLock()
{
THREAD_EXIT();
THD_rec_mutex_lock(&databases_rec_mutex);
databases_rec_mutex->enter();
THREAD_ENTER();
}
inline void dbMutexUnlock()
{
THD_rec_mutex_unlock(&databases_rec_mutex);
databases_rec_mutex->leave();
}
} // anonymous
@ -194,7 +196,7 @@ void Jrd::Trigger::compile(thread_db* tdbb)
Database* dbb = tdbb->getDatabase();
THREAD_EXIT();
const int error = THD_rec_mutex_lock(&dbb->dbb_sp_rec_mutex);
const int error = dbb->dbb_sp_rec_mutex.enter();
THREAD_ENTER();
if (error) {
@ -202,7 +204,7 @@ void Jrd::Trigger::compile(thread_db* tdbb)
}
if (request)
{
THD_rec_mutex_unlock(&dbb->dbb_sp_rec_mutex);
dbb->dbb_sp_rec_mutex.leave();
return;
}
#endif /* SUPERSERVER */
@ -248,7 +250,7 @@ void Jrd::Trigger::compile(thread_db* tdbb)
}
#ifdef SUPERSERVER
THD_rec_mutex_unlock(&dbb->dbb_sp_rec_mutex);
dbb->dbb_sp_rec_mutex.leave();
#endif
throw;
}
@ -267,7 +269,7 @@ void Jrd::Trigger::compile(thread_db* tdbb)
compile_in_progress = false;
#ifdef SUPERSERVER
THD_rec_mutex_unlock(&dbb->dbb_sp_rec_mutex);
dbb->dbb_sp_rec_mutex.leave();
#endif
}
}

View File

@ -93,7 +93,7 @@
#include "../jrd/isc.h"
// recursive mutexes
#include "../jrd/thd.h"
#include "../common/thd.h"
// Definition of block types for data allocation in JRD
#include "../jrd/jrd_blks.h"
@ -237,7 +237,7 @@ public:
DatabaseModules modules; // external function/filter modules
Firebird::Mutex* dbb_mutexes; // Database block mutexes
REC_MUTX_T dbb_sp_rec_mutex; // Recursive mutex for accessing/updating stored procedure metadata
Firebird::RecursiveMutex dbb_sp_rec_mutex; // Recursive mutex for accessing/updating stored procedure metadata
//SLONG dbb_sort_size; // Size of sort space per sort, unused for now
UATOM dbb_ast_flags; // flags modified at AST level
@ -1093,8 +1093,6 @@ public:
* there is no database set up.
*/
#include "../jrd/thd.h"
#if defined(DEV_BUILD)
#include "../jrd/err_proto.h"

View File

@ -28,7 +28,6 @@
#define JRD_PWD_H
#include "../jrd/ibase.h"
#include "../jrd/thd.h"
#include "../jrd/sha.h"
#ifdef HAVE_STDLIB_H
#include <stdlib.h>

View File

@ -40,7 +40,6 @@
#include "../jrd/lck_proto.h"
#include "../lock/lock_proto.h"
#include "../jrd/sch_proto.h"
#include "../jrd/thd.h"
#include "../jrd/gdsassert.h"
#ifdef HAVE_SYS_TYPES_H

View File

@ -33,7 +33,6 @@
#include "../jrd/gds_proto.h"
#include "../jrd/log_proto.h"
#include "../jrd/pag_proto.h"
#include "../jrd/thd.h"

View File

@ -92,7 +92,6 @@
#include "../jrd/os/pio_proto.h"
#include "../jrd/scl_proto.h"
#include "../jrd/sdw_proto.h"
#include "../jrd/thd.h"
#include "../jrd/sch_proto.h"
#include "../jrd/thread_proto.h"
#include "../jrd/iberr.h"
@ -3008,7 +3007,7 @@ jrd_prc* MET_procedure(thread_db* tdbb, int id, bool noscan, USHORT flags)
THREAD_EXIT();
if (THD_rec_mutex_lock(&dbb->dbb_sp_rec_mutex))
if (dbb->dbb_sp_rec_mutex.enter())
{
THREAD_ENTER();
return NULL;
@ -3048,7 +3047,7 @@ jrd_prc* MET_procedure(thread_db* tdbb, int id, bool noscan, USHORT flags)
if ((procedure->prc_flags & PRC_being_scanned) ||
(procedure->prc_flags & PRC_scanned))
{
THD_rec_mutex_unlock(&dbb->dbb_sp_rec_mutex);
dbb->dbb_sp_rec_mutex.leave();
return procedure;
}
}
@ -3347,12 +3346,12 @@ jrd_prc* MET_procedure(thread_db* tdbb, int id, bool noscan, USHORT flags)
fb_assert(procedure->prc_flags & PRC_being_scanned);
procedure->prc_flags &= ~PRC_being_scanned;
THD_rec_mutex_unlock(&dbb->dbb_sp_rec_mutex);
dbb->dbb_sp_rec_mutex.leave();
} // try
catch (const Firebird::Exception&) {
procedure->prc_flags &= ~(PRC_being_scanned | PRC_scanned);
THD_rec_mutex_unlock(&dbb->dbb_sp_rec_mutex);
dbb->dbb_sp_rec_mutex.leave();
if (procedure->prc_existence_lock)
{
LCK_release(tdbb, procedure->prc_existence_lock);
@ -3717,7 +3716,7 @@ void MET_scan_relation( thread_db* tdbb, jrd_rel* relation)
Database* dbb = tdbb->getDatabase();
THREAD_EXIT();
if (THD_rec_mutex_lock(&dbb->dbb_sp_rec_mutex)) {
if (dbb->dbb_sp_rec_mutex.enter()) {
THREAD_ENTER();
return;
}
@ -3726,7 +3725,7 @@ void MET_scan_relation( thread_db* tdbb, jrd_rel* relation)
if (relation->rel_flags & REL_scanned
|| relation->rel_flags & REL_deleted)
{
THD_rec_mutex_unlock(&dbb->dbb_sp_rec_mutex);
dbb->dbb_sp_rec_mutex.leave();
return;
}
@ -4064,7 +4063,7 @@ void MET_scan_relation( thread_db* tdbb, jrd_rel* relation)
}
relation->rel_flags &= ~REL_being_scanned;
THD_rec_mutex_unlock(&dbb->dbb_sp_rec_mutex);
dbb->dbb_sp_rec_mutex.leave();
relation->rel_current_format = NULL;
@ -4080,7 +4079,7 @@ void MET_scan_relation( thread_db* tdbb, jrd_rel* relation)
if (blob)
BLB_close(tdbb, blob);
THD_rec_mutex_unlock(&dbb->dbb_sp_rec_mutex);
dbb->dbb_sp_rec_mutex.leave();
// Some functions inside FOR loop may throw, in which case request
// remained active forever. AP: 13-may-05.

View File

@ -47,7 +47,6 @@
#include "../jrd/mov_proto.h"
#include "../jrd/nav_proto.h"
#include "../jrd/rse_proto.h"
#include "../jrd/thd.h"
#include "../jrd/vio_proto.h"
using namespace Jrd;

View File

@ -38,7 +38,6 @@
#include "err_proto.h"
#include "cch_proto.h"
#include "isc_proto.h"
#include "thd.h"
#include "../jrd/thread_proto.h"
#include "os/pio_proto.h"
#include "gen/iberror.h"

View File

@ -58,7 +58,6 @@
#include "../jrd/sort.h"
#include "../jrd/rse.h"
#include "../jrd/intl.h"
#include "../jrd/thd.h"
#include "../jrd/gdsassert.h"
#include "../jrd/btr_proto.h"
#include "../jrd/cch_proto.h"

View File

@ -47,8 +47,8 @@
#include "../jrd/isc_proto.h"
#include "../jrd/os/isc_i_proto.h"
#include "../jrd/isc_s_proto.h"
#include "../jrd/thd.h"
#include "../common/classes/locks.h"
#include "../common/classes/init.h"
#ifdef HAVE_VFORK_H
#include <vfork.h>
@ -115,7 +115,7 @@ static bool initialized_signals = false;
static SIG volatile signals = NULL;
static SLONG volatile overflow_count = 0;
static Firebird::Mutex sig_mutex;
static Firebird::GlobalPtr<Firebird::Mutex> sig_mutex;
static int process_id = 0;
@ -295,7 +295,7 @@ static bool isc_signal2(
if (!process_id)
process_id = getpid();
sig_mutex.enter();
Firebird::MutexLockGuard guard(sig_mutex);
/* See if this signal has ever been cared about before */
@ -338,8 +338,6 @@ static bool isc_signal2(
que_signal(signal_number, handler, arg, flags, old_sig_w_siginfo);
sig_mutex.leave();
return rc;
}
@ -362,7 +360,7 @@ void ISC_signal_cancel(
SIG sig;
volatile SIG* ptr;
sig_mutex.enter();
Firebird::MutexLockGuard guard(sig_mutex);
for (ptr = &signals; sig = *ptr;) {
if (sig->sig_signal == signal_number &&
@ -375,9 +373,6 @@ void ISC_signal_cancel(
else
ptr = &(*ptr)->sig_next;
}
sig_mutex.leave();
}

View File

@ -64,7 +64,6 @@
#include "../jrd/mov_proto.h"
#include "../jrd/ods_proto.h"
#include "../jrd/os/pio_proto.h"
#include "../jrd/thd.h"
#include "../common/classes/init.h"
using namespace Jrd;

View File

@ -39,7 +39,6 @@
#include "../common/classes/alloc.h"
#include "../common/classes/init.h"
#include "../common/classes/array.h"
#include "../jrd/thd.h"
#include <windows.h>
#include <process.h>
@ -63,7 +62,7 @@ private:
Firebird::InlineStorage<ThreadPriorityScheduler*, 16> > TpsPointers;
enum OperationMode {Running, Stopping, ShutdownComplete};
static Firebird::Mutex mutex; // locks modification of thps chains
static Firebird::GlobalPtr<Firebird::Mutex> mutex; // locks modification of thps chains
static ThreadPriorityScheduler* chain; // where starts thps chain
static Firebird::InitMutex<ThreadPriorityScheduler> initialized;
static OperationMode opMode; // current mode

View File

@ -24,7 +24,6 @@
#include "firebird.h"
#include "../jrd/common.h"
#include "gen/iberror.h"
#include "../jrd/thd.h"
#include "../jrd/gdsassert.h"
#include "../jrd/event_proto.h"
#include "../jrd/gds_proto.h"

View File

@ -46,7 +46,7 @@ private:
tReportEvent *fReportEvent;
bool InitFlag;
public:
SyslogAccess() {
SyslogAccess(Firebird::MemoryPool&) {
InitializeCriticalSection(&cs);
InitFlag = false;
LogHandle = 0;
@ -84,7 +84,7 @@ void SyslogAccess::Record(WORD wType, const Firebird::string& Msg)
LeaveCriticalSection(&cs);
}
class SyslogAccess iSyslogAccess;
Firebird::InitInstance<SyslogAccess> iSyslogAccess;
} // namespace
namespace Firebird {
@ -100,6 +100,6 @@ namespace Firebird {
wType = EVENTLOG_ERROR_TYPE;
break;
}
iSyslogAccess.Record(wType, Msg);
iSyslogAccess().Record(wType, Msg);
}
} // namespace Firebird

View File

@ -45,7 +45,6 @@
#include "../jrd/isc_proto.h"
#include "../jrd/os/isc_i_proto.h"
#include "../jrd/isc_s_proto.h"
#include "../jrd/thd.h"
#include <windows.h>
#include <process.h>
@ -67,8 +66,6 @@
static USHORT initialized_signals = FALSE;
static SLONG volatile overflow_count = 0;
static Firebird::Mutex sig_mutex;
static int process_id = 0;
const USHORT MAX_OPN_EVENTS = 40;

View File

@ -49,7 +49,7 @@
// #define DEBUG_THREAD_PSCHED
Firebird::Mutex ThreadPriorityScheduler::mutex;
Firebird::GlobalPtr<Firebird::Mutex> ThreadPriorityScheduler::mutex;
ThreadPriorityScheduler* ThreadPriorityScheduler::chain = 0;
Firebird::InitMutex<ThreadPriorityScheduler> ThreadPriorityScheduler::initialized;
ThreadPriorityScheduler::OperationMode
@ -109,9 +109,8 @@ void ThreadPriorityScheduler::Cleanup(void*)
void ThreadPriorityScheduler::cleanup()
{
mutex.enter();
Firebird::MutexLockGuard guard(mutex);
opMode = Stopping;
mutex.leave();
}
void ThreadPriorityScheduler::attach()
@ -125,10 +124,11 @@ void ThreadPriorityScheduler::attach()
{
Firebird::system_call_failed::raise("DuplicateHandle", GetLastError());
}
mutex.enter();
next = chain;
chain = this;
mutex.leave();
{
Firebird::MutexLockGuard guard(mutex);
next = chain;
chain = this;
}
#ifdef DEBUG_THREAD_PSCHED
gds__log("^ handle=%p priority=%d", handle,
flags & THPS_BOOSTED ?
@ -152,7 +152,7 @@ void ThreadPriorityScheduler::detach()
{
if (active)
{
mutex.enter();
Firebird::MutexLockGuard guard(mutex);
TLS_SET(currentScheduler, 0);
if (opMode == ShutdownComplete)
{
@ -173,7 +173,6 @@ void ThreadPriorityScheduler::detach()
{
toDetach->add(this);
}
mutex.leave();
}
else
{
@ -269,9 +268,8 @@ unsigned int __stdcall ThreadPriorityScheduler::schedulerMain(LPVOID)
if (toDetach->getCount() > 0)
{
mutex.enter();
Firebird::MutexLockGuard guard(mutex);
doDetach();
mutex.leave();
}
}
return 0;

View File

@ -96,7 +96,6 @@
#include "../jrd/ods_proto.h"
#include "../jrd/pag_proto.h"
#include "../jrd/os/pio_proto.h"
#include "../jrd/thd.h"
#include "../jrd/thread_proto.h"
#include "../jrd/isc_f_proto.h"
#include "../jrd/TempSpace.h"

View File

@ -63,7 +63,6 @@
#include "../jrd/gds_proto.h"
#include "../jrd/met_proto.h"
#include "../jrd/par_proto.h"
#include "../jrd/thd.h"
#include "../common/utils_proto.h"
#include "../jrd/SysFunction.h"

View File

@ -48,7 +48,6 @@
#include "../jrd/met_proto.h"
#include "../jrd/mov_proto.h"
#include "../jrd/pcmet_proto.h"
#include "../jrd/thd.h"
using namespace Jrd;

View File

@ -35,7 +35,6 @@
#include "../jrd/err_proto.h"
#include "../jrd/gds_proto.h"
#include "../jrd/sch_proto.h"
#include "../jrd/thd.h"
#include "../jrd/thread_proto.h"
#include "../jrd/jrd_proto.h"
#include "../jrd/scl.h"

View File

@ -101,7 +101,6 @@ defined APIs for this function.
#include "../jrd/err_proto.h"
#include "../jrd/flu_proto.h"
#include "../jrd/sch_proto.h"
#include "../jrd/thd.h"
#include "../jrd/thread_proto.h"
#ifdef WIN_NT
#include <windows.h>

View File

@ -66,7 +66,6 @@
#include "../jrd/rlck_proto.h"
#include "../jrd/rse_proto.h"
#include "../jrd/sort_proto.h"
#include "../jrd/thd.h"
#include "../jrd/vio_proto.h"
#include "../jrd/VirtualTable.h"

View File

@ -40,6 +40,7 @@
#include "../jrd/gdsassert.h"
#include "../jrd/os/thd_priority.h"
#include "../common/classes/locks.h"
#include "../common/classes/init.h"
#ifdef WIN_NT
#include <windows.h>
@ -76,14 +77,14 @@ static void stall_ast(THREAD);
static THREAD free_threads = NULL;
static THREAD active_thread = NULL;
static THREAD ast_thread = NULL;
static Firebird::Mutex thread_mutex;
static Firebird::GlobalPtr<Firebird::Mutex> thread_mutex;
namespace {
class SchedulerInit
{
public:
SchedulerInit()
SchedulerInit(Firebird::MemoryPool&)
{}
~SchedulerInit()
@ -123,14 +124,14 @@ public:
} // namespace
static SchedulerInit initHolder;
static Firebird::GlobalPtr<SchedulerInit> initHolder;
static inline void sch_mutex_lock()
{
try
{
thread_mutex.enter();
thread_mutex->enter();
}
catch (const Firebird::system_call_failed& e)
{
@ -142,7 +143,7 @@ static inline void sch_mutex_unlock()
{
try
{
thread_mutex.leave();
thread_mutex->leave();
}
catch (const Firebird::system_call_failed& e)
{

Some files were not shown because too many files have changed in this diff Show More