void* myNew(size_t size, const char* file, int line) { #ifdef USE_CPLUSPLUS_11_MUTEX std::lock_guard<std::mutex> lg(GetMutex()); #else Amju::MutexLocker ml(GetMutex()); #endif // We have to allow allocations of size 0. // To make sure this works OK with malloc, change size to 1 in this case. // TODO Also print warning ? if (size == 0) { size = 1; } void* p = malloc(size); assert(depth >= 0); ++depth; if (ready && depth == 1) { currentAlloc++; if (breakId == currentAlloc) { // Break - use assert by default, or TODO allow another function to be set std::cout << "Mem: debug break on ID: " << breakId << "\n"; myBreaker.Break(); } if (breakSize && breakSize == size) { // Break on allocation of this size // TODO Allow another function to be called now std::cout << "Mem: debug break on size: " << size << "\n"; myBreaker.Break(); } totalMemAllocated += size; if (totalMemAllocated > maxMemAllocated) { maxMemAllocated = totalMemAllocated; } // Check that total is under a limit if set if (limit && totalMemAllocated > limit) { // Break - TODO allow another function ? std::cout << "Mem: over limit! Limit: " << limit << " total now: " << totalMemAllocated << "\n"; myBreaker.Break(); } // Avoid [] so we don't need default ctor std::pair<void*, Allocation> kv = std::make_pair(p, Allocation(size, p, currentAlloc, file, line, Amju::CallStack::Instance()->GetFunctionNames())); AllocMgr::Instance()->allocMap.insert(kv); } assert(depth >= 0); --depth; return p; }
// DumpAllocations //------------------------------------------------------------------------------ /*static*/ void MemTracker::DumpAllocations() { if ( s_Enabled == false ) { OUTPUT( "DumpAllocations failed - MemTracker not enabled\n" ); return; } if ( s_Initialized == false ) { OUTPUT( "DumpAllocations : No allocations\n" ); return; } MutexHolder mh( GetMutex() ); if ( s_AllocationCount == 0 ) { OUTPUT( "DumpAllocations : No allocations\n" ); return; } uint64_t total = 0; uint64_t numAllocs = 0; // for each leak, we'll print a view of the memory unsigned char displayChar[256]; memset( displayChar, '.', sizeof( displayChar ) ); const unsigned char * okChars = (const unsigned char *)"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`1234567890-=!@#$^&*()_+[]{};:'\",<>/?|\\"; const unsigned char * ok = okChars; for ( ;; ) { unsigned char c = *ok; if ( c == 0 ) break; displayChar[ c ] = c; ++ok; } char memView[ 32 ] = { 0 }; OUTPUT( "--- DumpAllocations ------------------------------------------------\n" ); for ( size_t i=0; i<ALLOCATION_HASH_SIZE; ++i ) { Allocation * a = s_AllocationHashTable[ i ]; while ( a ) { uint32_t id = a->m_Id; uint64_t addr = (size_t)a->m_Ptr; uint64_t size = a->m_Size; // format a view of the memory contents const char * src = (const char *)addr; char * dst = memView; const size_t num = Math::Min< size_t >( (size_t)size, 31 ); for ( uint32_t j=0; j<num; ++j ) { unsigned char c = *src; *dst = displayChar[ c ]; ++src; ++dst; } *dst = 0; OUTPUT( "%s(%u): Id %u : %" PRIu64 " bytes @ 0x%016" PRIx64 " (Mem: %s)\n", a->m_File, a->m_Line, id, size, addr, memView ); ++numAllocs; total += size; a = a->m_Next; } } OUTPUT( "--------------------------------------------------------------------\n" ); OUTPUT( "Total: %" PRIu64 " bytes in %" PRIu64 " allocs\n", total, numAllocs ); OUTPUT( "--------------------------------------------------------------------\n" ); }
void unregisterSelf() { std::lock_guard<std::mutex> lock(GetMutex()); auto& objects = GetRegisteredObjects(lock); objects.erase(this->getRemoteId()); }
void CSeqVector::GetSeqData(TSeqPos start, TSeqPos stop, string& buffer) const { TMutexGuard guard(GetMutex()); x_GetIterator(start).GetSeqData(start, stop, buffer); }
CConstRef<CSeq_literal> CSeqVector::GetGapSeq_literal(TSeqPos pos) const { TMutexGuard guard(GetMutex()); return x_GetIterator(pos).GetGapSeq_literal(); }
TSeqPos CSeqVector::GetGapSizeForward(TSeqPos pos) const { TMutexGuard guard(GetMutex()); return x_GetIterator(pos).GetGapSizeForward(); }
int OutputMonitor::__CreateMutexEvent() { int ret; assert(this->m_hNotifyEvt == NULL); assert(this->m_hDBWinMutex == NULL); assert(this->m_hDBWinBufferReady == NULL); assert(this->m_hDBWinDataReady == NULL); this->m_hNotifyEvt = GetEvent(NULL,1); if(this->m_hNotifyEvt == NULL) { ret = GETERRNO(); goto fail; } /*now first to make sure that the*/ if (this->m_GlobalWin32) { this->m_hDBWinMutex = GetMutex("Global\\DBWinMutex",0); } else { this->m_hDBWinMutex = GetMutex("DBWinMutex", 0); } if(this->m_hDBWinMutex == NULL) { if (this->m_GlobalWin32) { this->m_hDBWinMutex = GetMutex("Global\\DBWinMutex",1); } else { this->m_hDBWinMutex = GetMutex("DBWinMutex", 1); } if(this->m_hDBWinMutex == NULL) { ret = GETERRNO(); goto fail; } } if (this->m_GlobalWin32) { this->m_hDBWinBufferReady = GetEvent("Global\\DBWIN_BUFFER_READY", 0); } else { this->m_hDBWinBufferReady = GetEvent("DBWIN_BUFFER_READY", 0); } if(this->m_hDBWinBufferReady == NULL) { if (this->m_GlobalWin32) { this->m_hDBWinBufferReady = GetEvent("Global\\DBWIN_BUFFER_READY", 1); } else { this->m_hDBWinBufferReady = GetEvent("DBWIN_BUFFER_READY", 1); } if(this->m_hDBWinBufferReady == NULL) { ret = GETERRNO(); goto fail; } } if (this->m_GlobalWin32) { this->m_hDBWinDataReady = GetEvent("Global\\DBWIN_DATA_READY", 0); } else { this->m_hDBWinDataReady = GetEvent("DBWIN_DATA_READY", 0); } if(this->m_hDBWinDataReady == NULL) { if (this->m_GlobalWin32) { this->m_hDBWinDataReady = GetEvent("Global\\DBWIN_DATA_READY", 1); } else { this->m_hDBWinDataReady = GetEvent("DBWIN_DATA_READY", 1); } if(this->m_hDBWinDataReady == NULL) { ret = GETERRNO(); goto fail; } } SETERRNO(0); return 0; fail: this->__CloseMutexEvent(); SETERRNO(ret); return -ret; }