From: <ale...@us...> - 2010-06-08 13:35:52
|
Revision: 51231 http://firebird.svn.sourceforge.net/firebird/?rev=51231&view=rev Author: alexpeshkoff Date: 2010-06-08 13:35:46 +0000 (Tue, 08 Jun 2010) Log Message: ----------- Mac port - use dispatch semaphores Modified Paths: -------------- firebird/trunk/src/common/classes/semaphore.cpp firebird/trunk/src/common/classes/semaphore.h Modified: firebird/trunk/src/common/classes/semaphore.cpp =================================================================== --- firebird/trunk/src/common/classes/semaphore.cpp 2010-06-08 13:35:24 UTC (rev 51230) +++ firebird/trunk/src/common/classes/semaphore.cpp 2010-06-08 13:35:46 UTC (rev 51231) @@ -33,23 +33,18 @@ #ifdef COMMON_CLASSES_SEMAPHORE_MACH - void SignalSafeSemaphore::machErrorCheck(kern_return_t rc, const char* fun) + void SignalSafeSemaphore::init() { - if (rc != KERN_SUCCESS) + semaphore = dispatch_semaphore_create(0); + if (!semaphore) // With const zero parameter this means OOM { - (Arg::Gds(isc_sys_request) << fun << Arg::Mach(static_cast<ISC_STATUS>(rc))).raise(); + BadAlloc::raise(); } } - void SignalSafeSemaphore::init() - { - machErrorCheck(semaphore_create(mach_task_self(), &sem, SYNC_POLICY_FIFO, 0), - "semaphore_create"); - } - SignalSafeSemaphore::~SignalSafeSemaphore() { - machErrorCheck(semaphore_destroy(mach_task_self(), sem), "semaphore_destroy"); + dispatch_release(semaphore); } #endif // COMMON_CLASSES_SEMAPHORE_MACH Modified: firebird/trunk/src/common/classes/semaphore.h =================================================================== --- firebird/trunk/src/common/classes/semaphore.h 2010-06-08 13:35:24 UTC (rev 51230) +++ firebird/trunk/src/common/classes/semaphore.h 2010-06-08 13:35:46 UTC (rev 51231) @@ -93,9 +93,7 @@ // Mach semaphore #define COMMON_CLASSES_SEMAPHORE_MACH -#include <mach/mach.h> -#include <mach/semaphore.h> -#include <mach/task.h> +#include <dispatch/dispatch.h> namespace Firebird { @@ -105,9 +103,8 @@ class SignalSafeSemaphore { private: - semaphore_t sem; + dispatch_semaphore_t semaphore; - static void machErrorCheck(kern_return_t rc, const char* function); void init(); public: @@ -118,7 +115,7 @@ void enter() { - machErrorCheck(semaphore_wait(sem), "semaphore_wait"); + dispatch_semaphore_wait(semaphore); } void release(SLONG count = 1) @@ -126,7 +123,7 @@ fb_assert(count >= 0); while (count--) { - machErrorCheck(semaphore_signal(sem), "semaphore_signal"); + dispatch_semaphore_signal(semaphore); } } }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ale...@us...> - 2010-10-15 15:53:44
|
Revision: 51708 http://firebird.svn.sourceforge.net/firebird/?rev=51708&view=rev Author: alexpeshkoff Date: 2010-10-15 15:53:38 +0000 (Fri, 15 Oct 2010) Log Message: ----------- Fixed issues, found by clang Modified Paths: -------------- firebird/trunk/src/common/classes/array.h firebird/trunk/src/common/classes/stack.h firebird/trunk/src/common/classes/vector.h Modified: firebird/trunk/src/common/classes/array.h =================================================================== --- firebird/trunk/src/common/classes/array.h 2010-10-15 15:52:44 UTC (rev 51707) +++ firebird/trunk/src/common/classes/array.h 2010-10-15 15:53:38 UTC (rev 51708) @@ -456,7 +456,7 @@ { size_t pos; find(KeyOfValue::generate(this, item), pos); - insert(pos, item); + this->insert(pos, item); return pos; } }; Modified: firebird/trunk/src/common/classes/stack.h =================================================================== --- firebird/trunk/src/common/classes/stack.h 2010-10-15 15:52:44 UTC (rev 51707) +++ firebird/trunk/src/common/classes/stack.h 2010-10-15 15:53:38 UTC (rev 51708) @@ -48,7 +48,7 @@ Entry(Object e, Entry* stk) : inherited(), next(stk) { - add(e); + this->add(e); } Entry(Entry* stk) : inherited(), next(stk) { } @@ -62,7 +62,7 @@ { if (inherited::getCount() < this->getCapacity()) { - add(e); + this->add(e); return this; } Entry* newEntry = FB_NEW(p) Entry(e, this); Modified: firebird/trunk/src/common/classes/vector.h =================================================================== --- firebird/trunk/src/common/classes/vector.h 2010-10-15 15:52:44 UTC (rev 51707) +++ firebird/trunk/src/common/classes/vector.h 2010-10-15 15:53:38 UTC (rev 51708) @@ -169,7 +169,7 @@ { size_t pos; find(KeyOfValue::generate(this, item), pos); - insert(pos, item); + this->insert(pos, item); return pos; } }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ale...@us...> - 2010-10-27 09:49:22
|
Revision: 51784 http://firebird.svn.sourceforge.net/firebird/?rev=51784&view=rev Author: alexpeshkoff Date: 2010-10-27 09:49:16 +0000 (Wed, 27 Oct 2010) Log Message: ----------- Fixed performance issues when creating and destroying pools Modified Paths: -------------- firebird/trunk/src/common/classes/alloc.cpp firebird/trunk/src/common/classes/alloc.h Modified: firebird/trunk/src/common/classes/alloc.cpp =================================================================== --- firebird/trunk/src/common/classes/alloc.cpp 2010-10-27 03:18:06 UTC (rev 51783) +++ firebird/trunk/src/common/classes/alloc.cpp 2010-10-27 09:49:16 UTC (rev 51784) @@ -163,14 +163,28 @@ } } -MemoryPool::MemoryPool(MemoryStats& s, bool shared, int rounding, int cutoff, int minAlloc) +MemoryPool::MemoryPool(bool shared, int rounding, int cutoff, int minAlloc) : roundingSize(rounding), threshold(cutoff), minAllocation(minAlloc), - threadShared(shared), pool_destroying(false), stats(&s) + threadShared(shared), pool_destroying(false), stats(default_stats_group), parent(NULL) { size_t vecSize = (cutoff + rounding) / rounding; size_t l = vecSize * sizeof(void*); - freeObjects = (MemBlock**) allocRaw(l); - memset(freeObjects, 0, l); + init(allocRaw(l), l); +} + +MemoryPool::MemoryPool(MemoryPool& p, MemoryStats& s, bool shared, int rounding, int cutoff, int minAlloc) + : roundingSize(rounding), threshold(cutoff), minAllocation(minAlloc), + threadShared(shared), pool_destroying(false), stats(&s), parent(&p) +{ + size_t vecSize = (cutoff + rounding) / rounding; + size_t l = vecSize * sizeof(void*); + init(parent->allocate(l), l); +} + +void MemoryPool::init(void* memory, size_t length) +{ + freeObjects = (MemBlock**) memory; + memset(freeObjects, 0, length); bigHunks = NULL; smallHunks = NULL; freeBlocks.nextLarger = freeBlocks.priorSmaller = &freeBlocks; @@ -186,11 +200,6 @@ #endif } -MemoryPool* MemoryPool::createPool(MemoryPool* parentPool, MemoryStats&) -{ - return FB_NEW(*(parentPool ? parentPool : getDefaultMemoryPool())) MemoryPool(); -} - MemoryPool::~MemoryPool(void) { pool_destroying = true; @@ -214,7 +223,14 @@ } #endif - releaseRaw(freeObjects, ((threshold + roundingSize) / roundingSize) * sizeof(void*)); + if (parent) + { + MemoryPool::release(freeObjects); + } + else + { + releaseRaw(freeObjects, ((threshold + roundingSize) / roundingSize) * sizeof(void*)); + } freeObjects = NULL; for (MemSmallHunk* hunk; hunk = smallHunks;) @@ -230,6 +246,15 @@ } } +MemoryPool* MemoryPool::createPool(MemoryPool* parentPool, MemoryStats& stats) +{ + if (!parentPool) + { + parentPool = getDefaultMemoryPool(); + } + return FB_NEW(*parentPool) MemoryPool(*parentPool, stats); +} + void MemoryPool::setStatsGroup(MemoryStats& newStats) throw () { MutexLockGuard guard(mutex, "MemoryPool::setStatsGroup"); Modified: firebird/trunk/src/common/classes/alloc.h =================================================================== --- firebird/trunk/src/common/classes/alloc.h 2010-10-27 03:18:06 UTC (rev 51783) +++ firebird/trunk/src/common/classes/alloc.h 2010-10-27 09:49:16 UTC (rev 51784) @@ -232,12 +232,16 @@ class MemoryPool { -public: - MemoryPool(MemoryStats& stats = *default_stats_group, +private: + MemoryPool(MemoryPool& parent, MemoryStats& stats, bool shared = true, int rounding = DEFAULT_ROUNDING, int cutoff = DEFAULT_CUTOFF, int minAllocation = DEFAULT_ALLOCATION); + MemoryPool(bool shared = true, int rounding = DEFAULT_ROUNDING, + int cutoff = DEFAULT_CUTOFF, int minAllocation = DEFAULT_ALLOCATION); + void init(void* memory, size_t length); virtual ~MemoryPool(void); +public: static MemoryPool* defaultMemoryManager; private: @@ -258,6 +262,8 @@ static MemoryStats* default_stats_group; // Statistics group for the pool MemoryStats* stats; + // Parent pool if present + MemoryPool* parent; // Memory used AtomicCounter used_memory, mapped_memory; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ale...@us...> - 2010-11-04 16:22:49
|
Revision: 51843 http://firebird.svn.sourceforge.net/firebird/?rev=51843&view=rev Author: alexpeshkoff Date: 2010-11-04 16:22:42 +0000 (Thu, 04 Nov 2010) Log Message: ----------- Make fb_string's length limit type-dependent Modified Paths: -------------- firebird/trunk/src/common/classes/fb_string.cpp firebird/trunk/src/common/classes/fb_string.h Modified: firebird/trunk/src/common/classes/fb_string.cpp =================================================================== --- firebird/trunk/src/common/classes/fb_string.cpp 2010-11-04 15:28:08 UTC (rev 51842) +++ firebird/trunk/src/common/classes/fb_string.cpp 2010-11-04 16:22:42 UTC (rev 51843) @@ -87,20 +87,23 @@ { const AbstractString::size_type AbstractString::npos = (AbstractString::size_type)(~0); - AbstractString::AbstractString(const AbstractString& v) + AbstractString::AbstractString(const size_type limit, const AbstractString& v) + : max_length(limit) { initialize(v.length()); memcpy(stringBuffer, v.c_str(), v.length()); } - AbstractString::AbstractString(const size_type sizeL, const void* dataL) + AbstractString::AbstractString(const size_type limit, const size_type sizeL, const void* dataL) + : max_length(limit) { initialize(sizeL); memcpy(stringBuffer, dataL, sizeL); } - AbstractString::AbstractString(const_pointer p1, const size_type n1, + AbstractString::AbstractString(const size_type limit, const_pointer p1, const size_type n1, const_pointer p2, const size_type n2) + : max_length(limit) { // CVC: npos must be maximum size_type value for all platforms. // fb_assert(n2 < npos - n1 && n1 + n2 <= max_length()); @@ -114,7 +117,8 @@ memcpy(stringBuffer + n1, p2, n2); } - AbstractString::AbstractString(const size_type sizeL, char_type c) + AbstractString::AbstractString(const size_type limit, const size_type sizeL, char_type c) + : max_length(limit) { initialize(sizeL); memset(stringBuffer, c, sizeL); @@ -175,8 +179,8 @@ void AbstractString::reserve(size_type n) { // Do not allow to reserve huge buffers - if (n > max_length()) - n = max_length(); + if (n > getMaxLength()) + n = getMaxLength(); reserveBuffer(n); } @@ -426,16 +430,16 @@ while (true) { n *= 2; - if (n > max_length()) - n = max_length(); + if (n > getMaxLength()) + n = getMaxLength(); FB_VA_COPY(paramsCopy, params); l = VSNPRINTF(baseAssign(n), n + 1, format, paramsCopy); FB_CLOSE_VACOPY(paramsCopy); if (l >= 0) break; - if (n >= max_length()) + if (n >= getMaxLength()) { - stringBuffer[max_length()] = 0; + stringBuffer[getMaxLength()] = 0; return; } } Modified: firebird/trunk/src/common/classes/fb_string.h =================================================================== --- firebird/trunk/src/common/classes/fb_string.h 2010-11-04 15:28:08 UTC (rev 51842) +++ firebird/trunk/src/common/classes/fb_string.h 2010-11-04 16:22:42 UTC (rev 51843) @@ -58,7 +58,12 @@ enum {INLINE_BUFFER_SIZE = 32, INIT_RESERVE = 16/*, KEEP_SIZE = 512*/}; protected: - typedef USHORT internal_size_type; // 16 bits! + typedef ULONG internal_size_type; // 32 bits! + + private: + const internal_size_type max_length; + + protected: char_type inlineBuffer[INLINE_BUFFER_SIZE]; char_type* stringBuffer; internal_size_type stringLength, bufferSize; @@ -71,9 +76,9 @@ } } - static void checkLength(size_type len) + void checkLength(size_type len) { - if (len > max_length()) { + if (len > getMaxLength()) { fatal_exception::raise("Firebird::string - length exceeds predefined limit"); } } @@ -95,8 +100,9 @@ newSize = size_t(bufferSize) * 2u; // Do not grow buffer beyond string length limit - if (newSize > max_length() + 1) - newSize = max_length() + 1; + size_type max_length = getMaxLength() + 1; + if (newSize > max_length) + newSize = max_length; // Allocate new buffer char_type *newBuffer = FB_NEW(getPool()) char_type[newSize]; @@ -130,8 +136,9 @@ size_type newSize = len + 1 + INIT_RESERVE; // Do not grow buffer beyond string length limit - if (newSize > max_length() + 1) - newSize = max_length() + 1; + size_type max_length = getMaxLength() + 1; + if (newSize > max_length) + newSize = max_length; // Allocate new buffer stringBuffer = FB_NEW(getPool()) char_type[newSize]; @@ -147,36 +154,36 @@ } protected: - AbstractString(const size_type sizeL, const void* datap); + AbstractString(const size_type limit, const size_type sizeL, const void* datap); - AbstractString(const_pointer p1, const size_type n1, + AbstractString(const size_type limit, const_pointer p1, const size_type n1, const_pointer p2, const size_type n2); - AbstractString(const AbstractString& v); + AbstractString(const size_type limit, const AbstractString& v); - AbstractString() : - stringBuffer(inlineBuffer), stringLength(0), bufferSize(INLINE_BUFFER_SIZE) + AbstractString(const size_type limit) : + max_length(limit), stringBuffer(inlineBuffer), stringLength(0), bufferSize(INLINE_BUFFER_SIZE) { stringBuffer[0] = 0; } - AbstractString(const size_type sizeL, char_type c); + AbstractString(const size_type limit, const size_type sizeL, char_type c); - explicit AbstractString(MemoryPool& p) : AutoStorage(p), - stringBuffer(inlineBuffer), stringLength(0), bufferSize(INLINE_BUFFER_SIZE) + AbstractString(const size_type limit, MemoryPool& p) : AutoStorage(p), + max_length(limit), stringBuffer(inlineBuffer), stringLength(0), bufferSize(INLINE_BUFFER_SIZE) { stringBuffer[0] = 0; } - AbstractString(MemoryPool& p, const AbstractString& v) - : AutoStorage(p) + AbstractString(const size_type limit, MemoryPool& p, const AbstractString& v) + : AutoStorage(p), max_length(limit) { initialize(v.length()); memcpy(stringBuffer, v.c_str(), stringLength); } - AbstractString(MemoryPool& p, const void* s, const size_type l) - : AutoStorage(p) + AbstractString(const size_type limit, MemoryPool& p, const void* s, const size_type l) + : AutoStorage(p), max_length(limit) { initialize(l); memcpy(stringBuffer, s, l); @@ -202,6 +209,11 @@ void baseTrim(const TrimType whereTrim, const_pointer toTrim); + size_type getMaxLength() + { + return max_length; + } + public: const_pointer c_str() const { @@ -351,10 +363,6 @@ { return length(); } - static size_type max_length() - { - return 0xfffe; // Max length of character field in Firebird - } size_type capacity() const { return bufferSize - 1u; @@ -574,48 +582,72 @@ { return memcmp(s1, s2, n); } + + static AbstractString::size_type getMaxLength() + { + return 0xFFFFFFFEu; + } }; + class PathNameComparator { public: static int compare(AbstractString::const_pointer s1, AbstractString::const_pointer s2, const AbstractString::size_type n); + + static AbstractString::size_type getMaxLength() + { + return 0xFFFEu; + } }; + class IgnoreCaseComparator { public: static int compare(AbstractString::const_pointer s1, AbstractString::const_pointer s2, const AbstractString::size_type n); + + static AbstractString::size_type getMaxLength() + { + return 0xFFFFFFFEu; + } }; template<typename Comparator> class StringBase : public AbstractString { - typedef StringBase<Comparator> StringType; + typedef StringBase StringType; protected: - StringBase<Comparator>(const_pointer p1, size_type n1, - const_pointer p2, size_type n2) : - AbstractString(p1, n1, p2, n2) {} + StringBase(const_pointer p1, size_type n1, + const_pointer p2, size_type n2) : + AbstractString(Comparator::getMaxLength(), p1, n1, p2, n2) {} private: StringType add(const_pointer s, size_type n) const { return StringBase<Comparator>(c_str(), length(), s, n); } public: - StringBase<Comparator>() : AbstractString() {} - StringBase<Comparator>(const StringType& v) : AbstractString(v) {} - StringBase<Comparator>(const void* s, size_type n) : AbstractString(n, s) {} - StringBase<Comparator>(const_pointer s) : AbstractString(strlen(s), s) {} - explicit StringBase<Comparator>(const unsigned char* s) : AbstractString(strlen((char*)s), (char*)s) {} - StringBase<Comparator>(size_type n, char_type c) : AbstractString(n, c) {} - //explicit StringBase<Comparator>(char_type c) : AbstractString(1, c) {} - StringBase<Comparator>(const_iterator first, const_iterator last) : AbstractString(last - first, first) {} - explicit StringBase<Comparator>(MemoryPool& p) : AbstractString(p) {} - StringBase<Comparator>(MemoryPool& p, const AbstractString& v) : AbstractString(p, v) {} - StringBase<Comparator>(MemoryPool& p, const char_type* s, size_type l) : AbstractString(p, s, l) {} + StringBase() : AbstractString(Comparator::getMaxLength()) {} + StringBase(const StringType& v) : AbstractString(Comparator::getMaxLength(), v) {} + StringBase(const void* s, size_type n) : AbstractString(Comparator::getMaxLength(), n, s) {} + StringBase(const_pointer s) : AbstractString(Comparator::getMaxLength(), strlen(s), s) {} + explicit StringBase(const unsigned char* s) : + AbstractString(Comparator::getMaxLength(), strlen((char*)s), (char*)s) {} + StringBase(size_type n, char_type c) : AbstractString(Comparator::getMaxLength(), n, c) {} + StringBase(const_iterator first, const_iterator last) : + AbstractString(Comparator::getMaxLength(), last - first, first) {} + explicit StringBase(MemoryPool& p) : AbstractString(Comparator::getMaxLength(), p) {} + StringBase(MemoryPool& p, const AbstractString& v) : AbstractString(Comparator::getMaxLength(), p, v) {} + StringBase(MemoryPool& p, const char_type* s, size_type l) : + AbstractString(Comparator::getMaxLength(), p, s, l) {} + static size_type max_length() + { + return Comparator::getMaxLength(); + } + StringType& assign(const StringType& str) { fb_assert(&str != this); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ale...@us...> - 2011-01-21 17:18:46
|
Revision: 52180 http://firebird.svn.sourceforge.net/firebird/?rev=52180&view=rev Author: alexpeshkoff Date: 2011-01-21 17:18:40 +0000 (Fri, 21 Jan 2011) Log Message: ----------- Avoid use of negative block size for small blocks Modified Paths: -------------- firebird/trunk/src/common/classes/alloc.cpp firebird/trunk/src/common/classes/alloc.h Modified: firebird/trunk/src/common/classes/alloc.cpp =================================================================== --- firebird/trunk/src/common/classes/alloc.cpp 2011-01-21 17:16:13 UTC (rev 52179) +++ firebird/trunk/src/common/classes/alloc.cpp 2011-01-21 17:18:40 UTC (rev 52180) @@ -219,7 +219,7 @@ VALGRIND_DISCARD( VALGRIND_MAKE_MEM_DEFINED(block, OFFSET(MemBlock*, body))); VALGRIND_DISCARD( - VALGRIND_MAKE_WRITABLE(object, absVal(block->length))); + VALGRIND_MAKE_WRITABLE(object, block->length)); } #endif @@ -289,7 +289,7 @@ if (COMPARE_EXCHANGE_POINTER(freeObjects + slot, block, (void*) block->pool)) { #ifdef MEM_DEBUG - if (slot != (-block->length) / roundingSize) + if (slot != block->length / roundingSize) corrupt("length trashed for block in slot"); #endif return block; @@ -305,7 +305,7 @@ freeObjects[slot] = (MemBlock*) block->pool; #ifdef MEM_DEBUG - if (slot != (-block->length) / roundingSize) + if (slot != block->length / roundingSize) corrupt("length trashed for block in slot"); #endif return block; @@ -323,7 +323,7 @@ MemBlock *block = (MemBlock*) hunk->memory; hunk->memory += length; hunk->spaceRemaining -= length; - block->length = -(SINT64) length; + block->length = length; return block; } @@ -340,7 +340,7 @@ block = (MemBlock*) ((UCHAR*) hunk + l); hunk->spaceRemaining = minAllocation - length - l; hunk->memory = (UCHAR*) block + length; - block->length = -(SINT64) length; + block->length = length; return block; } @@ -475,13 +475,13 @@ memory->fileName = fileName; memory->lineNumber = line; memset (&memory->body, INIT_BYTE, size); - memset (&memory->body + size, GUARD_BYTE, absVal(memory->length) - size - OFFSET(MemBlock*,body)); + memset (&memory->body + size, GUARD_BYTE, memory->length - size - OFFSET(MemBlock*,body)); #endif ++blocksAllocated; ++blocksActive; - increment_usage(absVal(memory->length)); + increment_usage(memory->length); return &memory->body; } @@ -524,10 +524,10 @@ // Remove protection from memory block #ifdef VALGRIND_FIX_IT VALGRIND_DISCARD( - VALGRIND_MAKE_MEM_DEFINED(object, absVal(block->length) - VALGRIND_REDZONE)); + VALGRIND_MAKE_MEM_DEFINED(object, block->length - VALGRIND_REDZONE)); #else VALGRIND_DISCARD( - VALGRIND_MAKE_WRITABLE(object, absVal(block->length) - VALGRIND_REDZONE)); + VALGRIND_MAKE_WRITABLE(object, block->length - VALGRIND_REDZONE)); #endif // Replace element in circular buffer @@ -538,7 +538,7 @@ pool->delayedFreePos = 0; #endif - size_t size = absVal(block->length); + size_t size = block->length; #ifdef DEBUG_GDS_ALLOC block->fileName = NULL; #endif @@ -556,7 +556,7 @@ corrupt("bad block released"); #ifdef MEM_DEBUG - for (const UCHAR* end = (UCHAR*) block + absVal(block->length), *p = end - GUARD_BYTES; p < end;) + for (const UCHAR* end = (UCHAR*) block + block->length, *p = end - GUARD_BYTES; p < end;) { if (*p++ != GUARD_BYTE) corrupt("guard bytes overwritten"); @@ -564,19 +564,19 @@ #endif --blocksActive; - const SINT64 length = block->length; + const size_t length = block->length; - // If length is negative, this is a small block + // If length is less than threshold, this is a small block - if (length < 0) + if (length <= threshold) { #ifdef MEM_DEBUG - memset (&block->body, DEL_BYTE, -length - OFFSET(MemBlock*, body)); + memset (&block->body, DEL_BYTE, length - OFFSET(MemBlock*, body)); #endif if (threadShared) { - for (int slot = -length / roundingSize;;) + for (int slot = length / roundingSize;;) { void *next = freeObjects [slot]; block->pool = (MemoryPool*) next; @@ -586,7 +586,7 @@ } } - int slot = -length / roundingSize; + int slot = length / roundingSize; void *next = freeObjects [slot]; block->pool = (MemoryPool*) next; freeObjects[slot] = block; @@ -1023,11 +1023,11 @@ { if (used) { - fprintf(file, "USED %p: size=%d allocated at %s:%d\n", - blk, absVal(blk->length), blk->fileName, blk->lineNumber); + fprintf(file, "USED %p: size=%" SIZEFORMAT " allocated at %s:%d\n", + blk, blk->length, blk->fileName, blk->lineNumber); } else - fprintf(file, "FREE %p: size=%d\n", blk, absVal(blk->length)); + fprintf(file, "FREE %p: size=%" SIZEFORMAT "\n", blk, blk->length); } } } @@ -1060,7 +1060,7 @@ { MemHeader* m = (MemHeader*)ptr; print_block(m->fileName != NULL, file, m, used_only, filter_path, filter_len); - ptr += absVal(m->length); + ptr += m->length; } } Modified: firebird/trunk/src/common/classes/alloc.h =================================================================== --- firebird/trunk/src/common/classes/alloc.h 2011-01-21 17:16:13 UTC (rev 52179) +++ firebird/trunk/src/common/classes/alloc.h 2011-01-21 17:18:40 UTC (rev 52180) @@ -86,9 +86,9 @@ return FB_ALIGN(value, ALLOC_ALIGNMENT); } -static const int DEFAULT_ROUNDING = 8; -static const int DEFAULT_CUTOFF = 4096; -static const int DEFAULT_ALLOCATION = 65536; +static const unsigned int DEFAULT_ROUNDING = 8; +static const unsigned int DEFAULT_CUTOFF = 4096; +static const size_t DEFAULT_ALLOCATION = 65536; class MemoryPool; class MemoryStats @@ -171,7 +171,7 @@ { public: MemoryPool *pool; - SINT64 length; + size_t length; #ifdef DEBUG_GDS_ALLOC INT32 lineNumber; const char *fileName; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <di...@us...> - 2011-02-06 16:20:02
|
Revision: 52304 http://firebird.svn.sourceforge.net/firebird/?rev=52304&view=rev Author: dimitr Date: 2011-02-06 16:19:55 +0000 (Sun, 06 Feb 2011) Log Message: ----------- Sorry, but I've got tired of these endless warnings. Modified Paths: -------------- firebird/trunk/src/common/classes/fb_string.cpp firebird/trunk/src/common/classes/fb_string.h Modified: firebird/trunk/src/common/classes/fb_string.cpp =================================================================== --- firebird/trunk/src/common/classes/fb_string.cpp 2011-02-06 15:39:37 UTC (rev 52303) +++ firebird/trunk/src/common/classes/fb_string.cpp 2011-02-06 16:19:55 UTC (rev 52304) @@ -88,14 +88,14 @@ const AbstractString::size_type AbstractString::npos = (AbstractString::size_type)(~0); AbstractString::AbstractString(const size_type limit, const AbstractString& v) - : max_length(limit) + : max_length(static_cast<internal_size_type>(limit)) { initialize(v.length()); memcpy(stringBuffer, v.c_str(), v.length()); } AbstractString::AbstractString(const size_type limit, const size_type sizeL, const void* dataL) - : max_length(limit) + : max_length(static_cast<internal_size_type>(limit)) { initialize(sizeL); memcpy(stringBuffer, dataL, sizeL); @@ -103,7 +103,7 @@ AbstractString::AbstractString(const size_type limit, const_pointer p1, const size_type n1, const_pointer p2, const size_type n2) - : max_length(limit) + : max_length(static_cast<internal_size_type>(limit)) { // CVC: npos must be maximum size_type value for all platforms. // fb_assert(n2 < npos - n1 && n1 + n2 <= max_length()); @@ -118,7 +118,7 @@ } AbstractString::AbstractString(const size_type limit, const size_type sizeL, char_type c) - : max_length(limit) + : max_length(static_cast<internal_size_type>(limit)) { initialize(sizeL); memset(stringBuffer, c, sizeL); Modified: firebird/trunk/src/common/classes/fb_string.h =================================================================== --- firebird/trunk/src/common/classes/fb_string.h 2011-02-06 15:39:37 UTC (rev 52303) +++ firebird/trunk/src/common/classes/fb_string.h 2011-02-06 16:19:55 UTC (rev 52304) @@ -162,7 +162,8 @@ AbstractString(const size_type limit, const AbstractString& v); AbstractString(const size_type limit) : - max_length(limit), stringBuffer(inlineBuffer), stringLength(0), bufferSize(INLINE_BUFFER_SIZE) + max_length(static_cast<internal_size_type>(limit)), + stringBuffer(inlineBuffer), stringLength(0), bufferSize(INLINE_BUFFER_SIZE) { stringBuffer[0] = 0; } @@ -170,20 +171,21 @@ AbstractString(const size_type limit, const size_type sizeL, char_type c); AbstractString(const size_type limit, MemoryPool& p) : AutoStorage(p), - max_length(limit), stringBuffer(inlineBuffer), stringLength(0), bufferSize(INLINE_BUFFER_SIZE) + max_length(static_cast<internal_size_type>(limit)), + stringBuffer(inlineBuffer), stringLength(0), bufferSize(INLINE_BUFFER_SIZE) { stringBuffer[0] = 0; } AbstractString(const size_type limit, MemoryPool& p, const AbstractString& v) - : AutoStorage(p), max_length(limit) + : AutoStorage(p), max_length(static_cast<internal_size_type>(limit)) { initialize(v.length()); memcpy(stringBuffer, v.c_str(), stringLength); } AbstractString(const size_type limit, MemoryPool& p, const void* s, const size_type l) - : AutoStorage(p), max_length(limit) + : AutoStorage(p), max_length(static_cast<internal_size_type>(limit)) { initialize(l); memcpy(stringBuffer, s, l); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <di...@us...> - 2011-04-28 16:59:36
|
Revision: 52837 http://firebird.svn.sourceforge.net/firebird/?rev=52837&view=rev Author: dimitr Date: 2011-04-28 16:59:29 +0000 (Thu, 28 Apr 2011) Log Message: ----------- Misc. Modified Paths: -------------- firebird/trunk/src/common/classes/SyncObject.cpp firebird/trunk/src/common/classes/SyncObject.h firebird/trunk/src/common/classes/Synchronize.cpp firebird/trunk/src/common/classes/Synchronize.h Modified: firebird/trunk/src/common/classes/SyncObject.cpp =================================================================== --- firebird/trunk/src/common/classes/SyncObject.cpp 2011-04-28 16:59:29 UTC (rev 52836) +++ firebird/trunk/src/common/classes/SyncObject.cpp 2011-04-28 16:59:29 UTC (rev 52837) @@ -23,7 +23,7 @@ * Copyright (c) 1997 - 2000, 2001, 2003 Netfrastructure, Inc. * All Rights Reserved. * - * The \xD1ode was ported into Firebird Open Source RDBMS project by + * The Code was ported into Firebird Open Source RDBMS project by * Vladyslav Khorsun at 2010 * * Contributor(s): @@ -225,7 +225,7 @@ } } -void SyncObject::downGrade(LockType type) +void SyncObject::downgrade(LockType type) { fb_assert(monitorCount == 0); fb_assert(type == Shared); @@ -389,7 +389,7 @@ return next; } -void SyncObject::grantLocks(void) +void SyncObject::grantLocks() { mutex.enter(); fb_assert((waiters && waitingThreads) || (!waiters && !waitingThreads)); @@ -459,7 +459,7 @@ } -bool SyncObject::ourExclusiveLock(void) const +bool SyncObject::ourExclusiveLock() const { if (lockState != -1) return false; @@ -477,7 +477,7 @@ isc_arg_end); } -void SyncObject::assertionFailed(void) +void SyncObject::assertionFailed() { throw OSRIException (isc_sys_request, isc_arg_string, "SyncObject assertion failed", Modified: firebird/trunk/src/common/classes/SyncObject.h =================================================================== --- firebird/trunk/src/common/classes/SyncObject.h 2011-04-28 16:59:29 UTC (rev 52836) +++ firebird/trunk/src/common/classes/SyncObject.h 2011-04-28 16:59:29 UTC (rev 52837) @@ -23,7 +23,7 @@ * Copyright (c) 1997 - 2000, 2001, 2003 Netfrastructure, Inc. * All Rights Reserved. * - * The \xD1ode was ported into Firebird Open Source RDBMS project by + * The Code was ported into Firebird Open Source RDBMS project by * Vladyslav Khorsun at 2010 * * Contributor(s): @@ -38,7 +38,6 @@ namespace Firebird { #define LOG_DEBUG -#define ASSERT fb_assert enum LockType { None, @@ -55,7 +54,7 @@ public: virtual void lock(Sync *sync, LockType type) = 0; virtual void unlock(Sync *sync, LockType type) = 0; - virtual void downGrade(LockType type) = 0; + virtual void downgrade(LockType type) = 0; }; class SyncObject : public SynchronizationObject @@ -76,11 +75,11 @@ bool lockConditional(LockType type); virtual void unlock(Sync *sync, LockType type); - void unlock(void); + void unlock(); - virtual void downGrade(LockType type); + virtual void downgrade(LockType type); - LockType getState(void) const + LockType getState() const { if (lockState.value() == 0) return None; @@ -101,15 +100,15 @@ return (waiters.value() > 0); } - bool ourExclusiveLock(void) const; + bool ourExclusiveLock() const; void sysServiceFailed(const char* service, int code); - void assertionFailed(void); + void assertionFailed(); protected: void wait(LockType type, ThreadSync *thread, Sync *sync); ThreadSync* grantThread(ThreadSync *thread); - void grantLocks(void); + void grantLocks(); void validate(LockType lockType); AtomicCounter lockState; @@ -127,7 +126,7 @@ public: Sync(SynchronizationObject *obj, const char *fromWhere) { - ASSERT(obj); + fb_assert(obj); syncObject = obj; prior = NULL; where = fromWhere; @@ -136,7 +135,7 @@ ~Sync() { - ASSERT(state != Invalid); + fb_assert(state != Invalid); if (syncObject && state != None) { @@ -160,15 +159,15 @@ void unlock() { - ASSERT(state != None); + fb_assert(state != None); syncObject->unlock(this, state); state = None; } - void downGrade(LockType type) + void downgrade(LockType type) { - ASSERT(state == Exclusive); - syncObject->downGrade(type); + fb_assert(state == Exclusive); + syncObject->downgrade(type); state = Shared; } @@ -204,7 +203,7 @@ ~SyncLockGuard() { - //ASSERT(state != None); + //fb_assert(state != None); if (state != None) unlock(); } @@ -218,7 +217,7 @@ { oldState = state; - ASSERT(oldState != None); + fb_assert(oldState != None); if (oldState != None) unlock(); } Modified: firebird/trunk/src/common/classes/Synchronize.cpp =================================================================== --- firebird/trunk/src/common/classes/Synchronize.cpp 2011-04-28 16:59:29 UTC (rev 52836) +++ firebird/trunk/src/common/classes/Synchronize.cpp 2011-04-28 16:59:29 UTC (rev 52837) @@ -23,7 +23,7 @@ * Copyright (c) 1997 - 2000, 2001, 2003 Netfrastructure, Inc. * All Rights Reserved. * -* The \xD1ode was ported into Firebird Open Source RDBMS project by +* The Code was ported into Firebird Open Source RDBMS project by * Vladyslav Khorsun at 2010 * * Contributor(s): @@ -284,7 +284,7 @@ TLS_SET(threadIndex, thread); } -FB_THREAD_ID ThreadSync::getCurrentThreadId(void) +FB_THREAD_ID ThreadSync::getCurrentThreadId() { return getThreadId(); } @@ -315,8 +315,8 @@ void ThreadSync::grantLock(SyncObject *lock) { - ASSERT(!lockGranted); - ASSERT(!lockPending || lockPending->syncObject == lock); + fb_assert(!lockGranted); + fb_assert(!lockPending || lockPending->syncObject == lock); lockGranted = true; lockPending = NULL; Modified: firebird/trunk/src/common/classes/Synchronize.h =================================================================== --- firebird/trunk/src/common/classes/Synchronize.h 2011-04-28 16:59:29 UTC (rev 52836) +++ firebird/trunk/src/common/classes/Synchronize.h 2011-04-28 16:59:29 UTC (rev 52837) @@ -23,7 +23,7 @@ * Copyright (c) 1997 - 2000, 2001, 2003 Netfrastructure, Inc. * All Rights Reserved. * - * The \xD1ode was ported into Firebird Open Source RDBMS project by + * The Code was ported into Firebird Open Source RDBMS project by * Vladyslav Khorsun at 2010 * * Contributor(s): @@ -84,7 +84,7 @@ static ThreadSync* findThread(); static ThreadSync* getThread(const char *desc); - static FB_THREAD_ID getCurrentThreadId(void); + static FB_THREAD_ID getCurrentThreadId(); const char* getWhere(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ale...@us...> - 2011-04-29 15:50:12
|
Revision: 52852 http://firebird.svn.sourceforge.net/firebird/?rev=52852&view=rev Author: alexpeshkoff Date: 2011-04-29 15:50:04 +0000 (Fri, 29 Apr 2011) Log Message: ----------- Cleanup: make fb_atomic be the single file working with atomic operations and membars Modified Paths: -------------- firebird/trunk/src/common/classes/SyncObject.cpp firebird/trunk/src/common/classes/alloc.cpp firebird/trunk/src/common/classes/alloc.h firebird/trunk/src/common/classes/fb_atomic.h Removed Paths: ------------- firebird/trunk/src/common/classes/Interlock.h Deleted: firebird/trunk/src/common/classes/Interlock.h =================================================================== --- firebird/trunk/src/common/classes/Interlock.h 2011-04-29 15:16:53 UTC (rev 52851) +++ firebird/trunk/src/common/classes/Interlock.h 2011-04-29 15:50:04 UTC (rev 52852) @@ -1,283 +0,0 @@ -/* - * - * The contents of this file are subject to the Initial - * Developer's Public License Version 1.0 (the "License"); - * you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * http://www.ibphoenix.com/idpl.html. - * - * Software distributed under the License is distributed on - * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either - * express or implied. See the License for the specific - * language governing rights and limitations under the License. - * - * The contents of this file or any work derived from this file - * may not be distributed under any other license whatsoever - * without the express prior written permission of the original - * author. - * - * - * The Original Code was created by James A. Starkey for IBPhoenix. - * - * Copyright (c) 2004 James A. Starkey - * All Rights Reserved. - */ - -#ifndef __INTERLOCK_H -#define __INTERLOCK_H - -#if defined(SOLARIS) || defined(hpux) -extern "C" -{ -extern int cas (volatile int *state, int compare, int exchange); -extern void* casx (volatile void **state, void* compare, void* exchange); -extern void membar_flush(void); -extern void membar_wait(void); -} -#define COMPARE_EXCHANGE(target,compare,exchange)\ - (cas(target, compare, exchange) == compare) -#define COMPARE_EXCHANGE_POINTER(target,compare,exchange)\ - (casx((volatile void**)target, (void*)compare, (void*)exchange) == compare) -#endif // defined(SOLARIS) || defined(hpux) - -#ifdef SOLARIS -#define WAIT_FOR_FLUSH_CACHE membar_wait(); -#define FLUSH_CACHE membar_flush(); -#else -/* I64 hpux currently has mf in the cas asm routines */ -/* (h6icas.s). They should probably be moved here instead */ -#endif // SOLARIS - - -#ifdef AIX_PPC -#include <sys/atomic_op.h> -extern "C" -{ -static inline int COMPARE_EXCHANGE(volatile int *target, int compare, int exchange) -{ - return compare_and_swap((int *)target, &compare, exchange); -} -static inline int COMPARE_EXCHANGE_POINTER(volatile void *target, volatile void * compare, void * exchange) -{ - return compare_and_swaplp((long *)target, (long*)&compare, (long)exchange); -} - -void asm_isync(void); - #pragma mc_func asm_isync { \ - "4c00012c" /* isync */ \ - } -void asm_sync(void); - #pragma mc_func asm_sync { \ - "7c0004ac" /* sync */ \ - } - -#define WAIT_FOR_FLUSH_CACHE asm_isync(); -#define FLUSH_CACHE asm_sync(); -} -#endif // AIX_PPC - -#ifdef DARWIN -#define __DEBUGGING__ -#include <CoreServices/CoreServices.h> -extern "C" -{ -static inline int COMPARE_EXCHANGE(volatile int* target, int compare, int exchange) -{ - return CompareAndSwap((UInt32)compare, (UInt32) exchange, (UInt32 *)(target)); -} - -static inline int COMPARE_EXCHANGE_POINTER(void* target, volatile void* compare, void* exchange) -{ - return CompareAndSwap( (UInt32) compare, (UInt32) exchange, (UInt32 *) target); -} - -} -#endif // DARWIN - - -#ifdef MVS -extern "C" { -static inline int cas (volatile int *state, int compare, int exchange) -{ - __cs((cs_t*)(&compare), (cs_t*)state, (cs_t)exchange); - return compare; -} -static inline void* casx (volatile void *state, volatile void *compare, void *exchange) -{ - __cs((cs_t*)(&compare), (cs_t*)state, (cs_t)exchange); - return (void*)compare; -} -} -#define COMPARE_EXCHANGE(target,compare,exchange)\ - (cas(target, compare, exchange) == compare) - -#define COMPARE_EXCHANGE_POINTER(target,compare,exchange)\ - (casx(target, compare, exchange) == compare) - -#endif // MVS - -#ifdef __VMS -#include <builtins.h> -extern "C" -{ - static inline int COMPARE_EXCHANGE(volatile int *target, int compare, int exchange) - { - return __CMP_STORE_LONG(&compare, compare, exchange, target); - } - static inline int COMPARE_EXCHANGE_POINTER(volatile void *target, volatile void * compare, void * exchange) - { - return __CMP_STORE_QUAD(compare, (__int64)compare, (__int64)exchange, &target); - } -} - -#endif // __VMS - -#ifdef _WIN32 -#include <windows.h> -#define INTERLOCKED_INCREMENT(variable) InterlockedIncrement (&variable) -#define INTERLOCKED_DECREMENT(variable) InterlockedDecrement (&variable) - -#define INTERLOCK_TYPE LONG -#define COMPARE_EXCHANGE(target,compare,exchange)\ - (InterlockedCompareExchange(target, exchange, compare) == compare) -#define COMPARE_EXCHANGE_POINTER(target,compare,exchange)\ - (InterlockedCompareExchangePointer((volatile PVOID*) target, (PVOID)exchange, (PVOID)compare) == compare) -#ifndef InterlockedIncrement -#define InterlockedIncrement _InterlockedIncrement -#define InterlockedDecrement _InterlockedDecrement -//#define InterlockedCompareExchange _InterlockedCompareExchange - -extern "C" - { - INTERLOCK_TYPE InterlockedIncrement(volatile INTERLOCK_TYPE* lpAddend); - INTERLOCK_TYPE InterlockedDecrement(volatile INTERLOCK_TYPE* lpAddend); - //PVOID InterlockedCompareExchange(volatile PVOID *target, PVOID exchange, PVOID compare); - } -#pragma intrinsic(_InterlockedIncrement) -#pragma intrinsic(_InterlockedDecrement) -//#pragma intrinsic(_InterlockedCompareExchange) -#endif - -#endif // _WIN32 - -#ifndef INTERLOCKED_INCREMENT -#define INTERLOCKED_INCREMENT(variable) interlockedIncrement (&variable) -#define INTERLOCKED_DECREMENT(variable) interlockedDecrement (&variable) -#endif - -#if defined (__i386) || (__x86_64__) -#define COMPARE_EXCHANGE(target,compare,exchange)\ - (inline_cas(target, compare, exchange)) -#define COMPARE_EXCHANGE_POINTER(target,compare,exchange)\ - (inline_cas_pointer((volatile void**)target, (void*)compare, (void*)exchange)) -#endif // defined (__i386) || (__x86_64__) - -#ifndef INTERLOCK_TYPE -#define INTERLOCK_TYPE int -#endif - -inline INTERLOCK_TYPE interlockedIncrement(volatile INTERLOCK_TYPE *ptr) -{ -#ifdef _WIN32 - return InterlockedIncrement ((INTERLOCK_TYPE*) ptr); -#elif defined DARWIN - return IncrementAtomic ((SInt32 *) ptr); -#elif defined (__i386) || (__x86_64__) - INTERLOCK_TYPE ret; - asm ( - "mov $1,%%eax\n\t" - "lock\n\t" "xaddl %%eax,%1\n\t" - "incl %%eax\n\t" - "movl %%eax,%0\n\t" - : "=m" (ret) - : "m" (*ptr) - : "%eax" - ); - return ret; -#else - for (;;) - { - int oldValue = *ptr; - int newValue = oldValue + 1; - if (COMPARE_EXCHANGE(ptr, oldValue, newValue)) - return newValue; - } -#endif // ifdef _WIN32 -} - -inline INTERLOCK_TYPE interlockedDecrement(volatile INTERLOCK_TYPE *ptr) -{ -#ifdef _WIN32 - return InterlockedDecrement ((INTERLOCK_TYPE*) ptr); -#elif defined DARWIN - return DecrementAtomic ((SInt32 *) ptr); -#elif defined (__i386) || (__x86_64__) - INTERLOCK_TYPE ret; - asm ( - "mov $-1,%%eax\n\t" - "lock\n\t" "xaddl %%eax,%1\n\t" - "decl %%eax\n\t" - "movl %%eax,%0\n\t" - : "=m" (ret) - : "m" (*ptr) - : "%eax" - ); - return ret; -#else - for (;;) - { - int oldValue = *ptr; - int newValue = oldValue - 1; - if (COMPARE_EXCHANGE(ptr, oldValue, newValue)) - return newValue; - } -#endif // ifdef _WIN32 -} - -inline int inline_cas (volatile int *target, int compare, int exchange) -{ -#if defined(__i386) || (__x86_64__) - char ret; - - __asm __volatile ("lock; cmpxchg %2, %1 ; sete %0" - : "=q" (ret), "+m" (*(target)) - : "r" (exchange), "a" (compare) - : "cc", "memory"); - - return ret; -#else - return -2; -#endif -} - -inline char inline_cas_pointer (volatile void **target, void *compare, void *exchange) -{ -#if defined(__i386) || defined(__x86_64__) - char ret; - - __asm __volatile ("lock; cmpxchg %2, %1 ; sete %0" - : "=q" (ret), "+m" (*(target)) - : "r" (exchange), "a" (compare) - : "cc", "memory"); - - return ret; -#else - return NULL; -#endif -} - - -/* On some machines, a "wait for flush complete" type instruction must be */ -/* executed to insure cache coherency across processors after the atomic */ -/* lock has been granted */ -#ifndef WAIT_FOR_FLUSH_CACHE -#define WAIT_FOR_FLUSH_CACHE -#endif - -/* On some machines, the cache must be flushed before an atomic lock is */ -/* released. */ -#ifndef FLUSH_CACHE -#define FLUSH_CACHE -#endif - -#endif // __INTERLOCK_H Modified: firebird/trunk/src/common/classes/SyncObject.cpp =================================================================== --- firebird/trunk/src/common/classes/SyncObject.cpp 2011-04-29 15:16:53 UTC (rev 52851) +++ firebird/trunk/src/common/classes/SyncObject.cpp 2011-04-29 15:50:04 UTC (rev 52852) @@ -35,7 +35,6 @@ #include "SyncObject.h" #include "Synchronize.h" -#include "Interlock.h" namespace Firebird { @@ -59,7 +58,7 @@ const AtomicCounter::counter_type newState = oldState + 1; if (lockState.compareExchange(oldState, newState)) { - WAIT_FOR_FLUSH_CACHE + WaitForFlushCache(); return; } } @@ -106,7 +105,7 @@ if (lockState.compareExchange(oldState, -1)) { exclusiveThread = thread; - WAIT_FOR_FLUSH_CACHE + WaitForFlushCache(); return; } } @@ -149,7 +148,7 @@ const AtomicCounter::counter_type newState = oldState + 1; if (lockState.compareExchange(oldState, newState)) { - WAIT_FOR_FLUSH_CACHE + WaitForFlushCache(); return true; } } @@ -175,7 +174,7 @@ if (lockState.compareExchange(oldState, -1)) { - WAIT_FOR_FLUSH_CACHE + WaitForFlushCache(); exclusiveThread = thread; return true; } @@ -203,7 +202,7 @@ const AtomicCounter::counter_type newState = (type == Shared) ? oldState - 1 : 0; exclusiveThread = NULL; - FLUSH_CACHE + FlushCache(); if (lockState.compareExchange(oldState, newState)) { @@ -236,7 +235,7 @@ fb_assert(exclusiveThread); fb_assert(exclusiveThread == ThreadSync::findThread()); - FLUSH_CACHE + FlushCache(); while (true) { Modified: firebird/trunk/src/common/classes/alloc.cpp =================================================================== --- firebird/trunk/src/common/classes/alloc.cpp 2011-04-29 15:16:53 UTC (rev 52851) +++ firebird/trunk/src/common/classes/alloc.cpp 2011-04-29 15:50:04 UTC (rev 52852) @@ -52,7 +52,6 @@ #include "../common/classes/fb_tls.h" #include "../common/classes/locks.h" #include "../common/classes/init.h" -#include "../common/classes/Interlock.h" #include "../common/classes/vector.h" #include "gen/iberror.h" @@ -171,8 +170,7 @@ threadShared(shared), pool_destroying(false), stats(default_stats_group), parent(NULL) { size_t vecSize = (cutoff + rounding) / rounding; - size_t l = vecSize * sizeof(void*); - init(allocRaw(l), l); + init(allocRaw(vecSize * sizeof(void*)), vecSize); } MemoryPool::MemoryPool(MemoryPool& p, MemoryStats& s, bool shared, int rounding, int cutoff, int minAlloc) @@ -180,14 +178,12 @@ threadShared(shared), pool_destroying(false), stats(&s), parent(&p) { size_t vecSize = (cutoff + rounding) / rounding; - size_t l = vecSize * sizeof(void*); - init(parent->allocate(l), l); + init(parent->allocate(vecSize * sizeof(void*)), vecSize); } void MemoryPool::init(void* memory, size_t length) { - freeObjects = (MemBlock**) memory; - memset(freeObjects, 0, length); + freeObjects = new(memory) FreeChainPtr[length]; bigHunks = NULL; smallHunks = NULL; freeBlocks.nextLarger = freeBlocks.priorSmaller = &freeBlocks; @@ -289,7 +285,7 @@ { while (block = freeObjects[slot]) { - if (COMPARE_EXCHANGE_POINTER(freeObjects + slot, block, (void*) block->pool)) + if (freeObjects[slot].compareExchange(block, block->next)) { #ifdef MEM_DEBUG if (slot != block->length / roundingSize) @@ -581,10 +577,9 @@ { for (int slot = length / roundingSize;;) { - void *next = freeObjects [slot]; - block->pool = (MemoryPool*) next; + block->next = freeObjects[slot]; - if (COMPARE_EXCHANGE_POINTER(freeObjects + slot, next, block)) + if (freeObjects[slot].compareExchange(block->next, block)) return; } } Modified: firebird/trunk/src/common/classes/alloc.h =================================================================== --- firebird/trunk/src/common/classes/alloc.h 2011-04-29 15:16:53 UTC (rev 52851) +++ firebird/trunk/src/common/classes/alloc.h 2011-04-29 15:50:04 UTC (rev 52852) @@ -167,10 +167,16 @@ typedef SLONG INT32; +class MemBlock; + class MemHeader { public: - MemoryPool *pool; + union + { + MemoryPool* pool; + MemBlock* next; + }; size_t length; #ifdef DEBUG_GDS_ALLOC INT32 lineNumber; @@ -247,7 +253,8 @@ private: size_t roundingSize, threshold, minAllocation; //int headerSize; - MemBlock **freeObjects; + typedef AtomicPointer<MemBlock> FreeChainPtr; + FreeChainPtr *freeObjects; MemBigHunk *bigHunks; MemSmallHunk *smallHunks; MemFreeBlock freeBlocks; Modified: firebird/trunk/src/common/classes/fb_atomic.h =================================================================== --- firebird/trunk/src/common/classes/fb_atomic.h 2011-04-29 15:16:53 UTC (rev 52851) +++ firebird/trunk/src/common/classes/fb_atomic.h 2011-04-29 15:50:04 UTC (rev 52852) @@ -140,7 +140,7 @@ T* operator ->() const { return value(); } void operator =(T* val) { setValue(val); } -protected: +private: volatile T* pointer; }; @@ -191,6 +191,16 @@ counter_type counter; }; +#define FLUSH_CACHE 1 +inline void FlushCache() +{ + asm_sync(); +} +inline void WaitForFlushCache() +{ + asm_isync(); +} + } // namespace Firebird #elif defined(HPUX) && defined(HAVE_ATOMIC_H) @@ -239,6 +249,12 @@ #include <atomic.h> +extern "C" +{ +extern void membar_flush(void); +extern void membar_wait(void); +} + namespace Firebird { // Solaris version - uses Solaris atomic_ops @@ -270,6 +286,16 @@ volatile counter_type counter; }; +#define FLUSH_CACHE 1 +inline void FlushCache() +{ + membar_flush(); +} +inline void WaitForFlushCache() +{ + membar_wait(); +} + } // namespace Firebird @@ -378,6 +404,42 @@ volatile counter_type counter; }; +class PlatformAtomicPointer +{ +public: + explicit PlatformAtomicPointer(void* val = NULL) : pointer(val) {} + ~PlatformAtomicPointer() {} + + void* platformValue() const { return (void*)pointer; } + + void* platformSetValue(void* val) + { + register void* result; + + __asm __volatile ("lock; xchg %0, %1" + : "=r" (result), "=m" (pointer) + : "0" (val), "m" (pointer) + : "cc", "memory"); + + return result; + } + + bool platformCompareExchange(void* oldVal, void* newVal) + { + register char ret; + + __asm __volatile ("lock; cmpxchg %2, %1 ; sete %0" + : "=r" (ret), "+m" (pointer) + : "r" (newVal), "a" (oldVal) + : "cc", "memory"); + + return ret; + } + +private: + volatile void* pointer; +}; + } // namespace Firebird #elif defined(HAVE_AO_COMPARE_AND_SWAP_FULL) && !defined(HPUX) @@ -546,6 +608,49 @@ }; +template <typename T> +class AtomicPointer : public PlatformAtomicPointer +{ +public: + explicit AtomicPointer(T* val = NULL) : PlatformAtomicPointer(val) {} + ~AtomicPointer() {} + + T* value() const + { + return (T*)platformValue(); + } + + void setValue(T* val) + { + platformSetValue(val); + } + + bool compareExchange(T* oldVal, T* newVal) + { + return platformCompareExchange(oldVal, newVal); + } + + operator T* () const + { + return value(); + } + + T* operator ->() const + { + return value(); + } + + void operator =(T* val) + { + setValue(val); + } +}; + +#ifndef FLUSH_CACHE +inline void FlushCache() { } +inline void WaitForFlushCache() { } +#endif + } // namespace Firebird #endif // CLASSES_FB_ATOMIC_H This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hv...@us...> - 2011-04-30 11:38:07
|
Revision: 52857 http://firebird.svn.sourceforge.net/firebird/?rev=52857&view=rev Author: hvlad Date: 2011-04-30 11:38:00 +0000 (Sat, 30 Apr 2011) Log Message: ----------- Some refactoring and cleanup. Modified Paths: -------------- firebird/trunk/src/common/classes/SyncObject.cpp firebird/trunk/src/common/classes/SyncObject.h firebird/trunk/src/common/classes/Synchronize.cpp firebird/trunk/src/common/classes/Synchronize.h Modified: firebird/trunk/src/common/classes/SyncObject.cpp =================================================================== --- firebird/trunk/src/common/classes/SyncObject.cpp 2011-04-30 03:16:00 UTC (rev 52856) +++ firebird/trunk/src/common/classes/SyncObject.cpp 2011-04-30 11:38:00 UTC (rev 52857) @@ -39,14 +39,14 @@ namespace Firebird { -void SyncObject::lock(Sync* sync, LockType type) +void SyncObject::lock(Sync* sync, SyncType type) { ThreadSync* thread = NULL; - if (type == LOCK_TYPE_SHARED) + if (type == SYNC_SHARED) { - // In Vulcan SyncObject locking is not fair. LOCK_TYPE_SHARED locks have priority - // before LOCK_TYPE_EXCLUSIVE locks. If we'll need to restore this behavior we + // In Vulcan SyncObject locking is not fair. Shared locks have priority + // before Exclusive locks. If we'll need to restore this behavior we // should replace loop condition below by: // while (true) while (waiters == 0) @@ -132,12 +132,12 @@ wait(type, thread, sync); } -bool SyncObject::lockConditional(LockType type) +bool SyncObject::lockConditional(SyncType type) { if (waitingThreads) return false; - if (type == LOCK_TYPE_SHARED) + if (type == SYNC_SHARED) { while (true) { @@ -184,10 +184,10 @@ } } -void SyncObject::unlock(Sync* sync, LockType type) +void SyncObject::unlock(Sync* sync, SyncType type) { - fb_assert((type == LOCK_TYPE_SHARED && lockState > 0) || - (type == LOCK_TYPE_EXCLUSIVE && lockState == -1)); + fb_assert((type == SYNC_SHARED && lockState > 0) || + (type == SYNC_EXCLUSIVE && lockState == -1)); if (monitorCount) { @@ -199,7 +199,7 @@ while (true) { const AtomicCounter::counter_type oldState = lockState; - const AtomicCounter::counter_type newState = (type == LOCK_TYPE_SHARED) ? oldState - 1 : 0; + const AtomicCounter::counter_type newState = (type == SYNC_SHARED) ? oldState - 1 : 0; exclusiveThread = NULL; FlushCache(); @@ -217,19 +217,19 @@ void SyncObject::unlock() { if (lockState > 0) - unlock(NULL, LOCK_TYPE_SHARED); + unlock(NULL, SYNC_SHARED); else if (lockState == -1) - unlock(NULL, LOCK_TYPE_EXCLUSIVE); + unlock(NULL, SYNC_EXCLUSIVE); else { fb_assert(false); } } -void SyncObject::downgrade(LockType type) +void SyncObject::downgrade(SyncType type) { fb_assert(monitorCount == 0); - fb_assert(type == LOCK_TYPE_SHARED); + fb_assert(type == SYNC_SHARED); fb_assert(lockState == -1); fb_assert(exclusiveThread); fb_assert(exclusiveThread == ThreadSync::findThread()); @@ -248,7 +248,7 @@ } } -void SyncObject::wait(LockType type, ThreadSync* thread, Sync* sync) +void SyncObject::wait(SyncType type, ThreadSync* thread, Sync* sync) { if (thread->nextWaiting) { @@ -330,7 +330,7 @@ { bool granted = false; - if (thread->lockType == LOCK_TYPE_SHARED) + if (thread->lockType == SYNC_SHARED) { AtomicCounter::counter_type oldState = lockState; @@ -366,19 +366,19 @@ } } -void SyncObject::validate(LockType lockType) +void SyncObject::validate(SyncType lockType) { switch (lockType) { - case LOCK_TYPE_NONE: + case SYNC_NONE: fb_assert(lockState == 0); break; - case LOCK_TYPE_SHARED: + case SYNC_SHARED: fb_assert(lockState > 0); break; - case LOCK_TYPE_EXCLUSIVE: + case SYNC_EXCLUSIVE: fb_assert(lockState == -1); break; } Modified: firebird/trunk/src/common/classes/SyncObject.h =================================================================== --- firebird/trunk/src/common/classes/SyncObject.h 2011-04-30 03:16:00 UTC (rev 52856) +++ firebird/trunk/src/common/classes/SyncObject.h 2011-04-30 11:38:00 UTC (rev 52857) @@ -39,27 +39,19 @@ #define SYNC_LOG_DEBUG -enum LockType { - LOCK_TYPE_NONE, - LOCK_TYPE_EXCLUSIVE, - LOCK_TYPE_SHARED, - LOCK_TYPE_INVALID +enum SyncType { + SYNC_NONE, + SYNC_EXCLUSIVE, + SYNC_SHARED, + SYNC_INVALID }; class Sync; class ThreadSync; -class SynchronizationObject +class SyncObject { public: - virtual void lock(Sync* sync, LockType type) = 0; - virtual void unlock(Sync* sync, LockType type) = 0; - virtual void downgrade(LockType type) = 0; -}; - -class SyncObject : public SynchronizationObject -{ -public: SyncObject() : waiters(0), monitorCount(0), @@ -68,27 +60,27 @@ { } - virtual ~SyncObject() + ~SyncObject() { } - virtual void lock(Sync* sync, LockType type); - bool lockConditional(LockType type); + void lock(Sync* sync, SyncType type); + bool lockConditional(SyncType type); - virtual void unlock(Sync* sync, LockType type); + void unlock(Sync* sync, SyncType type); void unlock(); - virtual void downgrade(LockType type); + void downgrade(SyncType type); - LockType getState() const + SyncType getState() const { if (lockState.value() == 0) - return LOCK_TYPE_NONE; + return SYNC_NONE; if (lockState.value() < 0) - return LOCK_TYPE_EXCLUSIVE; + return SYNC_EXCLUSIVE; - return LOCK_TYPE_SHARED; + return SYNC_SHARED; } bool isLocked() const @@ -103,14 +95,11 @@ bool ourExclusiveLock() const; - void sysServiceFailed(const char* service, int code); - void assertionFailed(); - protected: - void wait(LockType type, ThreadSync* thread, Sync* sync); + void wait(SyncType type, ThreadSync* thread, Sync* sync); ThreadSync* grantThread(ThreadSync* thread); void grantLocks(); - void validate(LockType lockType); + void validate(SyncType lockType); AtomicCounter lockState; AtomicCounter waiters; @@ -127,9 +116,9 @@ friend class ThreadSync; public: - Sync(SynchronizationObject* obj, const char* fromWhere) - : state(LOCK_TYPE_NONE), - request(LOCK_TYPE_NONE), + Sync(SyncObject* obj, const char* fromWhere) + : state(SYNC_NONE), + request(SYNC_NONE), syncObject(obj), prior(NULL), where(fromWhere) @@ -139,23 +128,23 @@ ~Sync() { - fb_assert(state != LOCK_TYPE_INVALID); + fb_assert(state != SYNC_INVALID); - if (syncObject && state != LOCK_TYPE_NONE) + if (syncObject && state != SYNC_NONE) { syncObject->unlock(this, state); - state = LOCK_TYPE_INVALID; + state = SYNC_INVALID; } } - void lock(LockType type) + void lock(SyncType type) { request = type; syncObject->lock(this, type); state = type; } - void lock(LockType type, const char* fromWhere) + void lock(SyncType type, const char* fromWhere) { where = fromWhere; lock(type); @@ -163,31 +152,31 @@ void unlock() { - fb_assert(state != LOCK_TYPE_NONE); + fb_assert(state != SYNC_NONE); syncObject->unlock(this, state); - state = LOCK_TYPE_NONE; + state = SYNC_NONE; } - void downgrade(LockType type) + void downgrade(SyncType type) { - fb_assert(state == LOCK_TYPE_EXCLUSIVE); + fb_assert(state == SYNC_EXCLUSIVE); syncObject->downgrade(type); - state = LOCK_TYPE_SHARED; + state = SYNC_SHARED; } - void setObject(SynchronizationObject* obj) + void setObject(SyncObject* obj) { - if (syncObject && state != LOCK_TYPE_NONE) + if (syncObject && state != SYNC_NONE) syncObject->unlock(this, state); - state = LOCK_TYPE_NONE; + state = SYNC_NONE; syncObject = obj; } protected: - LockType state; - LockType request; - SynchronizationObject* syncObject; + SyncType state; + SyncType request; + SyncObject* syncObject; Sync* prior; // not used const char* where; }; @@ -196,7 +185,7 @@ class SyncLockGuard : public Sync { public: - SyncLockGuard(SynchronizationObject* obj, LockType type, const char* fromWhere) + SyncLockGuard(SyncObject* obj, SyncType type, const char* fromWhere) : Sync(obj, fromWhere) { lock(type); @@ -204,8 +193,8 @@ ~SyncLockGuard() { - //fb_assert(state != LOCK_TYPE_NONE); - if (state != LOCK_TYPE_NONE) + //fb_assert(state != SYNC_NONE); + if (state != SYNC_NONE) unlock(); } }; @@ -213,24 +202,24 @@ class SyncUnlockGuard : public Sync { public: - SyncUnlockGuard(SynchronizationObject* obj, const char* fromWhere) + SyncUnlockGuard(SyncObject* obj, const char* fromWhere) : Sync(obj, fromWhere) { oldState = state; - fb_assert(oldState != LOCK_TYPE_NONE); - if (oldState != LOCK_TYPE_NONE) + fb_assert(oldState != SYNC_NONE); + if (oldState != SYNC_NONE) unlock(); } ~SyncUnlockGuard() { - if (oldState != LOCK_TYPE_NONE) + if (oldState != SYNC_NONE) lock(oldState); } private: - LockType oldState; + SyncType oldState; }; } // namespace Firebird Modified: firebird/trunk/src/common/classes/Synchronize.cpp =================================================================== --- firebird/trunk/src/common/classes/Synchronize.cpp 2011-04-30 03:16:00 UTC (rev 52856) +++ firebird/trunk/src/common/classes/Synchronize.cpp 2011-04-30 11:38:00 UTC (rev 52857) @@ -245,7 +245,7 @@ description = desc; threadId = getCurrentThreadId(); prevWaiting = nextWaiting = NULL; - lockType = LOCK_TYPE_NONE; + lockType = SYNC_NONE; lockGranted = false; lockPending = NULL; locks = NULL; @@ -300,7 +300,7 @@ { ThreadSync* thread = getThread("ThreadSync::validateLocks"); - // hvlad: not worked + // hvlad: not worked, probably we should implement it at some day if (thread->locks) { SYNC_LOG_DEBUG("thread %d has active locks:\n", thread->threadId); Modified: firebird/trunk/src/common/classes/Synchronize.h =================================================================== --- firebird/trunk/src/common/classes/Synchronize.h 2011-04-30 03:16:00 UTC (rev 52856) +++ firebird/trunk/src/common/classes/Synchronize.h 2011-04-30 11:38:00 UTC (rev 52857) @@ -76,12 +76,12 @@ class ThreadSync : public Synchronize { +friend class SyncObject; + public: ThreadSync(const char* desc); virtual ~ThreadSync(); - void init(const char* description); - static ThreadSync* findThread(); static ThreadSync* getThread(const char* desc); static FB_THREAD_ID getCurrentThreadId(); @@ -89,19 +89,20 @@ const char* getWhere(); static void validateLocks(); + +private: void grantLock(SyncObject* lock); + void init(const char* description); + static void setThread(ThreadSync* thread); FB_THREAD_ID threadId; ThreadSync* nextWaiting; // next thread in sleep que (see SyncObject) ThreadSync* prevWaiting; // previous thread in sleep que (see SyncObject) - LockType lockType; // requested lock type (see SyncObject) + SyncType lockType; // requested lock type (see SyncObject) volatile bool lockGranted; Sync* lockPending; Sync* locks; const char* description; - -protected: - static void setThread(ThreadSync* thread); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2011-05-23 15:33:25
|
Revision: 52990 http://firebird.svn.sourceforge.net/firebird/?rev=52990&view=rev Author: asfernandes Date: 2011-05-23 15:33:19 +0000 (Mon, 23 May 2011) Log Message: ----------- Make synchronization primitives work in the POSIX build. Modified Paths: -------------- firebird/trunk/src/common/classes/Synchronize.cpp firebird/trunk/src/common/classes/Synchronize.h Modified: firebird/trunk/src/common/classes/Synchronize.cpp =================================================================== --- firebird/trunk/src/common/classes/Synchronize.cpp 2011-05-23 11:45:48 UTC (rev 52989) +++ firebird/trunk/src/common/classes/Synchronize.cpp 2011-05-23 15:33:19 UTC (rev 52990) @@ -32,10 +32,20 @@ #include "../../common/common.h" #include "fb_tls.h" #include "../thd.h" - #include "SyncObject.h" #include "Synchronize.h" +#ifdef TIME_WITH_SYS_TIME +# include <sys/time.h> +# include <time.h> +#else +# ifdef HAVE_SYS_TIME_H +# include <sys/time.h> +# else +# include <time.h> +# endif +#endif + #define NANO 1000000000 #define MICRO 1000000 @@ -48,39 +58,28 @@ { #ifdef _WIN32 evnt = CreateEvent(NULL, false, false, NULL); -#endif - -#ifdef _PTHREADS +#else int ret = pthread_mutex_init(&mutex, NULL); pthread_cond_init(&condition, NULL); #endif - -#ifdef SOLARIS_MT - int ret = mutex_init(&mutex, USYNC_THREAD, NULL); - cond_init(&condition, USYNC_THREAD, NULL); -#endif } Synchronize::~Synchronize() { #ifdef _WIN32 CloseHandle(evnt); -#endif - -#ifdef _PTHREADS +#else int ret = pthread_mutex_destroy(&mutex); ret = pthread_cond_destroy(&condition); #endif - -#ifdef SOLARIS_MT - int ret = mutex_destroy(&mutex); -#endif } void Synchronize::sleep() { sleeping = true; + #ifdef _WIN32 + #ifdef _DEBUG for (;;) { @@ -91,32 +90,21 @@ #else sleep (INFINITE); #endif -#endif -#ifdef _PTHREADS +#else int ret = pthread_mutex_lock(&mutex); - CHECK_RET("pthread_mutex_lock failed, errno %d", errno); + if (ret) + system_call_failed::raise("pthread_mutex_lock", ret); while (!wakeup) pthread_cond_wait(&condition, &mutex); wakeup = false; ret = pthread_mutex_unlock(&mutex); - CHECK_RET("pthread_mutex_unlock failed, errno %d", errno); + if (ret) + system_call_failed::raise("pthread_mutex_unlock", ret); #endif -#ifdef SOLARIS_MT - int ret = mutex_lock(&mutex); - CHECK_RET("mutex_lock failed, errno %d", errno); - - while (!wakeup) - cond_wait(&condition, &mutex); - - wakeup = false; - ret = mutex_unlock(&mutex); - CHECK_RET("mutex_unlock failed, errno %d", errno); -#endif - sleeping = false; } @@ -129,9 +117,7 @@ sleeping = false; return n != WAIT_TIMEOUT; -#endif - -#ifdef _PTHREADS +#else struct timeval microTime; int ret = gettimeofday(µTime, NULL); SINT64 nanos = (SINT64) microTime.tv_sec * NANO + microTime.tv_usec * 1000 + @@ -139,8 +125,11 @@ struct timespec nanoTime; nanoTime.tv_sec = nanos / NANO; nanoTime.tv_nsec = nanos % NANO; + ret = pthread_mutex_lock (&mutex); - CHECK_RET("pthread_mutex_lock failed, errno %d", errno); + if (ret) + system_call_failed::raise("pthread_mutex_lock", ret); + int seconds = nanoTime.tv_sec - microTime.tv_sec; while (!wakeup) @@ -166,61 +155,24 @@ pthread_mutex_unlock(&mutex); return ret != ETIMEDOUT; #endif - -#ifdef SOLARIS_MT - struct timeval microTime; - int ret = gettimeofday(µTime, NULL); - SINT64 nanos = (SINT64) microTime.tv_sec * NANO + microTime.tv_usec * 1000 + - (SINT64) milliseconds * 1000000; - struct timespec nanoTime; - nanoTime.tv_sec = nanos / NANO; - nanoTime.tv_nsec = nanos % NANO; - ret = mutex_lock (&mutex); - CHECK_RET("mutex_lock failed, errno %d", errno); - int seconds = nanoTime.tv_sec - microTime.tv_sec; - - while (!wakeup) - { - ret = cond_timedwait(&condition, &mutex, &nanoTime); - if (ret == ETIMEDOUT) - break; - /*** - if (!wakeup) - Log::debug("Synchronize::sleep(milliseconds): unexpected wakeup, ret %d\n", ret); - ***/ - } - - sleeping = false; - wakeup = false; - mutex_unlock(&mutex); - - return ret != ETIMEDOUT; -#endif } void Synchronize::wake() { #ifdef _WIN32 SetEvent(evnt); -#endif - -#ifdef _PTHREADS +#else int ret = pthread_mutex_lock(&mutex); - CHECK_RET("pthread_mutex_lock failed, errno %d", errno); + if (ret) + system_call_failed::raise("pthread_mutex_lock", ret); + wakeup = true; pthread_cond_broadcast(&condition); + ret = pthread_mutex_unlock(&mutex); - CHECK_RET("pthread_mutex_unlock failed, errno %d", errno); + if (ret) + system_call_failed::raise("pthread_mutex_unlock", ret); #endif - -#ifdef SOLARIS_MT - int ret = mutex_lock(&mutex); - CHECK_RET("mutex_lock failed, errno %d", errno); - wakeup = true; - cond_broadcast(&condition); - ret = mutex_unlock(&mutex); - CHECK_RET("mutex_unlock failed, errno %d", errno); -#endif } void Synchronize::shutdown() Modified: firebird/trunk/src/common/classes/Synchronize.h =================================================================== --- firebird/trunk/src/common/classes/Synchronize.h 2011-05-23 11:45:48 UTC (rev 52989) +++ firebird/trunk/src/common/classes/Synchronize.h 2011-05-23 15:33:19 UTC (rev 52990) @@ -35,7 +35,11 @@ #include "../../common/common.h" #include "../../common/classes/SyncObject.h" +#ifndef _WIN32 +#include <pthread.h> +#endif + namespace Firebird { class Synchronize @@ -57,17 +61,10 @@ #ifdef _WIN32 void* evnt; -#endif - -#ifdef _PTHREADS +#else pthread_cond_t condition; pthread_mutex_t mutex; #endif - -#ifdef SOLARIS_MT - cond_t condition; - mutex_t mutex; -#endif }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ro...@us...> - 2012-01-17 12:33:21
|
Revision: 53876 http://firebird.svn.sourceforge.net/firebird/?rev=53876&view=rev Author: robocop Date: 2012-01-17 12:33:10 +0000 (Tue, 17 Jan 2012) Log Message: ----------- Helper method. Modified Paths: -------------- firebird/trunk/src/common/classes/MetaName.cpp firebird/trunk/src/common/classes/MetaName.h Modified: firebird/trunk/src/common/classes/MetaName.cpp =================================================================== --- firebird/trunk/src/common/classes/MetaName.cpp 2012-01-17 12:30:51 UTC (rev 53875) +++ firebird/trunk/src/common/classes/MetaName.cpp 2012-01-17 12:33:10 UTC (rev 53876) @@ -49,6 +49,14 @@ return *this; } + char* MetaName::getBuffer(const size_t l) + { + fb_assert (l < MAX_SQL_IDENTIFIER_SIZE); + init(); + count = l; + return data; + } + int MetaName::compare(const char* s, size_t l) const { if (s) @@ -112,13 +120,19 @@ va_end(params); } - char* MetaName::getBuffer(const size_t l) + size_t MetaName::copyTo(char* to, size_t toSize) const { - fb_assert (l < MAX_SQL_IDENTIFIER_SIZE); - init(); - count = l; - return data; + fb_assert(to); + fb_assert(toSize); + if (--toSize > length()) + { + toSize = length(); + } + memcpy(to, c_str(), toSize); + to[toSize] = 0; + return toSize; } + } // namespace Firebird Modified: firebird/trunk/src/common/classes/MetaName.h =================================================================== --- firebird/trunk/src/common/classes/MetaName.h 2012-01-17 12:30:51 UTC (rev 53875) +++ firebird/trunk/src/common/classes/MetaName.h 2012-01-17 12:33:10 UTC (rev 53876) @@ -100,6 +100,7 @@ void upper7(); void lower7(); void printf(const char*, ...); + size_t copyTo(char* to, size_t toSize) const; protected: static void adjustLength(const char* const s, size_t& l); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ro...@us...> - 2012-01-19 08:08:10
|
Revision: 53891 http://firebird.svn.sourceforge.net/firebird/?rev=53891&view=rev Author: robocop Date: 2012-01-19 08:07:59 +0000 (Thu, 19 Jan 2012) Log Message: ----------- Some paranoid checks for extreme cases. Modified Paths: -------------- firebird/trunk/src/common/classes/array.h firebird/trunk/src/common/classes/fb_string.cpp Modified: firebird/trunk/src/common/classes/array.h =================================================================== --- firebird/trunk/src/common/classes/array.h 2012-01-19 08:00:15 UTC (rev 53890) +++ firebird/trunk/src/common/classes/array.h 2012-01-19 08:07:59 UTC (rev 53891) @@ -35,6 +35,9 @@ namespace Firebird { +const size_t FB_MAX_SIZEOF = ~size_t(0); +const size_t FB_HALF_MAX_SIZEOF = FB_MAX_SIZEOF >> 1; + // Static part of the array template <typename T, size_t Capacity> class InlineStorage : public AutoStorage @@ -73,7 +76,11 @@ { public: explicit Array(MemoryPool& p) - : Storage(p), count(0), capacity(this->getStorageSize()), data(this->getStorage()) { } + : Storage(p), count(0), capacity(this->getStorageSize()), data(this->getStorage()) + { + // Ensure we can carry byte copy operations. + fb_assert(capacity < FB_MAX_SIZEOF / sizeof(T)); + } Array(MemoryPool& p, const size_t InitialCapacity) : Storage(p), count(0), capacity(this->getStorageSize()), data(this->getStorage()) @@ -186,6 +193,7 @@ void insert(const size_t index, const T& item) { fb_assert(index <= count); + fb_assert(count < FB_MAX_SIZEOF); ensureCapacity(count + 1); memmove(data + index + 1, data + index, sizeof(T) * (count++ - index)); data[index] = item; @@ -194,6 +202,7 @@ void insert(const size_t index, const Array<T, Storage>& items) { fb_assert(index <= count); + fb_assert(count <= FB_MAX_SIZEOF - items.count); ensureCapacity(count + items.count); memmove(data + index + items.count, data + index, sizeof(T) * (count - index)); memcpy(data + index, items.data, items.count); @@ -203,6 +212,7 @@ void insert(const size_t index, const T* items, const size_t itemsCount) { fb_assert(index <= count); + fb_assert(count <= FB_MAX_SIZEOF - itemsCount); ensureCapacity(count + itemsCount); memmove(data + index + itemsCount, data + index, sizeof(T) * (count - index)); memcpy(data + index, items, sizeof(T) * itemsCount); @@ -218,6 +228,7 @@ void add(const T* items, const size_t itemsCount) { + fb_assert(count <= FB_MAX_SIZEOF - itemsCount); ensureCapacity(count + itemsCount); memcpy(data + count, items, sizeof(T) * itemsCount); count += itemsCount; @@ -303,6 +314,7 @@ void join(const Array<T, Storage>& L) { + fb_assert(count <= FB_MAX_SIZEOF - L.count); ensureCapacity(count + L.count); memcpy(data + count, L.data, sizeof(T) * L.count); count += L.count; @@ -336,6 +348,7 @@ void push(const T* items, const size_t itemsSize) { + fb_assert(count <= FB_MAX_SIZEOF - itemsSize); ensureCapacity(count + itemsSize); memcpy(data + count, items, sizeof(T) * itemsSize); count += itemsSize; @@ -416,9 +429,20 @@ { if (newcapacity > capacity) { - if (newcapacity < capacity * 2) { - newcapacity = capacity * 2; + if (capacity <= FB_HALF_MAX_SIZEOF) + { + if (newcapacity < capacity * 2) + newcapacity = capacity * 2; } + else + { + newcapacity = FB_MAX_SIZEOF; + } + + // Ensure we can carry byte copy operations. + // What to do here, throw in release build? + fb_assert(newcapacity < FB_MAX_SIZEOF / sizeof(T)); + T* newdata = static_cast<T*> (this->getPool().allocate(sizeof(T) * newcapacity #ifdef DEBUG_GDS_ALLOC Modified: firebird/trunk/src/common/classes/fb_string.cpp =================================================================== --- firebird/trunk/src/common/classes/fb_string.cpp 2012-01-19 08:00:15 UTC (rev 53890) +++ firebird/trunk/src/common/classes/fb_string.cpp 2012-01-19 08:07:59 UTC (rev 53891) @@ -134,7 +134,7 @@ pos = length; n = 0; } - else if (pos + n > length || n == npos) { + else if (n > length || pos + n > length || n == npos) { n = length - pos; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hv...@us...> - 2012-03-30 14:15:18
|
Revision: 54288 http://firebird.svn.sourceforge.net/firebird/?rev=54288&view=rev Author: hvlad Date: 2012-03-30 14:15:08 +0000 (Fri, 30 Mar 2012) Log Message: ----------- Small refactoring Modified Paths: -------------- firebird/trunk/src/common/classes/ImplementHelper.h firebird/trunk/src/common/classes/auto.h Modified: firebird/trunk/src/common/classes/ImplementHelper.h =================================================================== --- firebird/trunk/src/common/classes/ImplementHelper.h 2012-03-30 13:52:11 UTC (rev 54287) +++ firebird/trunk/src/common/classes/ImplementHelper.h 2012-03-30 14:15:08 UTC (rev 54288) @@ -44,17 +44,7 @@ // If you need interface on stack, use template AutoPtr<YourInterface, AutoDisposable> // as second parameter to store it. -class AutoDisposable -{ -public: - static void clear(IDisposable* ptr) - { - if (ptr) - { - ptr->dispose(); - } - } -}; +typedef SimpleDispose<IDisposable> AutoDisposable; // Implement standard interface and plugin functions Modified: firebird/trunk/src/common/classes/auto.h =================================================================== --- firebird/trunk/src/common/classes/auto.h 2012-03-30 13:52:11 UTC (rev 54287) +++ firebird/trunk/src/common/classes/auto.h 2012-03-30 14:15:08 UTC (rev 54288) @@ -69,6 +69,21 @@ } }; + +template <typename T> +class SimpleDispose +{ +public: + static void clear(T* ptr) + { + if (ptr) + { + ptr->dispose(); + } + } +}; + + template <typename Where, typename Clear = SimpleDelete<Where> > class AutoPtr { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ale...@us...> - 2012-11-12 08:51:52
|
Revision: 57348 http://firebird.svn.sourceforge.net/firebird/?rev=57348&view=rev Author: alexpeshkoff Date: 2012-11-12 08:51:41 +0000 (Mon, 12 Nov 2012) Log Message: ----------- Misc Modified Paths: -------------- firebird/trunk/src/common/classes/semaphore.cpp firebird/trunk/src/common/classes/semaphore.h Modified: firebird/trunk/src/common/classes/semaphore.cpp =================================================================== --- firebird/trunk/src/common/classes/semaphore.cpp 2012-11-12 04:39:35 UTC (rev 57347) +++ firebird/trunk/src/common/classes/semaphore.cpp 2012-11-12 08:51:41 UTC (rev 57348) @@ -1,7 +1,7 @@ /* * PROGRAM: Client/Server Common Code - * MODULE: locks.cpp - * DESCRIPTION: Darwin specific semaphore support + * MODULE: semaphore.cpp + * DESCRIPTION: Semaphore support * * The contents of this file are subject to the Initial * Developer's Public License Version 1.0 (the "License"); @@ -66,7 +66,7 @@ namespace Firebird { -#ifdef COMMON_CLASSES_SEMAPHORE_MACH +#ifdef COMMON_CLASSES_SEMAPHORE_DISPATCH void SignalSafeSemaphore::init() { @@ -82,10 +82,9 @@ dispatch_release(semaphore); } -#endif // COMMON_CLASSES_SEMAPHORE_MACH +#endif // COMMON_CLASSES_SEMAPHORE_DISPATCH - #ifdef COMMON_CLASSES_SEMAPHORE_POSIX_RT #ifndef WORKING_SEM_INIT @@ -281,9 +280,10 @@ } timespec timeout = getCurrentTime(); - nanoseconds += timeout.tv_nsec; - timeout.tv_sec += nanoseconds / 1000000000l; - timeout.tv_nsec = nanoseconds % 1000000000l; + timeout.tv_sec += milliseconds / 1000; + timeout.tv_nsec += (milliseconds % 1000) * 1000000; + timeout.tv_sec += (timeout.tv_nsec / 1000000000l); + timeout.tv_nsec %= 1000000000l; err = pthread_cond_timedwait(&cv, &mu, &timeout); mtxUnlock(); Modified: firebird/trunk/src/common/classes/semaphore.h =================================================================== --- firebird/trunk/src/common/classes/semaphore.h 2012-11-12 04:39:35 UTC (rev 57347) +++ firebird/trunk/src/common/classes/semaphore.h 2012-11-12 08:51:41 UTC (rev 57348) @@ -91,8 +91,8 @@ #ifdef DARWIN -// Mach semaphore -#define COMMON_CLASSES_SEMAPHORE_MACH +// dispatch semaphore +#define COMMON_CLASSES_SEMAPHORE_DISPATCH #include <dispatch/dispatch.h> namespace Firebird This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <di...@us...> - 2013-03-12 09:39:41
|
Revision: 57769 http://sourceforge.net/p/firebird/code/57769 Author: dimitr Date: 2013-03-12 09:39:38 +0000 (Tue, 12 Mar 2013) Log Message: ----------- Disallowed default copying and assignment in sync wrappers. Fixed a theoretically possible handle leak in the condition class. Thanks to Dmitry Kovalenko. Modified Paths: -------------- firebird/trunk/src/common/classes/condition.h firebird/trunk/src/common/classes/locks.h firebird/trunk/src/common/classes/rwlock.h firebird/trunk/src/common/classes/semaphore.h Modified: firebird/trunk/src/common/classes/condition.h =================================================================== --- firebird/trunk/src/common/classes/condition.h 2013-03-12 03:06:14 UTC (rev 57768) +++ firebird/trunk/src/common/classes/condition.h 2013-03-12 09:39:38 UTC (rev 57769) @@ -61,16 +61,26 @@ FALSE, // non-signaled initially NULL); // unnamed + if (!events[SIGNAL]) + system_call_failed::raise("CreateEvent(SIGNAL)"); + // Create a manual-reset event. events[BROADCAST] = CreateEvent(NULL, // no security TRUE, // manual-reset FALSE, // non-signaled initially NULL); // unnamed - if (!events[SIGNAL] || !events[BROADCAST]) - system_call_failed::raise("CreateCondition(Event)"); + if (!events[BROADCAST]) + { + CloseHandle(events[SIGNAL]); + system_call_failed::raise("CreateEvent(BROADCAST)"); + } } + // Forbid copying + Condition(const Condition&); + Condition& operator=(const Condition&); + public: Condition() { init(); } explicit Condition(MemoryPool&) { init(); } @@ -145,6 +155,10 @@ } } + // Forbid copying + Condition(const Condition&); + Condition& operator=(const Condition&); + public: Condition() { init(); } explicit Condition(MemoryPool&) { init(); } Modified: firebird/trunk/src/common/classes/locks.h =================================================================== --- firebird/trunk/src/common/classes/locks.h 2013-03-12 03:06:14 UTC (rev 57768) +++ firebird/trunk/src/common/classes/locks.h 2013-03-12 09:39:38 UTC (rev 57769) @@ -167,6 +167,11 @@ public: static void initMutexes() { } + +private: + // Forbid copying + Mutex(const Mutex&); + Mutex& operator=(const Mutex&); }; class Spinlock : public Mutex @@ -290,6 +295,11 @@ public: static void initMutexes(); + +private: + // Forbid copying + Mutex(const Mutex&); + Mutex& operator=(const Mutex&); }; #ifdef NOT_USED_OR_REPLACED // we do not use spinlocks currently @@ -327,6 +337,11 @@ if (pthread_spin_unlock(&spinlock)) system_call_failed::raise("pthread_spin_unlock"); } + +private: + // Forbid copying + Spinlock(const Spinlock&); + Spinlock& operator=(const Spinlock&); }; #else typedef Mutex Spinlock; @@ -415,6 +430,10 @@ } private: + // Forbid copying + MutexCheckoutGuard(const MutexCheckoutGuard&); + MutexCheckoutGuard& operator=(const MutexCheckoutGuard&); + MutexUnlockGuard unlock; MutexLockGuard lock; }; Modified: firebird/trunk/src/common/classes/rwlock.h =================================================================== --- firebird/trunk/src/common/classes/rwlock.h 2013-03-12 03:06:14 UTC (rev 57768) +++ firebird/trunk/src/common/classes/rwlock.h 2013-03-12 09:39:38 UTC (rev 57769) @@ -72,8 +72,9 @@ system_call_failed::raise("CreateEvent"); } - // Forbid copy constructor - RWLock(const RWLock& source); + // Forbid copying + RWLock(const RWLock&); + RWLock& operator=(const RWLock&); public: RWLock() { init(); } @@ -199,8 +200,9 @@ AtomicCounter lockCounter; #endif - // Forbid copy constructor - RWLock(const RWLock& source); + // Forbid copying + RWLock(const RWLock&); + RWLock& operator=(const RWLock&); void init() { @@ -346,8 +348,10 @@ } private: - // Forbid copy constructor - ReadLockGuard(const ReadLockGuard& source); + // Forbid copying + ReadLockGuard(const ReadLockGuard&); + ReadLockGuard& operator=(const ReadLockGuard&); + RWLock* lock; }; @@ -383,8 +387,10 @@ } private: - // Forbid copy constructor - WriteLockGuard(const WriteLockGuard& source); + // Forbid copying + WriteLockGuard(const WriteLockGuard&); + WriteLockGuard& operator=(const WriteLockGuard&); + RWLock* lock; }; Modified: firebird/trunk/src/common/classes/semaphore.h =================================================================== --- firebird/trunk/src/common/classes/semaphore.h 2013-03-12 03:06:14 UTC (rev 57768) +++ firebird/trunk/src/common/classes/semaphore.h 2013-03-12 09:39:38 UTC (rev 57769) @@ -53,6 +53,10 @@ system_call_failed::raise("CreateSemaphore"); } + // Forbid copying + Semaphore(const Semaphore&); + Semaphore& operator=(const Semaphore&); + public: Semaphore() { init(); } explicit Semaphore(MemoryPool&) { init(); } @@ -107,6 +111,10 @@ void init(); + // Forbid copying + SignalSafeSemaphore(const SignalSafeSemaphore&); + SignalSafeSemaphore& operator=(const SignalSafeSemaphore&); + public: SignalSafeSemaphore() { init(); } explicit SignalSafeSemaphore(MemoryPool&) { init(); } @@ -157,6 +165,10 @@ void init(); + // Forbid copying + SignalSafeSemaphore(const SignalSafeSemaphore&); + SignalSafeSemaphore& operator=(const SignalSafeSemaphore&); + public: SignalSafeSemaphore() { init(); } explicit SignalSafeSemaphore(MemoryPool&) { init(); } @@ -221,6 +233,10 @@ void mtxLock(); void mtxUnlock(); + // Forbid copying + Semaphore(const Semaphore&); + Semaphore& operator=(const Semaphore&); + public: Semaphore() { init(); } explicit Semaphore(MemoryPool&) { init(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <di...@us...> - 2013-04-13 16:31:15
|
Revision: 57948 http://sourceforge.net/p/firebird/code/57948 Author: dimitr Date: 2013-04-13 16:31:12 +0000 (Sat, 13 Apr 2013) Log Message: ----------- Misc and small cleanup. Modified Paths: -------------- firebird/trunk/src/common/classes/Synchronize.cpp firebird/trunk/src/common/classes/Synchronize.h Modified: firebird/trunk/src/common/classes/Synchronize.cpp =================================================================== --- firebird/trunk/src/common/classes/Synchronize.cpp 2013-04-13 15:07:51 UTC (rev 57947) +++ firebird/trunk/src/common/classes/Synchronize.cpp 2013-04-13 16:31:12 UTC (rev 57948) @@ -56,7 +56,7 @@ sleeping(false), wakeup(false) { -#ifdef _WIN32 +#ifdef WIN_NT evnt = CreateEvent(NULL, false, false, NULL); #else int ret = pthread_mutex_init(&mutex, NULL); @@ -66,7 +66,7 @@ Synchronize::~Synchronize() { -#ifdef _WIN32 +#ifdef WIN_NT CloseHandle(evnt); #else int ret = pthread_mutex_destroy(&mutex); @@ -78,9 +78,9 @@ { sleeping = true; -#ifdef _WIN32 +#ifdef WIN_NT -#ifdef _DEBUG +#ifdef DEV_BUILD for (;;) { const int n = WaitForSingleObject(evnt, 10000); @@ -88,7 +88,7 @@ break; } #else - sleep (INFINITE); + sleep(INFINITE); #endif #else @@ -112,7 +112,7 @@ { sleeping = true; -#ifdef _WIN32 +#ifdef WIN_NT const int n = WaitForSingleObject(evnt, milliseconds); sleeping = false; @@ -159,7 +159,7 @@ void Synchronize::wake() { -#ifdef _WIN32 +#ifdef WIN_NT SetEvent(evnt); #else int ret = pthread_mutex_lock(&mutex); @@ -187,34 +187,23 @@ TLS_DECLARE(ThreadSync*, threadIndex); ThreadSync::ThreadSync(const char* desc) + : threadId(getCurrentThreadId()), nextWaiting(NULL), prevWaiting(NULL), + lockType(SYNC_NONE), lockGranted(false), lockPending(NULL), locks(NULL), + description(desc) { - init(desc); setThread(this); } -void ThreadSync::init(const char* desc) -{ - description = desc; - threadId = getCurrentThreadId(); - prevWaiting = nextWaiting = NULL; - lockType = SYNC_NONE; - lockGranted = false; - lockPending = NULL; - locks = NULL; -} - ThreadSync::~ThreadSync() { setThread(NULL); } - ThreadSync* ThreadSync::findThread() { return TLS_GET(threadIndex); } - ThreadSync* ThreadSync::getThread(const char* desc) { ThreadSync* thread = findThread(); @@ -238,7 +227,6 @@ return getThreadId(); } - const char* ThreadSync::getWhere() const { if (lockPending && lockPending->where) @@ -247,21 +235,6 @@ return ""; } - -void ThreadSync::validateLocks() -{ - ThreadSync* thread = getThread("ThreadSync::validateLocks"); - - // hvlad: not worked, probably we should implement it at some day - if (thread->locks) - { - SYNC_LOG_DEBUG("thread %d has active locks:\n", thread->threadId); - for (Sync* sync = thread->locks; sync; sync = sync->prior) - SYNC_LOG_DEBUG(" %s\n", sync->where); - } -} - - void ThreadSync::grantLock(SyncObject* lock) { fb_assert(!lockGranted); Modified: firebird/trunk/src/common/classes/Synchronize.h =================================================================== --- firebird/trunk/src/common/classes/Synchronize.h 2013-04-13 15:07:51 UTC (rev 57947) +++ firebird/trunk/src/common/classes/Synchronize.h 2013-04-13 16:31:12 UTC (rev 57948) @@ -34,7 +34,7 @@ #include "../common/classes/SyncObject.h" -#ifndef _WIN32 +#ifndef WIN_NT #include "fb_pthread.h" #endif @@ -56,9 +56,8 @@ bool shutdownInProgress; bool sleeping; volatile bool wakeup; - ///SINT64 waitTime; -#ifdef _WIN32 +#ifdef WIN_NT void* evnt; #else pthread_cond_t condition; @@ -84,11 +83,8 @@ const char* getWhere() const; - static void validateLocks(); - private: void grantLock(SyncObject* lock); - void init(const char* description); static void setThread(ThreadSync* thread); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hv...@us...> - 2013-06-16 21:29:02
|
Revision: 58193 http://sourceforge.net/p/firebird/code/58193 Author: hvlad Date: 2013-06-16 21:28:59 +0000 (Sun, 16 Jun 2013) Log Message: ----------- A cleanup and a few improvements : - ability to wait with finite timeout - separate counts of waiting readers and writers - two interlocked operations are needed when lock granted to a waiting readers (despite of its amount) Modified Paths: -------------- firebird/trunk/src/common/classes/SyncObject.cpp firebird/trunk/src/common/classes/SyncObject.h Modified: firebird/trunk/src/common/classes/SyncObject.cpp =================================================================== --- firebird/trunk/src/common/classes/SyncObject.cpp 2013-06-16 21:21:33 UTC (rev 58192) +++ firebird/trunk/src/common/classes/SyncObject.cpp 2013-06-16 21:28:59 UTC (rev 58193) @@ -38,8 +38,10 @@ namespace Firebird { +const int WRITER_INCR = 0x00010000L; +const int READERS_MASK = 0x0000FFFFL; -void SyncObject::lock(Sync* sync, SyncType type, const char* from) +bool SyncObject::lock(Sync* sync, SyncType type, const char* from, int timeOut) { ThreadSync* thread = NULL; @@ -63,10 +65,13 @@ MutexLockGuard g(mutex, FB_FUNCTION); reason(from); #endif - return; + return true; } } + if (timeOut == 0) + return false; + mutex.enter(FB_FUNCTION); ++waiters; @@ -83,7 +88,7 @@ --waiters; reason(from); mutex.leave(); - return; + return true; } } @@ -99,7 +104,7 @@ { ++monitorCount; reason(from); - return; + return true; } while (waiters == 0) @@ -112,13 +117,19 @@ { exclusiveThread = thread; WaitForFlushCache(); +#ifdef DEV_BUILD + MutexLockGuard g(mutex, FB_FUNCTION); +#endif reason(from); - return; + return true; } } + if (timeOut == 0) + return false; + mutex.enter(FB_FUNCTION); - ++waiters; + waiters += WRITER_INCR; while (!waitingThreads) { @@ -129,15 +140,15 @@ if (lockState.compareExchange(oldState, -1)) { exclusiveThread = thread; - --waiters; + waiters -= WRITER_INCR; + reason(from); mutex.leave(); - reason(from); - return; + return true; } } } - wait(type, thread, sync); + return wait(type, thread, sync, timeOut); #ifdef DEV_BUILD MutexLockGuard g(mutex, FB_FUNCTION); reason(from); @@ -163,8 +174,8 @@ WaitForFlushCache(); #ifdef DEV_BUILD MutexLockGuard g(mutex, FB_FUNCTION); +#endif reason(from); -#endif return true; } } @@ -223,7 +234,7 @@ if (lockState.compareExchange(oldState, newState)) { - if (waiters) + if (newState == 0 && waiters) grantLocks(); return; @@ -231,18 +242,6 @@ } } -void SyncObject::unlock() -{ - if (lockState > 0) - unlock(NULL, SYNC_SHARED); - else if (lockState == -1) - unlock(NULL, SYNC_EXCLUSIVE); - else - { - fb_assert(false); - } -} - void SyncObject::downgrade(SyncType type) { fb_assert(monitorCount == 0); @@ -257,7 +256,7 @@ { if (lockState.compareExchange(-1, 1)) { - if (waiters) + if (waiters & READERS_MASK) grantLocks(); return; @@ -265,7 +264,7 @@ } } -void SyncObject::wait(SyncType type, ThreadSync* thread, Sync* sync) +bool SyncObject::wait(SyncType type, ThreadSync* thread, Sync* sync, int timeOut) { if (thread->nextWaiting) { @@ -292,25 +291,53 @@ thread->lockPending = sync; mutex.leave(); - while (!thread->lockGranted) + bool wakeup = false; + while (timeOut && !thread->lockGranted) { - const bool wakeup = thread->sleep(10000); + const int wait = timeOut > 10000 ? 10000 : timeOut; + wakeup = true; + + if (timeOut == -1) + thread->sleep(); + else + wakeup = thread->sleep(wait); + if (thread->lockGranted) - break; + return true; - if (!wakeup) - { - // stalled(thread); - break; - } + //if (!wakeup) + // stalled(thread); + + if (timeOut != -1) + timeOut -= wait; } - while (!thread->lockGranted) - thread->sleep(); + if (thread->lockGranted) + return true; + + MutexLockGuard guard(mutex, "SyncObject::wait"); + if (thread->lockGranted) + return true; + + dequeThread(thread); + if (type == SYNC_SHARED) + --waiters; + else + waiters -= WRITER_INCR; + + fb_assert(timeOut >= 0); + return false; } ThreadSync* SyncObject::grantThread(ThreadSync* thread) { + ThreadSync* next = dequeThread(thread); + thread->grantLock(this); + return next; +} + +ThreadSync* SyncObject::dequeThread(ThreadSync* thread) +{ ThreadSync* next = NULL; if (thread == thread->nextWaiting) @@ -330,9 +357,6 @@ waitingThreads = next; } - --waiters; - thread->grantLock(this); - return next; } @@ -342,44 +366,54 @@ fb_assert((waiters && waitingThreads) || (!waiters && !waitingThreads)); ThreadSync* thread = waitingThreads; + if (!thread) + return; - while (thread) + if (thread->lockType == SYNC_SHARED) { - bool granted = false; + AtomicCounter::counter_type oldState = lockState; - if (thread->lockType == SYNC_SHARED) + while (oldState >= 0) { - AtomicCounter::counter_type oldState = lockState; + const int cntWake = waiters & READERS_MASK; + const AtomicCounter::counter_type newState = oldState + cntWake; + if (lockState.compareExchange(oldState, newState)) + { + waiters -= cntWake; - while (oldState >= 0) - { - const AtomicCounter::counter_type newState = oldState + 1; - if (lockState.compareExchange(oldState, newState)) + for (int i = 0; i < cntWake;) { - granted = true; - thread = grantThread(thread); - break; + if (thread->lockType == SYNC_SHARED) + { + ThreadSync* next = dequeThread(thread); + thread->grantLock(this); + thread = next; + i++; + } + else + { + thread = thread->nextWaiting; + } } - oldState = lockState; + + break; } + oldState = lockState; } - else + } + else + { + while (lockState == 0) { - while (lockState == 0) + if (lockState.compareExchange(0, -1)) { - if (lockState.compareExchange(0, -1)) - { - granted = true; - exclusiveThread = thread; - thread = grantThread(thread); - break; - } + exclusiveThread = thread; + waiters -= WRITER_INCR; + dequeThread(thread); + thread->grantLock(this); + return; } } - - if (!granted) { - break; - } } } Modified: firebird/trunk/src/common/classes/SyncObject.h =================================================================== --- firebird/trunk/src/common/classes/SyncObject.h 2013-06-16 21:21:33 UTC (rev 58192) +++ firebird/trunk/src/common/classes/SyncObject.h 2013-06-16 21:28:59 UTC (rev 58193) @@ -38,7 +38,6 @@ namespace Firebird { -inline void SYNC_LOG_DEBUG(...) {} enum SyncType { SYNC_NONE, @@ -65,11 +64,28 @@ { } - void lock(Sync* sync, SyncType type, const char* from); + void lock(Sync* sync, SyncType type, const char* from) + { + const bool ret = lock(sync, type, from, -1); + fb_assert(ret); + } + + // timeOut is in milliseconds, -1 - wait infinite + bool lock(Sync* sync, SyncType type, const char* from, int timeOut); bool lockConditional(SyncType type, const char* from); void unlock(Sync* sync, SyncType type); - void unlock(); + void unlock() + { + if (lockState > 0) + unlock(NULL, SYNC_SHARED); + else if (lockState == -1) + unlock(NULL, SYNC_EXCLUSIVE); + else + { + fb_assert(false); + } + } void downgrade(SyncType type); @@ -97,14 +113,14 @@ bool ourExclusiveLock() const; protected: - void wait(SyncType type, ThreadSync* thread, Sync* sync); + bool wait(SyncType type, ThreadSync* thread, Sync* sync, int timeOut); + ThreadSync* dequeThread(ThreadSync* thread); ThreadSync* grantThread(ThreadSync* thread); void grantLocks(); void validate(SyncType lockType) const; AtomicCounter lockState; AtomicCounter waiters; - //int waiters; int monitorCount; Mutex mutex; ThreadSync* volatile exclusiveThread; @@ -121,7 +137,6 @@ : state(SYNC_NONE), request(SYNC_NONE), syncObject(obj), - prior(NULL), where(fromWhere) { fb_assert(obj); @@ -183,7 +198,6 @@ SyncType state; SyncType request; SyncObject* syncObject; - Sync* prior; // not used const char* where; }; @@ -199,7 +213,6 @@ ~SyncLockGuard() { - //fb_assert(state != SYNC_NONE); if (state != SYNC_NONE) unlock(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <asf...@us...> - 2013-06-17 01:13:05
|
Revision: 58197 http://sourceforge.net/p/firebird/code/58197 Author: asfernandes Date: 2013-06-17 01:13:02 +0000 (Mon, 17 Jun 2013) Log Message: ----------- Misc. Modified Paths: -------------- firebird/trunk/src/common/classes/SyncObject.cpp firebird/trunk/src/common/classes/SyncObject.h Modified: firebird/trunk/src/common/classes/SyncObject.cpp =================================================================== --- firebird/trunk/src/common/classes/SyncObject.cpp 2013-06-17 00:27:06 UTC (rev 58196) +++ firebird/trunk/src/common/classes/SyncObject.cpp 2013-06-17 01:13:02 UTC (rev 58197) @@ -38,8 +38,8 @@ namespace Firebird { -const int WRITER_INCR = 0x00010000L; -const int READERS_MASK = 0x0000FFFFL; +static const int WRITER_INCR = 0x00010000L; +static const int READERS_MASK = 0x0000FFFFL; bool SyncObject::lock(Sync* sync, SyncType type, const char* from, int timeOut) { @@ -308,7 +308,7 @@ //if (!wakeup) // stalled(thread); - if (timeOut != -1) + if (timeOut != -1) timeOut -= wait; } Modified: firebird/trunk/src/common/classes/SyncObject.h =================================================================== --- firebird/trunk/src/common/classes/SyncObject.h 2013-06-17 00:27:06 UTC (rev 58196) +++ firebird/trunk/src/common/classes/SyncObject.h 2013-06-17 01:13:02 UTC (rev 58197) @@ -75,6 +75,7 @@ bool lockConditional(SyncType type, const char* from); void unlock(Sync* sync, SyncType type); + void unlock() { if (lockState > 0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hv...@us...> - 2013-07-25 14:21:48
|
Revision: 58413 http://sourceforge.net/p/firebird/code/58413 Author: hvlad Date: 2013-07-25 14:21:46 +0000 (Thu, 25 Jul 2013) Log Message: ----------- Fixed memory leak when fbclient library is unloaded manually Modified Paths: -------------- firebird/trunk/src/common/classes/alloc.cpp firebird/trunk/src/common/classes/alloc.h Modified: firebird/trunk/src/common/classes/alloc.cpp =================================================================== --- firebird/trunk/src/common/classes/alloc.cpp 2013-07-25 11:07:06 UTC (rev 58412) +++ firebird/trunk/src/common/classes/alloc.cpp 2013-07-25 14:21:46 UTC (rev 58413) @@ -115,6 +115,45 @@ MemoryStats* MemoryPool::default_stats_group = NULL; Mutex* cache_mutex = NULL; + + +namespace { + +// We cache this amount of extents to avoid memory mapping overhead +const int MAP_CACHE_SIZE = 16; // == 1 MB + +Vector<void*, MAP_CACHE_SIZE> extents_cache; + +volatile size_t map_page_size = 0; +int dev_zero_fd = 0; + +#if defined(WIN_NT) +size_t get_page_size() +{ + SYSTEM_INFO info; + GetSystemInfo(&info); + return info.dwPageSize; +} +#else +size_t get_page_size() +{ + return sysconf(_SC_PAGESIZE); +} +#endif + +inline size_t get_map_page_size() +{ + if (!map_page_size) + { + MutexLockGuard guard(*cache_mutex, "get_map_page_size"); + if (!map_page_size) + map_page_size = get_page_size(); + } + return map_page_size; +} + +} + // Initialize process memory pool (called from InstanceControl). void MemoryPool::init() @@ -157,6 +196,9 @@ default_stats_group = NULL; } + while (extents_cache.getCount()) + releaseRaw(extents_cache.pop(), DEFAULT_ALLOCATION, false); + if (cache_mutex) { cache_mutex->~Mutex(); @@ -748,43 +790,7 @@ freeBlock->nextTwin = freeBlock->priorTwin = freeBlock; } -namespace { -// We cache this amount of extents to avoid memory mapping overhead -const int MAP_CACHE_SIZE = 16; // == 1 MB - -Vector<void*, MAP_CACHE_SIZE> extents_cache; - -volatile size_t map_page_size = 0; -int dev_zero_fd = 0; - -#if defined(WIN_NT) -size_t get_page_size() -{ - SYSTEM_INFO info; - GetSystemInfo(&info); - return info.dwPageSize; -} -#else -size_t get_page_size() -{ - return sysconf(_SC_PAGESIZE); -} -#endif - -inline size_t get_map_page_size() -{ - if (!map_page_size) - { - MutexLockGuard guard(*cache_mutex, "get_map_page_size"); - if (!map_page_size) - map_page_size = get_page_size(); - } - return map_page_size; -} - -} - void* MemoryPool::allocRaw(size_t size) throw (OOM_EXCEPTION) { #ifndef USE_VALGRIND @@ -884,10 +890,10 @@ } } -void MemoryPool::releaseRaw(void* block, size_t size) throw () +void MemoryPool::releaseRaw(void* block, size_t size, bool use_cache) throw () { #ifndef USE_VALGRIND - if (size == DEFAULT_ALLOCATION) + if (use_cache && (size == DEFAULT_ALLOCATION)) { MutexLockGuard guard(*cache_mutex, "MemoryPool::releaseRaw"); if (extents_cache.getCount() < extents_cache.getCapacity()) Modified: firebird/trunk/src/common/classes/alloc.h =================================================================== --- firebird/trunk/src/common/classes/alloc.h 2013-07-25 11:07:06 UTC (rev 58412) +++ firebird/trunk/src/common/classes/alloc.h 2013-07-25 14:21:46 UTC (rev 58413) @@ -292,7 +292,7 @@ ) throw (OOM_EXCEPTION); protected: - void corrupt(const char* text) throw (); + static void corrupt(const char* text) throw (); private: virtual void memoryIsExhausted(void) throw (OOM_EXCEPTION); @@ -302,7 +302,7 @@ void validateFreeList(void) throw (); void validateBigBlock(MemBigObject* block) throw (); static void release(void* block) throw (); - void releaseRaw(void *block, size_t size) throw (); + static void releaseRaw(void *block, size_t size, bool use_cache = true) throw (); #ifdef USE_VALGRIND // Circular FIFO buffer of read/write protected blocks pending free operation This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ale...@us...> - 2013-10-01 08:08:07
|
Revision: 58680 http://sourceforge.net/p/firebird/code/58680 Author: alexpeshkoff Date: 2013-10-01 08:08:06 +0000 (Tue, 01 Oct 2013) Log Message: ----------- Fixed build with valgrind Modified Paths: -------------- firebird/trunk/src/common/classes/alloc.cpp firebird/trunk/src/common/classes/alloc.h Modified: firebird/trunk/src/common/classes/alloc.cpp =================================================================== --- firebird/trunk/src/common/classes/alloc.cpp 2013-10-01 00:30:29 UTC (rev 58679) +++ firebird/trunk/src/common/classes/alloc.cpp 2013-10-01 08:08:06 UTC (rev 58680) @@ -197,7 +197,7 @@ } while (extents_cache.getCount()) - releaseRaw(extents_cache.pop(), DEFAULT_ALLOCATION, false); + releaseRaw(true, extents_cache.pop(), DEFAULT_ALLOCATION, false); if (cache_mutex) { @@ -284,20 +284,20 @@ } else { - releaseRaw(freeObjects, ((threshold + roundingSize) / roundingSize) * sizeof(void*)); + releaseRaw(pool_destroying, freeObjects, ((threshold + roundingSize) / roundingSize) * sizeof(void*)); } freeObjects = NULL; for (MemSmallHunk* hunk; hunk = smallHunks;) { smallHunks = hunk->nextHunk; - releaseRaw(hunk, minAllocation); + releaseRaw(pool_destroying, hunk, minAllocation); } for (MemBigHunk* hunk; hunk = bigHunks;) { bigHunks = hunk->nextHunk; - releaseRaw(hunk, hunk->length); + releaseRaw(pool_destroying, hunk, hunk->length); } } @@ -529,6 +529,8 @@ #ifdef DEBUG_GDS_ALLOC memory->fileName = fileName; memory->lineNumber = line; +#endif +#ifdef MEM_DEBUG memset(&memory->body, INIT_BYTE, size); memset(&memory->body + size, GUARD_BYTE, memory->length - size - OFFSET(MemBlock*,body)); #endif @@ -692,7 +694,7 @@ { *ptr = hunk->nextHunk; decrement_mapping(hunk->length); - releaseRaw(hunk, hunk->length); + releaseRaw(pool_destroying, hunk, hunk->length); return; } } @@ -891,7 +893,7 @@ } } -void MemoryPool::releaseRaw(void* block, size_t size, bool use_cache) throw () +void MemoryPool::releaseRaw(bool destroying, void* block, size_t size, bool use_cache) throw () { #ifndef USE_VALGRIND if (use_cache && (size == DEFAULT_ALLOCATION)) @@ -914,7 +916,7 @@ // Employ extents delayed free logic only when pool is destroying. // In normal case all blocks pass through queue of sufficent length by themselves - if (pool_destroying) + if (destroying) { // Synchronize delayed free queue using extents mutex MutexLockGuard guard(*cache_mutex, "MemoryPool::releaseRaw"); Modified: firebird/trunk/src/common/classes/alloc.h =================================================================== --- firebird/trunk/src/common/classes/alloc.h 2013-10-01 00:30:29 UTC (rev 58679) +++ firebird/trunk/src/common/classes/alloc.h 2013-10-01 08:08:06 UTC (rev 58680) @@ -59,6 +59,7 @@ #undef MEM_DEBUG #ifdef DEBUG_GDS_ALLOC #define MEM_DEBUG +#define USE_VALGRIND #endif #ifdef USE_VALGRIND @@ -302,7 +303,7 @@ void validateFreeList(void) throw (); void validateBigBlock(MemBigObject* block) throw (); static void release(void* block) throw (); - static void releaseRaw(void *block, size_t size, bool use_cache = true) throw (); + static void releaseRaw(bool destroying, void *block, size_t size, bool use_cache = true) throw (); #ifdef USE_VALGRIND // Circular FIFO buffer of read/write protected blocks pending free operation This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ale...@us...> - 2014-06-19 12:25:25
|
Revision: 59732 http://sourceforge.net/p/firebird/code/59732 Author: alexpeshkoff Date: 2014-06-19 12:25:16 +0000 (Thu, 19 Jun 2014) Log Message: ----------- HPUX port - fixed assertion for RISC machines with compiler missing __thread support Modified Paths: -------------- firebird/trunk/src/common/classes/alloc.cpp firebird/trunk/src/common/classes/alloc.h firebird/trunk/src/common/classes/fb_tls.h firebird/trunk/src/common/classes/init.cpp Modified: firebird/trunk/src/common/classes/alloc.cpp =================================================================== --- firebird/trunk/src/common/classes/alloc.cpp 2014-06-19 12:24:35 UTC (rev 59731) +++ firebird/trunk/src/common/classes/alloc.cpp 2014-06-19 12:25:16 UTC (rev 59732) @@ -1092,20 +1092,42 @@ } // Declare thread-specific variable for context memory pool +#ifndef TLS_CLASS TLS_DECLARE(MemoryPool*, contextPool); +#else +TLS_DECLARE(MemoryPool*, *contextPoolPtr); +#endif //TLS_CLASS MemoryPool* MemoryPool::setContextPool(MemoryPool* newPool) { +#ifndef TLS_CLASS MemoryPool* const old = TLS_GET(contextPool); TLS_SET(contextPool, newPool); +#else + MemoryPool* const old = TLS_GET(*contextPoolPtr); + TLS_SET(*contextPoolPtr, newPool); +#endif //TLS_CLASS return old; } MemoryPool* MemoryPool::getContextPool() { +#ifndef TLS_CLASS return TLS_GET(contextPool); +#else + return TLS_GET(*contextPoolPtr); +#endif //TLS_CLASS } +void MemoryPool::contextPoolInit() +{ +#ifdef TLS_CLASS + // Allocate TLS entry for context pool + contextPoolPtr = FB_NEW(*getDefaultMemoryPool()) TLS_CLASS<MemoryPool*>; + // To be deleted by InstanceControl::InstanceList::destructors() at TLS priority +#endif //TLS_CLASS +} + MemoryPool& AutoStorage::getAutoMemoryPool() { MemoryPool* p = MemoryPool::getContextPool(); Modified: firebird/trunk/src/common/classes/alloc.h =================================================================== --- firebird/trunk/src/common/classes/alloc.h 2014-06-19 12:24:35 UTC (rev 59731) +++ firebird/trunk/src/common/classes/alloc.h 2014-06-19 12:25:16 UTC (rev 59732) @@ -358,6 +358,9 @@ static void init(); static void cleanup(); + // Initialize context pool + static void contextPoolInit(); + // Statistics void increment_usage(size_t size) throw () { Modified: firebird/trunk/src/common/classes/fb_tls.h =================================================================== --- firebird/trunk/src/common/classes/fb_tls.h 2014-06-19 12:24:35 UTC (rev 59731) +++ firebird/trunk/src/common/classes/fb_tls.h 2014-06-19 12:25:16 UTC (rev 59732) @@ -88,8 +88,8 @@ }; } // namespace Firebird # define TLS_DECLARE(TYPE, NAME) ::Firebird::Win32Tls<TYPE> NAME -# define TLS_GET(NAME) NAME.get() -# define TLS_SET(NAME, VALUE) NAME.set(VALUE) +# define TLS_GET(NAME) (NAME).get() +# define TLS_SET(NAME, VALUE) (NAME).set(VALUE) // 14-Jul-2004 Nickolay Samofatov. // @@ -163,9 +163,11 @@ } // namespace Firebird # define TLS_DECLARE(TYPE, NAME) ::Firebird::TlsValue<TYPE> NAME -# define TLS_GET(NAME) NAME.get() -# define TLS_SET(NAME, VALUE) NAME.set(VALUE) +# define TLS_GET(NAME) (NAME).get() +# define TLS_SET(NAME, VALUE) (NAME).set(VALUE) +# define TLS_CLASS TlsValue + #endif #endif // CLASSES_FB_TLS_H Modified: firebird/trunk/src/common/classes/init.cpp =================================================================== --- firebird/trunk/src/common/classes/init.cpp 2014-06-19 12:24:35 UTC (rev 59731) +++ firebird/trunk/src/common/classes/init.cpp 2014-06-19 12:25:16 UTC (rev 59732) @@ -127,6 +127,8 @@ #endif //DEBUG_INIT initDone = true; + + Firebird::MemoryPool::contextPoolInit(); } Firebird::InstanceControl::InstanceList* instanceList = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hv...@us...> - 2014-12-18 10:39:02
|
Revision: 60383 http://sourceforge.net/p/firebird/code/60383 Author: hvlad Date: 2014-12-18 10:38:54 +0000 (Thu, 18 Dec 2014) Log Message: ----------- Patch for mingw by Alexey Pavlov : Fix using function pointer Modified Paths: -------------- firebird/trunk/src/common/classes/locks.cpp firebird/trunk/src/common/classes/locks.h Modified: firebird/trunk/src/common/classes/locks.cpp =================================================================== --- firebird/trunk/src/common/classes/locks.cpp 2014-12-18 10:20:39 UTC (rev 60382) +++ firebird/trunk/src/common/classes/locks.cpp 2014-12-18 10:38:54 UTC (rev 60383) @@ -120,8 +120,8 @@ // On Win 98 and Win ME TryEnterCriticalSection is defined, but not implemented // So direct linking to it won't hurt and will signal our incompatibility with Win 95 -TryEnterCS::tTryEnterCriticalSection* TryEnterCS::m_funct = - reinterpret_cast<TryEnterCS::tTryEnterCriticalSection*>(&TryEnterCriticalSection); +TryEnterCS::tTryEnterCriticalSection TryEnterCS::m_funct = + reinterpret_cast<TryEnterCS::tTryEnterCriticalSection>(TryEnterCriticalSection); static TryEnterCS tryEnterCS; Modified: firebird/trunk/src/common/classes/locks.h =================================================================== --- firebird/trunk/src/common/classes/locks.h 2014-12-18 10:20:39 UTC (rev 60382) +++ firebird/trunk/src/common/classes/locks.h 2014-12-18 10:38:54 UTC (rev 60383) @@ -62,14 +62,13 @@ static bool tryEnter(LPCRITICAL_SECTION lpCS) { - return ((*m_funct) (lpCS) == TRUE); + return ((m_funct) (lpCS) == TRUE); } private: - typedef WINBASEAPI BOOL WINAPI tTryEnterCriticalSection - (LPCRITICAL_SECTION lpCriticalSection); + typedef BOOL (WINAPI *tTryEnterCriticalSection)(LPCRITICAL_SECTION lpCriticalSection); - static tTryEnterCriticalSection* m_funct; + static tTryEnterCriticalSection m_funct; }; class Mutex : public Reasons This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ale...@us...> - 2014-12-18 16:23:06
|
Revision: 60388 http://sourceforge.net/p/firebird/code/60388 Author: alexpeshkoff Date: 2014-12-18 16:23:03 +0000 (Thu, 18 Dec 2014) Log Message: ----------- getCount() in FB classes never throws exceptions Modified Paths: -------------- firebird/trunk/src/common/classes/SafeArg.h firebird/trunk/src/common/classes/array.h firebird/trunk/src/common/classes/fb_string.h firebird/trunk/src/common/classes/objects_array.h firebird/trunk/src/common/classes/stack.h firebird/trunk/src/common/classes/vector.h Modified: firebird/trunk/src/common/classes/SafeArg.h =================================================================== --- firebird/trunk/src/common/classes/SafeArg.h 2014-12-18 16:20:46 UTC (rev 60387) +++ firebird/trunk/src/common/classes/SafeArg.h 2014-12-18 16:23:03 UTC (rev 60388) @@ -165,7 +165,7 @@ SafeArg& operator<<(void* c); void dump(const TEXT* target[], FB_SIZE_T v_size) const; const safe_cell& getCell(FB_SIZE_T index) const; - FB_SIZE_T getCount() const; + FB_SIZE_T getCount() const throw(); private: FB_SIZE_T m_count; @@ -188,7 +188,7 @@ return *this; } -inline FB_SIZE_T SafeArg::getCount() const +inline FB_SIZE_T SafeArg::getCount() const throw() { return m_count; } Modified: firebird/trunk/src/common/classes/array.h =================================================================== --- firebird/trunk/src/common/classes/array.h 2014-12-18 16:20:46 UTC (rev 60387) +++ firebird/trunk/src/common/classes/array.h 2014-12-18 16:23:03 UTC (rev 60388) @@ -336,7 +336,7 @@ memcpy(data, items, sizeof(T) * count); } - size_type getCount() const { return count; } + size_type getCount() const throw() { return count; } bool isEmpty() const { return count == 0; } Modified: firebird/trunk/src/common/classes/fb_string.h =================================================================== --- firebird/trunk/src/common/classes/fb_string.h 2014-12-18 16:20:46 UTC (rev 60387) +++ firebird/trunk/src/common/classes/fb_string.h 2014-12-18 16:23:03 UTC (rev 60388) @@ -228,7 +228,7 @@ { return stringLength; } - size_type getCount() const + size_type getCount() const throw() { return stringLength; } Modified: firebird/trunk/src/common/classes/objects_array.h =================================================================== --- firebird/trunk/src/common/classes/objects_array.h 2014-12-18 16:20:46 UTC (rev 60387) +++ firebird/trunk/src/common/classes/objects_array.h 2014-12-18 16:23:03 UTC (rev 60388) @@ -304,7 +304,7 @@ } } - size_type getCount() const {return inherited::getCount();} + size_type getCount() const throw() {return inherited::getCount();} size_type getCapacity() const {return inherited::getCapacity();} bool hasData() const @@ -659,7 +659,7 @@ PointersArray() : values(), pointers() { } ~PointersArray() { } - size_type getCount() const + size_type getCount() const throw() { fb_assert(values.getCount() == pointers.getCount()); return values.getCount(); Modified: firebird/trunk/src/common/classes/stack.h =================================================================== --- firebird/trunk/src/common/classes/stack.h 2014-12-18 16:20:46 UTC (rev 60387) +++ firebird/trunk/src/common/classes/stack.h 2014-12-18 16:23:03 UTC (rev 60388) @@ -561,7 +561,7 @@ } } - FB_SIZE_T getCount() const + FB_SIZE_T getCount() const throw() { FB_SIZE_T rc = 0; for (Entry* entry = stk; entry; entry = entry->next) Modified: firebird/trunk/src/common/classes/vector.h =================================================================== --- firebird/trunk/src/common/classes/vector.h 2014-12-18 16:20:46 UTC (rev 60387) +++ firebird/trunk/src/common/classes/vector.h 2014-12-18 16:23:03 UTC (rev 60388) @@ -59,7 +59,7 @@ const T* begin() const { return data; } const T* end() const { return data + count; } bool hasData() const { return (count != 0); } - FB_SIZE_T getCount() const { return count; } + FB_SIZE_T getCount() const throw() { return count; } FB_SIZE_T getCapacity() const { return Capacity; } void clear() { count = 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hv...@us...> - 2015-02-16 13:53:10
|
Revision: 60700 http://sourceforge.net/p/firebird/code/60700 Author: hvlad Date: 2015-02-16 13:53:03 +0000 (Mon, 16 Feb 2015) Log Message: ----------- Correct accounting of mapped memory Modified Paths: -------------- firebird/trunk/src/common/classes/alloc.cpp firebird/trunk/src/common/classes/alloc.h Modified: firebird/trunk/src/common/classes/alloc.cpp =================================================================== --- firebird/trunk/src/common/classes/alloc.cpp 2015-02-16 11:33:06 UTC (rev 60699) +++ firebird/trunk/src/common/classes/alloc.cpp 2015-02-16 13:53:03 UTC (rev 60700) @@ -694,8 +694,8 @@ if (&hunk->blocks == freeBlock) { *ptr = hunk->nextHunk; - decrement_mapping(hunk->length); - releaseRaw(pool_destroying, hunk, hunk->length); + size_t released = releaseRaw(pool_destroying, hunk, hunk->length); + decrement_mapping(released); return; } } @@ -894,7 +894,7 @@ } } -void MemoryPool::releaseRaw(bool destroying, void* block, size_t size, bool use_cache) throw () +size_t MemoryPool::releaseRaw(bool destroying, void* block, size_t size, bool use_cache) throw () { #ifndef USE_VALGRIND if (use_cache && (size == DEFAULT_ALLOCATION)) @@ -903,7 +903,7 @@ if (extents_cache.getCount() < extents_cache.getCapacity()) { extents_cache.push(block); - return; + return size; } } #else @@ -930,7 +930,7 @@ item->size = size; item->handle = handle; delayedExtentCount++; - return; + return size; } DelayedExtent* item = &delayedExtents[delayedExtentsPos]; @@ -970,6 +970,8 @@ #endif #endif // WIN_NT corrupt("OS memory deallocation error"); + + return size; } void MemoryPool::globalFree(void* block) throw () Modified: firebird/trunk/src/common/classes/alloc.h =================================================================== --- firebird/trunk/src/common/classes/alloc.h 2015-02-16 11:33:06 UTC (rev 60699) +++ firebird/trunk/src/common/classes/alloc.h 2015-02-16 13:53:03 UTC (rev 60700) @@ -302,7 +302,7 @@ void validateFreeList(void) throw (); void validateBigBlock(MemBigObject* block) throw (); static void release(void* block) throw (); - static void releaseRaw(bool destroying, void *block, size_t size, bool use_cache = true) throw (); + static size_t releaseRaw(bool destroying, void *block, size_t size, bool use_cache = true) throw (); #ifdef USE_VALGRIND // Circular FIFO buffer of read/write protected blocks pending free operation This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ale...@us...> - 2015-10-09 11:45:11
|
Revision: 62337 http://sourceforge.net/p/firebird/code/62337 Author: alexpeshkoff Date: 2015-10-09 11:45:08 +0000 (Fri, 09 Oct 2015) Log Message: ----------- Added memory pool describing constant MAX_MEDUIM_BLOCK_SIZE Modified Paths: -------------- firebird/trunk/src/common/classes/alloc.h firebird/trunk/src/common/classes/misc/class_test.cpp Modified: firebird/trunk/src/common/classes/alloc.h =================================================================== --- firebird/trunk/src/common/classes/alloc.h 2015-10-09 08:35:21 UTC (rev 62336) +++ firebird/trunk/src/common/classes/alloc.h 2015-10-09 11:45:08 UTC (rev 62337) @@ -165,6 +165,9 @@ static MemoryStats* default_stats_group; public: + // This is maximum block size which is cached (not allocated directly from OS) + enum RecommendedBufferSize { MAX_MEDUIM_BLOCK_SIZE = 64384 }; // MediumLimits::TOP_LIMIT - 128 + static MemoryPool* defaultMemoryManager; public: Modified: firebird/trunk/src/common/classes/misc/class_test.cpp =================================================================== --- firebird/trunk/src/common/classes/misc/class_test.cpp 2015-10-09 08:35:21 UTC (rev 62336) +++ firebird/trunk/src/common/classes/misc/class_test.cpp 2015-10-09 11:45:08 UTC (rev 62337) @@ -579,6 +579,12 @@ VERIFY_POOL(pool); VERIFY_POOL(parent); + printf("Allocate max recommended medium buffer (%d bytes): ", MemoryPool::MAX_MEDUIM_BLOCK_SIZE); + void* maxMedium = pool->allocate(MemoryPool::MAX_MEDUIM_BLOCK_SIZE); + printf(" DONE\n"); + VERIFY_POOL(pool); + VERIFY_POOL(parent); + printf("Deallocate the rest of small items in quasi-random order: "); while (items.getNext()) { pool->deallocate(items.current().item); @@ -593,6 +599,12 @@ } while (bigItems.getNext()); printf(" DONE\n"); + printf("Deallocate max recommended medium buffer: "); + pool->deallocate(maxMedium); + printf(" DONE\n"); + VERIFY_POOL(pool); + VERIFY_POOL(parent); + printf("Deallocate %d large items: ", LARGE_ITEMS/2); for (i = 0; i<LARGE_ITEMS/2; i++) pool->deallocate(la[i]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |