sal/rtl/alloc_arena.cxx | 431 ++++++++++++-------------------------- sal/rtl/alloc_cache.cxx | 530 +++++++++++++++-------------------------------- sal/rtl/alloc_cache.hxx | 38 +-- sal/rtl/alloc_global.cxx | 95 ++------ sal/rtl/alloc_impl.hxx | 36 +-- sal/rtl/bootstrap.cxx | 408 +++++++++++++++++++++--------------- 6 files changed, 618 insertions(+), 920 deletions(-)
New commits: commit 3b4fdb3f64a5db4ecfd38242c6b799c5d248a066 Author: Chris Sherlock <chris.sherloc...@gmail.com> Date: Sat Jul 22 23:43:20 2017 +1000 rtl: fix bootstrap formatting, comparison to nullptr Change-Id: I8d00e616a56cc3edac6ba2149fd6f9ae44c23a95 diff --git a/sal/rtl/bootstrap.cxx b/sal/rtl/bootstrap.cxx index 1b66dbab5c78..a3bbb277a448 100644 --- a/sal/rtl/bootstrap.cxx +++ b/sal/rtl/bootstrap.cxx @@ -60,16 +60,19 @@ using rtl::OUStringToOString; struct Bootstrap_Impl; -namespace { +namespace +{ static char const VND_SUN_STAR_PATHNAME[] = "vnd.sun.star.pathname:"; -bool isPathnameUrl(rtl::OUString const & url) { +bool isPathnameUrl(rtl::OUString const & url) +{ return url.matchIgnoreAsciiCase(VND_SUN_STAR_PATHNAME); } -bool resolvePathnameUrl(rtl::OUString * url) { - OSL_ASSERT(url != nullptr); +bool resolvePathnameUrl(rtl::OUString * url) +{ + OSL_ASSERT(url); if (!isPathnameUrl(*url) || (osl::FileBase::getFileURLFromSystemPath( url->copy(RTL_CONSTASCII_LENGTH(VND_SUN_STAR_PATHNAME)), *url) == @@ -100,7 +103,7 @@ rtl::OUString recursivelyExpandMacros( Bootstrap_Impl const * requestFile, rtl::OUString const & requestKey, ExpandRequestLink const * requestStack) { - for (; requestStack != nullptr; requestStack = requestStack->next) { + for (; requestStack; requestStack = requestStack->next) { if (requestStack->file == requestFile && requestStack->key == requestKey) { @@ -111,7 +114,7 @@ rtl::OUString recursivelyExpandMacros( return expandMacros(file, text, mode, &link); } -} +} // end namespace struct rtl_bootstrap_NameValue { @@ -120,8 +123,7 @@ struct rtl_bootstrap_NameValue rtl_bootstrap_NameValue() {} - rtl_bootstrap_NameValue( - OUString const & name, OUString const & value ) + rtl_bootstrap_NameValue(OUString const & name, OUString const & value ) : sName( name ), sValue( value ) {} @@ -133,9 +135,11 @@ bool find( NameValueList const & list, rtl::OUString const & key, rtl::OUString * value) { - OSL_ASSERT(value != nullptr); - for (NameValueList::const_iterator i(list.begin()); i != list.end(); ++i) { - if (i->sName == key) { + OSL_ASSERT(value); + for (NameValueList::const_iterator i(list.begin()); i != list.end(); ++i) + { + if (i->sName == key) + { *value = i->sValue; return true; } @@ -143,7 +147,8 @@ bool find( return false; } -namespace { +namespace +{ struct rtl_bootstrap_set_list : public rtl::Static< NameValueList, rtl_bootstrap_set_list > {}; } @@ -151,9 +156,10 @@ namespace { static bool getFromCommandLineArgs( rtl::OUString const & key, rtl::OUString * value ) { - OSL_ASSERT(value != nullptr); + OSL_ASSERT(value); + static NameValueList *pNameValueList = nullptr; - if( ! pNameValueList ) + if (!pNameValueList) { static NameValueList nameValueList; @@ -169,12 +175,13 @@ static bool getFromCommandLineArgs( pArg->buffer[4] == ':' ) { sal_Int32 nIndex = rtl_ustr_indexOfChar( pArg->buffer, '=' ); + if( nIndex >= 0 ) { - rtl_bootstrap_NameValue nameValue; nameValue.sName = OUString( &(pArg->buffer[5]), nIndex - 5 ); nameValue.sValue = OUString( &(pArg->buffer[nIndex+1]) ); + if( i == nArgCount-1 && nameValue.sValue.getLength() && nameValue.sValue[nameValue.sValue.getLength()-1] == 13 ) @@ -184,6 +191,7 @@ static bool getFromCommandLineArgs( // that was edited on windows nameValue.sValue = nameValue.sValue.copy(0,nameValue.sValue.getLength()-1); } + nameValueList.push_back( nameValue ); } } @@ -194,11 +202,11 @@ static bool getFromCommandLineArgs( bool found = false; - for( NameValueList::iterator ii = pNameValueList->begin() ; - ii != pNameValueList->end() ; - ++ii ) + for(NameValueList::iterator ii = pNameValueList->begin(); + ii != pNameValueList->end(); + ++ii) { - if( (*ii).sName == key ) + if ((*ii).sName == key) { *value = (*ii).sValue; found = true; @@ -209,7 +217,7 @@ static bool getFromCommandLineArgs( return found; } -static void getExecutableDirectory_Impl (rtl_uString ** ppDirURL) +static void getExecutableDirectory_Impl(rtl_uString ** ppDirURL) { OUString fileName; osl_getExecutableFile(&(fileName.pData)); @@ -222,9 +230,9 @@ static void getExecutableDirectory_Impl (rtl_uString ** ppDirURL) static OUString & getIniFileName_Impl() { - osl::MutexGuard guard( osl::Mutex::getGlobalMutex() ); + osl::MutexGuard guard(osl::Mutex::getGlobalMutex()); static OUString *pStaticName = nullptr; - if( ! pStaticName ) + if (!pStaticName) { OUString fileName; @@ -243,8 +251,7 @@ static OUString & getIniFileName_Impl() fileName = rtl::OUString("vnd.sun.star.pathname:/assets/rc"); resolvePathnameUrl(&fileName); #else - if(getFromCommandLineArgs( - "INIFILENAME", &fileName)) + if (getFromCommandLineArgs("INIFILENAME", &fileName)) { resolvePathnameUrl(&fileName); } @@ -254,14 +261,18 @@ static OUString & getIniFileName_Impl() // get rid of a potential executable extension OUString progExt = ".bin"; - if(fileName.getLength() > progExt.getLength() - && fileName.copy(fileName.getLength() - progExt.getLength()).equalsIgnoreAsciiCase(progExt)) + if (fileName.getLength() > progExt.getLength() + && fileName.copy(fileName.getLength() - progExt.getLength()).equalsIgnoreAsciiCase(progExt)) + { fileName = fileName.copy(0, fileName.getLength() - progExt.getLength()); + } progExt = ".exe"; - if(fileName.getLength() > progExt.getLength() - && fileName.copy(fileName.getLength() - progExt.getLength()).equalsIgnoreAsciiCase(progExt)) + if (fileName.getLength() > progExt.getLength() + && fileName.copy(fileName.getLength() - progExt.getLength()).equalsIgnoreAsciiCase(progExt)) + { fileName = fileName.copy(0, fileName.getLength() - progExt.getLength()); + } // append config file suffix fileName += SAL_CONFIGFILE(""); @@ -270,14 +281,14 @@ static OUString & getIniFileName_Impl() // We keep only executables in the MacOS folder, and all // rc files in LIBO_ETC_FOLDER (typically "Resources"). sal_Int32 off = fileName.lastIndexOf( "/MacOS/" ); - if ( off != -1 ) - fileName = fileName.replaceAt( off + 1, strlen("MacOS"), LIBO_ETC_FOLDER ); + if (off != -1) + fileName = fileName.replaceAt(off + 1, strlen("MacOS"), LIBO_ETC_FOLDER); #endif } #endif static OUString theFileName; - if(fileName.getLength()) + if (fileName.getLength()) theFileName = fileName; pStaticName = &theFileName; @@ -291,9 +302,9 @@ static OUString & getIniFileName_Impl() inline void EnsureNoFinalSlash (rtl::OUString & url) { sal_Int32 i = url.getLength(); - if (i > 0 && url[i - 1] == '/') { + + if (i > 0 && url[i - 1] == '/') url = url.copy(0, i - 1); - } } struct Bootstrap_Impl @@ -333,18 +344,18 @@ Bootstrap_Impl::Bootstrap_Impl( OUString const & rIniName ) _base_ini( nullptr ), _iniName (rIniName) { - OUString base_ini( getIniFileName_Impl() ); + OUString base_ini(getIniFileName_Impl()); // normalize path FileStatus status( osl_FileStatus_Mask_FileURL ); DirectoryItem dirItem; - if (DirectoryItem::get( base_ini, dirItem ) == DirectoryItem::E_None && - dirItem.getFileStatus( status ) == DirectoryItem::E_None) + if (DirectoryItem::get(base_ini, dirItem) == DirectoryItem::E_None && + dirItem.getFileStatus(status) == DirectoryItem::E_None) { base_ini = status.getFileURL(); - if ( rIniName != base_ini ) + if (rIniName != base_ini) { _base_ini = static_cast< Bootstrap_Impl * >( - rtl_bootstrap_args_open( base_ini.pData ) ); + rtl_bootstrap_args_open(base_ini.pData)); } } SAL_INFO("sal.bootstrap", "Bootstrap_Impl(): sFile=" << _iniName); @@ -356,15 +367,13 @@ Bootstrap_Impl::Bootstrap_Impl( OUString const & rIniName ) while (osl_readLine(handle , reinterpret_cast<sal_Sequence **>(&seq)) == osl_File_E_None) { - OString line( reinterpret_cast<const char *>(seq.getConstArray()), seq.getLength() ); + OString line(reinterpret_cast<const char *>(seq.getConstArray()), seq.getLength()); sal_Int32 nIndex = line.indexOf('='); if (nIndex >= 1) { struct rtl_bootstrap_NameValue nameValue; - nameValue.sName = OStringToOUString( - line.copy(0,nIndex).trim(), RTL_TEXTENCODING_ASCII_US ); - nameValue.sValue = OStringToOUString( - line.copy(nIndex+1).trim(), RTL_TEXTENCODING_UTF8 ); + nameValue.sName = OStringToOUString(line.copy(0,nIndex).trim(), RTL_TEXTENCODING_ASCII_US); + nameValue.sValue = OStringToOUString(line.copy(nIndex+1).trim(), RTL_TEXTENCODING_UTF8); SAL_INFO("sal.bootstrap", "pushing: name=" << nameValue.sName << " value=" << nameValue.sValue); @@ -381,7 +390,7 @@ Bootstrap_Impl::Bootstrap_Impl( OUString const & rIniName ) Bootstrap_Impl::~Bootstrap_Impl() { - if (_base_ini != nullptr) + if (_base_ini) rtl_bootstrap_args_close( _base_ini ); } @@ -389,14 +398,14 @@ namespace { Bootstrap_Impl * get_static_bootstrap_handle() { - osl::MutexGuard guard( osl::Mutex::getGlobalMutex() ); + osl::MutexGuard guard(osl::Mutex::getGlobalMutex()); static Bootstrap_Impl * s_handle = nullptr; - if (s_handle == nullptr) + if (!s_handle) { - OUString iniName (getIniFileName_Impl()); + OUString iniName(getIniFileName_Impl()); s_handle = static_cast< Bootstrap_Impl * >( - rtl_bootstrap_args_open( iniName.pData ) ); - if (s_handle == nullptr) + rtl_bootstrap_args_open(iniName.pData)); + if (!s_handle) { Bootstrap_Impl * that = new Bootstrap_Impl( iniName ); ++that->_nRefCount; @@ -406,10 +415,12 @@ Bootstrap_Impl * get_static_bootstrap_handle() return s_handle; } -struct FundamentalIniData { +struct FundamentalIniData +{ rtlBootstrapHandle ini; - FundamentalIniData() { + FundamentalIniData() + { OUString uri; ini = (get_static_bootstrap_handle()->getValue( @@ -435,23 +446,28 @@ bool Bootstrap_Impl::getValue( LookupMode mode, bool override, ExpandRequestLink const * requestStack) const { - if (mode == LOOKUP_MODE_NORMAL && key == "URE_BOOTSTRAP") { + if (mode == LOOKUP_MODE_NORMAL && key == "URE_BOOTSTRAP") mode = LOOKUP_MODE_URE_BOOTSTRAP; - } - if (override && getDirectValue(key, value, mode, requestStack)) { + + if (override && getDirectValue(key, value, mode, requestStack)) return true; - } - if (key == "_OS") { + + if (key == "_OS") + { rtl_uString_assign( value, rtl::OUString(RTL_OS).pData); return true; } - if (key == "_ARCH") { + + if (key == "_ARCH") + { rtl_uString_assign( value, rtl::OUString(RTL_ARCH).pData); return true; } - if (key == "_CPPU_ENV") { + + if (key == "_CPPU_ENV") + { rtl_uString_assign( value, (rtl::OUString( @@ -459,71 +475,83 @@ bool Bootstrap_Impl::getValue( pData)); return true; } + #ifdef ANDROID - if (key == "APP_DATA_DIR") { + if (key == "APP_DATA_DIR") + { const char *app_data_dir = lo_get_app_data_dir(); rtl_uString_assign( value, rtl::OUString(app_data_dir, strlen(app_data_dir), RTL_TEXTENCODING_UTF8).pData); return true; } #endif + #ifdef IOS - if (key == "APP_DATA_DIR") { + if (key == "APP_DATA_DIR") + { const char *app_data_dir = [[[[NSBundle mainBundle] bundlePath] stringByAddingPercentEncodingWithAllowedCharacters: [NSCharacterSet URLPathAllowedCharacterSet]] UTF8String]; rtl_uString_assign( value, rtl::OUString(app_data_dir, strlen(app_data_dir), RTL_TEXTENCODING_UTF8).pData); return true; } #endif - if (key == "ORIGIN") { + + if (key == "ORIGIN") + { rtl_uString_assign( value, _iniName.copy( 0, std::max<sal_Int32>(0, _iniName.lastIndexOf('/'))).pData); return true; } - if (getAmbienceValue(key, value, mode, requestStack)) { + + if (getAmbienceValue(key, value, mode, requestStack)) return true; - } - if (key == "SYSUSERCONFIG") { + + if (key == "SYSUSERCONFIG") + { rtl::OUString v; bool b = osl::Security().getConfigDir(v); EnsureNoFinalSlash(v); rtl_uString_assign(value, v.pData); return b; } - if (key == "SYSUSERHOME") { + + if (key == "SYSUSERHOME") + { rtl::OUString v; bool b = osl::Security().getHomeDir(v); EnsureNoFinalSlash(v); rtl_uString_assign(value, v.pData); return b; } - if (key == "SYSBINDIR") { + + if (key == "SYSBINDIR") + { getExecutableDirectory_Impl(value); return true; } - if (_base_ini != nullptr && - _base_ini->getDirectValue(key, value, mode, requestStack)) - { + + if (_base_ini != nullptr && _base_ini->getDirectValue(key, value, mode, requestStack)) return true; - } - if (!override && getDirectValue(key, value, mode, requestStack)) { + + if (!override && getDirectValue(key, value, mode, requestStack)) return true; - } - if (mode == LOOKUP_MODE_NORMAL) { + + if (mode == LOOKUP_MODE_NORMAL) + { FundamentalIniData const & d = FundamentalIni::get(); Bootstrap_Impl const * b = static_cast<Bootstrap_Impl const *>(d.ini); - if (b != nullptr && b != this && - b->getDirectValue(key, value, mode, requestStack)) - { + if (b != nullptr && b != this && b->getDirectValue(key, value, mode, requestStack)) return true; - } } - if (defaultValue != nullptr) { + + if (defaultValue != nullptr) + { rtl_uString_assign(value, defaultValue); return true; } + rtl_uString_new(value); return false; } @@ -533,10 +561,12 @@ bool Bootstrap_Impl::getDirectValue( ExpandRequestLink const * requestStack) const { rtl::OUString v; - if (find(_nameValueList, key, &v)) { + if (find(_nameValueList, key, &v)) + { expandValue(value, v, mode, this, key, requestStack); return true; } + return false; } @@ -546,16 +576,19 @@ bool Bootstrap_Impl::getAmbienceValue( { rtl::OUString v; bool f; + { osl::MutexGuard g(osl::Mutex::getGlobalMutex()); f = find(rtl_bootstrap_set_list::get(), key, &v); } + if (f || getFromCommandLineArgs(key, &v) || osl_getEnvironment(key.pData, &v.pData) == osl_Process_E_None) { expandValue(value, v, mode, nullptr, key, requestStack); return true; } + return false; } @@ -588,15 +621,18 @@ struct bootstrap_map { // get and release must only be called properly synchronized via some mutex // (e.g., osl::Mutex::getGlobalMutex()): - static t * get() { - if (m_map == nullptr) { + static t * get() + { + if (m_map == nullptr) m_map = new t; - } + return m_map; } - static void release() { - if (m_map != nullptr && m_map->empty()) { + static void release() + { + if (m_map != nullptr && m_map->empty()) + { delete m_map; m_map = nullptr; } @@ -610,41 +646,40 @@ bootstrap_map::t * bootstrap_map::m_map = nullptr; } -rtlBootstrapHandle SAL_CALL rtl_bootstrap_args_open ( - rtl_uString * pIniName -) +rtlBootstrapHandle SAL_CALL rtl_bootstrap_args_open(rtl_uString * pIniName) { OUString iniName( pIniName ); // normalize path - FileStatus status( osl_FileStatus_Mask_FileURL ); + FileStatus status(osl_FileStatus_Mask_FileURL); DirectoryItem dirItem; - if (DirectoryItem::get( iniName, dirItem ) != DirectoryItem::E_None || - dirItem.getFileStatus( status ) != DirectoryItem::E_None) + if (DirectoryItem::get(iniName, dirItem) != DirectoryItem::E_None || + dirItem.getFileStatus(status) != DirectoryItem::E_None) { return nullptr; } + iniName = status.getFileURL(); Bootstrap_Impl * that; - osl::ResettableMutexGuard guard( osl::Mutex::getGlobalMutex() ); + osl::ResettableMutexGuard guard(osl::Mutex::getGlobalMutex()); bootstrap_map::t* p_bootstrap_map = bootstrap_map::get(); - bootstrap_map::t::const_iterator iFind( p_bootstrap_map->find( iniName ) ); + bootstrap_map::t::const_iterator iFind(p_bootstrap_map->find(iniName)); if (iFind == p_bootstrap_map->end()) { bootstrap_map::release(); guard.clear(); - that = new Bootstrap_Impl( iniName ); + that = new Bootstrap_Impl(iniName); guard.reset(); p_bootstrap_map = bootstrap_map::get(); - iFind = p_bootstrap_map->find( iniName ); + iFind = p_bootstrap_map->find(iniName); if (iFind == p_bootstrap_map->end()) { ++that->_nRefCount; ::std::pair< bootstrap_map::t::iterator, bool > insertion( p_bootstrap_map->insert( - bootstrap_map::t::value_type( iniName, that ) ) ); - OSL_ASSERT( insertion.second ); + bootstrap_map::t::value_type(iniName, that))); + OSL_ASSERT(insertion.second); } else { @@ -663,19 +698,18 @@ rtlBootstrapHandle SAL_CALL rtl_bootstrap_args_open ( return static_cast< rtlBootstrapHandle >( that ); } -void SAL_CALL rtl_bootstrap_args_close ( - rtlBootstrapHandle handle -) SAL_THROW_EXTERN_C() +void SAL_CALL rtl_bootstrap_args_close(rtlBootstrapHandle handle) SAL_THROW_EXTERN_C() { - if (handle == nullptr) + if (!handle) return; + Bootstrap_Impl * that = static_cast< Bootstrap_Impl * >( handle ); - osl::MutexGuard guard( osl::Mutex::getGlobalMutex() ); + osl::MutexGuard guard(osl::Mutex::getGlobalMutex()); bootstrap_map::t* p_bootstrap_map = bootstrap_map::get(); - OSL_ASSERT( - p_bootstrap_map->find( that->_iniName )->second == that ); + OSL_ASSERT(p_bootstrap_map->find(that->_iniName)->second == that); --that->_nRefCount; + if (that->_nRefCount == 0) { std::size_t const nLeaking = 8; // only hold up to 8 files statically @@ -698,14 +732,15 @@ sal_Bool SAL_CALL rtl_bootstrap_get_from_handle( rtl_uString * pDefault ) { - osl::MutexGuard guard( osl::Mutex::getGlobalMutex() ); + osl::MutexGuard guard(osl::Mutex::getGlobalMutex()); bool found = false; if(ppValue && pName) { if (handle == nullptr) handle = get_static_bootstrap_handle(); - found = static_cast< Bootstrap_Impl * >( handle )->getValue( + + found = static_cast< Bootstrap_Impl * >(handle)->getValue( pName, ppValue, pDefault, LOOKUP_MODE_NORMAL, false, nullptr ); } @@ -736,7 +771,7 @@ void SAL_CALL rtl_bootstrap_setIniFileName ( rtl_uString * pName ) { - osl::MutexGuard guard( osl::Mutex::getGlobalMutex() ); + osl::MutexGuard guard(osl::Mutex::getGlobalMutex()); OUString & file = getIniFileName_Impl(); file = pName; } @@ -755,15 +790,15 @@ void SAL_CALL rtl_bootstrap_set ( rtl_uString * pValue ) { - const OUString name( pName ); - const OUString value( pValue ); + const OUString name(pName); + const OUString value(pValue); - osl::MutexGuard guard( osl::Mutex::getGlobalMutex() ); + osl::MutexGuard guard(osl::Mutex::getGlobalMutex()); NameValueList& r_rtl_bootstrap_set_list = rtl_bootstrap_set_list::get(); - NameValueList::iterator iPos( r_rtl_bootstrap_set_list.begin() ); - NameValueList::iterator iEnd( r_rtl_bootstrap_set_list.end() ); - for ( ; iPos != iEnd; ++iPos ) + NameValueList::iterator iPos(r_rtl_bootstrap_set_list.begin()); + NameValueList::iterator iEnd(r_rtl_bootstrap_set_list.end()); + for (; iPos != iEnd; ++iPos) { if (iPos->sName == name) { @@ -774,20 +809,20 @@ void SAL_CALL rtl_bootstrap_set ( SAL_INFO("sal.bootstrap", "explicitly getting: name=" << name << " value=" <<value); - r_rtl_bootstrap_set_list.push_back( rtl_bootstrap_NameValue( name, value ) ); + r_rtl_bootstrap_set_list.push_back(rtl_bootstrap_NameValue(name, value)); } void SAL_CALL rtl_bootstrap_expandMacros_from_handle( rtlBootstrapHandle handle, rtl_uString ** macro) { - if (handle == nullptr) { + if (!handle) handle = get_static_bootstrap_handle(); - } - OUString expanded( expandMacros( static_cast< Bootstrap_Impl * >( handle ), - OUString::unacquired( macro ), - LOOKUP_MODE_NORMAL, nullptr ) ); - rtl_uString_assign( macro, expanded.pData ); + + OUString expanded(expandMacros(static_cast< Bootstrap_Impl * >(handle), + OUString::unacquired(macro), + LOOKUP_MODE_NORMAL, nullptr)); + rtl_uString_assign(macro, expanded.pData); } void SAL_CALL rtl_bootstrap_expandMacros(rtl_uString ** macro) @@ -795,34 +830,38 @@ void SAL_CALL rtl_bootstrap_expandMacros(rtl_uString ** macro) rtl_bootstrap_expandMacros_from_handle(nullptr, macro); } -void rtl_bootstrap_encode( rtl_uString const * value, rtl_uString ** encoded ) +void rtl_bootstrap_encode(rtl_uString const * value, rtl_uString ** encoded) { - OSL_ASSERT(value != nullptr); + OSL_ASSERT(value); rtl::OUStringBuffer b; - for (sal_Int32 i = 0; i < value->length; ++i) { + for (sal_Int32 i = 0; i < value->length; ++i) + { sal_Unicode c = value->buffer[i]; - if (c == '$' || c == '\\') { + if (c == '$' || c == '\\') b.append('\\'); - } + b.append(c); } + rtl_uString_assign(encoded, b.makeStringAndClear().pData); } namespace { -int hex(sal_Unicode c) { +int hex(sal_Unicode c) +{ return c >= '0' && c <= '9' ? c - '0' : c >= 'A' && c <= 'F' ? c - 'A' + 10 : c >= 'a' && c <= 'f' ? c - 'a' + 10 : -1; } -sal_Unicode read(rtl::OUString const & text, sal_Int32 * pos, bool * escaped) { - OSL_ASSERT( - pos != nullptr && *pos >= 0 && *pos < text.getLength() && escaped != nullptr); +sal_Unicode read(rtl::OUString const & text, sal_Int32 * pos, bool * escaped) +{ + OSL_ASSERT(pos && *pos >= 0 && *pos < text.getLength() && escaped); sal_Unicode c = text[(*pos)++]; - if (c == '\\') { + if (c == '\\') + { int n1, n2, n3, n4; if (*pos < text.getLength() - 4 && text[*pos] == 'u' && ((n1 = hex(text[*pos + 1])) >= 0) && @@ -835,11 +874,14 @@ sal_Unicode read(rtl::OUString const & text, sal_Int32 * pos, bool * escaped) { return static_cast< sal_Unicode >( (n1 << 12) | (n2 << 8) | (n3 << 4) | n4); } - if (*pos < text.getLength()) { + + if (*pos < text.getLength()) + { *escaped = true; return text[(*pos)++]; } } + *escaped = false; return c; } @@ -860,69 +902,94 @@ rtl::OUString expandMacros( { SAL_INFO("sal.bootstrap", "expandMacros called with: " << text); rtl::OUStringBuffer buf; - for (sal_Int32 i = 0; i < text.getLength();) { + + for (sal_Int32 i = 0; i < text.getLength();) + { bool escaped; sal_Unicode c = read(text, &i, &escaped); - if (escaped || c != '$') { + if (escaped || c != '$') + { buf.append(c); - } else { - if (i < text.getLength() && text[i] == '{') { + } + else + { + if (i < text.getLength() && text[i] == '{') + { ++i; sal_Int32 p = i; sal_Int32 nesting = 0; rtl::OUString seg[3]; int n = 0; - while (i < text.getLength()) { + + while (i < text.getLength()) + { sal_Int32 j = i; c = read(text, &i, &escaped); - if (!escaped) { - switch (c) { - case '{': - ++nesting; - break; - case '}': - if (nesting == 0) { - seg[n++] = text.copy(p, j - p); - goto done; - } else { - --nesting; - } - break; - case ':': - if (nesting == 0 && n < 2) { - seg[n++] = text.copy(p, j - p); - p = i; - } - break; + + if (!escaped) + { + switch (c) + { + case '{': + ++nesting; + break; + case '}': + if (nesting == 0) + { + seg[n++] = text.copy(p, j - p); + goto done; + } + else + { + --nesting; + } + break; + case ':': + if (nesting == 0 && n < 2) + { + seg[n++] = text.copy(p, j - p); + p = i; + } + break; } } } done: - for (int j = 0; j < n; ++j) { + for (int j = 0; j < n; ++j) + { seg[j] = expandMacros(file, seg[j], mode, requestStack); } - if (n == 1) { + + if (n == 1) + { buf.append(lookup(file, mode, false, seg[0], requestStack)); - } else if (n == 3 && seg[0] == ".override") { + } + else if (n == 3 && seg[0] == ".override") + { rtl::Bootstrap b(seg[1]); - Bootstrap_Impl * f = static_cast< Bootstrap_Impl * >( - b.getHandle()); - buf.append( - lookup(f, mode, f != nullptr, seg[2], requestStack)); - } else { - if (n == 3 && seg[1].isEmpty()) { + Bootstrap_Impl * f = static_cast< Bootstrap_Impl * >(b.getHandle()); + buf.append(lookup(f, mode, f != nullptr, seg[2], requestStack)); + } + else + { + if (n == 3 && seg[1].isEmpty()) + { // For backward compatibility, treat ${file::key} the // same as just ${file:key}: seg[1] = seg[2]; n = 2; } - if (n == 2) { + + if (n == 2) + { buf.append( lookup( static_cast< Bootstrap_Impl * >( rtl::Bootstrap(seg[0]).getHandle()), mode, false, seg[1], requestStack)); - } else { + } + else + { // Going through osl::Profile, this code erroneously // does not recursively expand macros in the resulting // replacement text (and if it did, it would fail to @@ -938,9 +1005,12 @@ rtl::OUString expandMacros( RTL_TEXTENCODING_UTF8)); } } - } else { + } + else + { rtl::OUStringBuffer kbuf; - for (; i < text.getLength();) { + for (; i < text.getLength();) + { sal_Int32 j = i; c = read(text, &j, &escaped); if (!escaped && @@ -949,9 +1019,11 @@ rtl::OUString expandMacros( { break; } + kbuf.append(c); i = j; } + buf.append( lookup( file, mode, false, kbuf.makeStringAndClear(), @@ -959,8 +1031,10 @@ rtl::OUString expandMacros( } } } + OUString result(buf.makeStringAndClear()); SAL_INFO("sal.bootstrap", "expandMacros result: " << result); + return result; } commit b714ba73cf2b08ea252a039d801c8dccb1337049 Author: Chris Sherlock <chris.sherloc...@gmail.com> Date: Sat Jul 22 22:25:52 2017 +1000 rtl: remove comparisons against nullptr from RTL mem files Change-Id: Ic0ae0378d5b46b3d11c99aef2e845796ad0a9c71 diff --git a/sal/rtl/alloc_arena.cxx b/sal/rtl/alloc_arena.cxx index 0e4aed5e2a31..7baa46f0cf36 100644 --- a/sal/rtl/alloc_arena.cxx +++ b/sal/rtl/alloc_arena.cxx @@ -100,7 +100,7 @@ bool rtl_arena_segment_populate(rtl_arena_type * arena) span = static_cast< rtl_arena_segment_type * >( rtl_machdep_alloc(gp_machdep_arena, &size)); - if (span != nullptr) + if (span) { rtl_arena_segment_type *first, *last, *head; sal_Size count = size / sizeof(rtl_arena_segment_type); @@ -137,7 +137,7 @@ inline void rtl_arena_segment_get( { rtl_arena_segment_type * head; - assert(*ppSegment == nullptr); + assert(!*ppSegment); head = &(arena->m_segment_reserve_head); if ((head->m_snext != head) || rtl_arena_segment_populate (arena)) @@ -234,7 +234,7 @@ void rtl_arena_hash_rescale( new_bytes = new_size * sizeof(rtl_arena_segment_type*); new_table = static_cast<rtl_arena_segment_type **>(rtl_arena_alloc (gp_arena_arena, &new_bytes)); - if (new_table != nullptr) + if (new_table) { rtl_arena_segment_type ** old_table; sal_Size old_size, i; @@ -253,7 +253,7 @@ void rtl_arena_hash_rescale( for (i = 0; i < old_size; i++) { rtl_arena_segment_type * curr = old_table[i]; - while (curr != nullptr) + while (curr) { rtl_arena_segment_type * next = curr->m_fnext; rtl_arena_segment_type ** head; @@ -310,7 +310,7 @@ rtl_arena_segment_type * rtl_arena_hash_remove( sal_Size lookups = 0; segpp = &(arena->m_hash_table[RTL_ARENA_HASH_INDEX(arena, addr)]); - while ((segment = *segpp) != nullptr) + while ((segment = *segpp)) { if (segment->m_addr == addr) { @@ -324,8 +324,8 @@ rtl_arena_segment_type * rtl_arena_hash_remove( segpp = &(segment->m_fnext); } - assert(segment != nullptr); // bad free - if (segment != nullptr) + assert(segment); // bad free + if (segment) { assert(segment->m_size == size); (void) size; // avoid warnings @@ -371,7 +371,7 @@ bool rtl_arena_segment_alloc( { int index = 0; - assert(*ppSegment == nullptr); + assert(!*ppSegment); if (!RTL_MEMORY_ISP2(size)) { unsigned int msb = highbit(size); @@ -409,7 +409,7 @@ bool rtl_arena_segment_alloc( } dequeue_and_leave: - if (*ppSegment != nullptr) + if (*ppSegment) { /* remove from freelist */ rtl_arena_freelist_remove (arena, (*ppSegment)); @@ -429,15 +429,15 @@ int rtl_arena_segment_create( rtl_arena_segment_type ** ppSegment ) { - assert((*ppSegment) == nullptr); - if (arena->m_source_alloc != nullptr) + assert(!*ppSegment); + if (arena->m_source_alloc) { rtl_arena_segment_get (arena, ppSegment); - if (*ppSegment != nullptr) + if (*ppSegment) { rtl_arena_segment_type * span = nullptr; rtl_arena_segment_get (arena, &span); - if (span != nullptr) + if (span) { /* import new span from source arena */ RTL_MEMORY_LOCK_RELEASE(&(arena->m_lock)); @@ -613,8 +613,8 @@ rtl_arena_type * rtl_arena_activate( void (SAL_CALL * source_free) (rtl_arena_type *, void *, sal_Size) ) { - assert(arena != nullptr); - if (arena != nullptr) + assert(arena); + if (arena) { (void) snprintf (arena->m_name, sizeof(arena->m_name), "%s", name); @@ -674,15 +674,15 @@ void rtl_arena_deactivate(rtl_arena_type * arena) RTL_MEMORY_LOCK_RELEASE(&(g_arena_list.m_lock)); /* cleanup quantum cache(s) */ - if ((arena->m_qcache_max > 0) && (arena->m_qcache_ptr != nullptr)) + if ((arena->m_qcache_max > 0) && (arena->m_qcache_ptr)) { int i, n = (arena->m_qcache_max >> arena->m_quantum_shift); for (i = 1; i <= n; i++) { - if (arena->m_qcache_ptr[i - 1] != nullptr) + if (arena->m_qcache_ptr[i-1]) { - rtl_cache_destroy (arena->m_qcache_ptr[i - 1]); - arena->m_qcache_ptr[i - 1] = nullptr; + rtl_cache_destroy (arena->m_qcache_ptr[i-1]); + arena->m_qcache_ptr[i-1] = nullptr; } } rtl_arena_free ( @@ -701,7 +701,7 @@ void rtl_arena_deactivate(rtl_arena_type * arena) /* cleanup still used segment(s) */ for (i = 0, n = arena->m_hash_size; i < n; i++) { - while ((segment = arena->m_hash_table[i]) != nullptr) + while ((segment = arena->m_hash_table[i])) { /* pop from hash table */ arena->m_hash_table[i] = segment->m_fnext; @@ -791,14 +791,14 @@ rtl_arena_type * SAL_CALL rtl_arena_create( try_alloc: result = static_cast<rtl_arena_type*>(rtl_arena_alloc (gp_arena_arena, &size)); - if (result != nullptr) + if (result) { rtl_arena_type * arena = result; rtl_arena_constructor (arena); if (!source_arena) { - assert(gp_default_arena != nullptr); + assert(gp_default_arena); source_arena = gp_default_arena; } @@ -812,14 +812,14 @@ try_alloc: source_free ); - if (result == nullptr) + if (!result) { rtl_arena_deactivate (arena); rtl_arena_destructor (arena); rtl_arena_free (gp_arena_arena, arena, size); } } - else if (gp_arena_arena == nullptr) + else if (!gp_arena_arena) { ensureArenaSingleton(); if (gp_arena_arena) @@ -833,7 +833,7 @@ try_alloc: void SAL_CALL rtl_arena_destroy(rtl_arena_type * arena) SAL_THROW_EXTERN_C() { - if (arena != nullptr) + if (arena) { rtl_arena_deactivate (arena); rtl_arena_destructor (arena); @@ -848,7 +848,7 @@ void * SAL_CALL rtl_arena_alloc( { void * addr = nullptr; - if ((arena != nullptr) && (pSize != nullptr)) + if (arena && pSize) { sal_Size size; @@ -876,7 +876,7 @@ void * SAL_CALL rtl_arena_alloc( { rtl_arena_segment_type * remainder = nullptr; rtl_arena_segment_get (arena, &remainder); - if (remainder != nullptr) + if (remainder) { segment->m_size = size; @@ -900,10 +900,10 @@ void * SAL_CALL rtl_arena_alloc( { /* allocate from quantum cache(s) */ int index = (size >> arena->m_quantum_shift) - 1; - assert(arena->m_qcache_ptr[index] != nullptr); + assert(arena->m_qcache_ptr[index]); addr = rtl_cache_alloc (arena->m_qcache_ptr[index]); - if (addr != nullptr) + if (addr) (*pSize) = size; } } @@ -916,7 +916,7 @@ void SAL_CALL rtl_arena_free ( sal_Size size ) SAL_THROW_EXTERN_C() { - if (arena != nullptr) + if (arena) { size = RTL_MEMORY_ALIGN(size, arena->m_quantum); if (size > arena->m_qcache_max) @@ -927,7 +927,7 @@ void SAL_CALL rtl_arena_free ( RTL_MEMORY_LOCK_ACQUIRE(&(arena->m_lock)); segment = rtl_arena_hash_remove (arena, reinterpret_cast<sal_uIntPtr>(addr), size); - if (segment != nullptr) + if (segment) { rtl_arena_segment_type *next, *prev; @@ -983,7 +983,7 @@ void SAL_CALL rtl_arena_free ( { /* free to quantum cache(s) */ int index = (size >> arena->m_quantum_shift) - 1; - assert(arena->m_qcache_ptr[index] != nullptr); + assert(arena->m_qcache_ptr[index]); rtl_cache_free (arena->m_qcache_ptr[index], addr); } @@ -1096,7 +1096,7 @@ void rtl_arena_init() /* machdep (pseudo) arena */ static rtl_arena_type g_machdep_arena; - assert(gp_machdep_arena == nullptr); + assert(!gp_machdep_arena); rtl_arena_constructor (&g_machdep_arena); gp_machdep_arena = rtl_arena_activate ( @@ -1106,13 +1106,13 @@ void rtl_arena_init() 0, /* no quantum caching */ nullptr, nullptr, nullptr /* no source */ ); - assert(gp_machdep_arena != nullptr); + assert(gp_machdep_arena); } { /* default arena */ static rtl_arena_type g_default_arena; - assert(gp_default_arena == nullptr); + assert(!gp_default_arena); rtl_arena_constructor (&g_default_arena); gp_default_arena = rtl_arena_activate ( @@ -1124,13 +1124,13 @@ void rtl_arena_init() rtl_machdep_alloc, rtl_machdep_free ); - assert(gp_default_arena != nullptr); + assert(gp_default_arena); } { /* arena internal arena */ static rtl_arena_type g_arena_arena; - assert(gp_arena_arena == nullptr); + assert(!gp_arena_arena); rtl_arena_constructor (&g_arena_arena); gp_arena_arena = rtl_arena_activate( @@ -1142,13 +1142,13 @@ void rtl_arena_init() rtl_arena_alloc, rtl_arena_free ); - assert(gp_arena_arena != nullptr); + assert(gp_arena_arena); } } void rtl_arena_fini() { - if (gp_arena_arena != nullptr) + if (gp_arena_arena) { rtl_arena_type * arena, * head; diff --git a/sal/rtl/alloc_cache.cxx b/sal/rtl/alloc_cache.cxx index 4dfa1eb966c4..04a982d99bc9 100644 --- a/sal/rtl/alloc_cache.cxx +++ b/sal/rtl/alloc_cache.cxx @@ -94,7 +94,7 @@ void rtl_cache_hash_rescale( new_bytes = new_size * sizeof(rtl_cache_bufctl_type*); new_table = static_cast<rtl_cache_bufctl_type**>(rtl_arena_alloc(gp_cache_arena, &new_bytes)); - if (new_table != nullptr) + if (new_table) { rtl_cache_bufctl_type ** old_table; sal_Size old_size, i; @@ -115,7 +115,7 @@ void rtl_cache_hash_rescale( for (i = 0; i < old_size; i++) { rtl_cache_bufctl_type * curr = old_table[i]; - while (curr != nullptr) + while (curr) { rtl_cache_bufctl_type * next = curr->m_next; rtl_cache_bufctl_type ** head; @@ -164,7 +164,7 @@ rtl_cache_bufctl_type * rtl_cache_hash_remove( sal_Size lookups = 0; ppHead = &(cache->m_hash_table[RTL_CACHE_HASH_INDEX(cache, addr)]); - while ((bufctl = *ppHead) != nullptr) + while ((bufctl = *ppHead)) { if (bufctl->m_addr == addr) { @@ -177,7 +177,7 @@ rtl_cache_bufctl_type * rtl_cache_hash_remove( ppHead = &(bufctl->m_next); } - assert(bufctl != nullptr); // bad free + assert(bufctl); // bad free if (lookups > 1) { @@ -235,7 +235,7 @@ rtl_cache_slab_type * rtl_cache_slab_create(rtl_cache_type * cache) size = cache->m_slab_size; addr = rtl_arena_alloc (cache->m_source, &size); - if (SAL_LIKELY(addr != nullptr)) + if (SAL_LIKELY(addr)) { assert(size >= cache->m_slab_size); @@ -251,7 +251,7 @@ rtl_cache_slab_type * rtl_cache_slab_create(rtl_cache_type * cache) slab = RTL_CACHE_SLAB(addr, cache->m_slab_size); (void) rtl_cache_slab_constructor (slab, nullptr); } - if (SAL_LIKELY(slab != nullptr)) + if (SAL_LIKELY(slab)) { slab->m_data = reinterpret_cast<sal_uIntPtr>(addr); @@ -282,7 +282,7 @@ void rtl_cache_slab_destroy( { /* cleanup bufctl(s) for free buffer(s) */ sal_Size ntypes = (slab->m_bp - slab->m_data) / cache->m_type_size; - for (ntypes -= refcnt; slab->m_sp != nullptr; ntypes--) + for (ntypes -= refcnt; slab->m_sp; ntypes--) { rtl_cache_bufctl_type * bufctl = slab->m_sp; @@ -321,7 +321,7 @@ bool rtl_cache_slab_populate(rtl_cache_type * cache) RTL_MEMORY_LOCK_RELEASE(&(cache->m_slab_lock)); slab = rtl_cache_slab_create (cache); RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_slab_lock)); - if (slab != nullptr) + if (slab) { /* update buffer start addr w/ current color */ slab->m_bp += cache->m_ncolor; @@ -359,7 +359,7 @@ void * rtl_cache_slab_alloc (rtl_cache_type * cache) slab = head->m_slab_next; assert(slab->m_ntypes < cache->m_ntypes); - if (slab->m_sp == nullptr) + if (!slab->m_sp) { /* initialize bufctl w/ current 'slab->m_bp' */ assert(slab->m_bp < slab->m_data + cache->m_ntypes * cache->m_type_size + cache->m_ncolor_max); @@ -368,7 +368,7 @@ void * rtl_cache_slab_alloc (rtl_cache_type * cache) /* allocate bufctl */ assert(cache != gp_cache_bufctl_cache); bufctl = static_cast<rtl_cache_bufctl_type*>(rtl_cache_alloc (gp_cache_bufctl_cache)); - if (bufctl == nullptr) + if (!bufctl) { /* out of memory */ RTL_MEMORY_LOCK_RELEASE(&(cache->m_slab_lock)); @@ -446,7 +446,7 @@ void rtl_cache_slab_free( slab = RTL_CACHE_SLAB(addr, cache->m_slab_size); } - if (slab != nullptr) + if (slab) { /* check for full slab */ if (slab->m_ntypes == cache->m_ntypes) @@ -501,7 +501,7 @@ void rtl_cache_magazine_destructor(void * obj, SAL_UNUSED_PARAMETER void *) { rtl_cache_magazine_type * mag = static_cast< rtl_cache_magazine_type * >( obj); - assert(mag->m_mag_next == nullptr); // assure removed from queue(s) + assert(!mag->m_mag_next); // assure removed from queue(s) assert(mag->m_mag_used == 0); // assure no longer referenced (void) mag; // avoid warnings } @@ -513,10 +513,10 @@ void rtl_cache_magazine_clear( { for (; mag->m_mag_used > 0; --mag->m_mag_used) { - void * obj = mag->m_objects[mag->m_mag_used - 1]; - mag->m_objects[mag->m_mag_used - 1] = nullptr; + void * obj = mag->m_objects[mag->m_mag_used-1]; + mag->m_objects[mag->m_mag_used-1] = nullptr; - if (cache->m_destructor != nullptr) + if (cache->m_destructor) { /* destruct object */ (cache->m_destructor)(obj, cache->m_userarg); @@ -554,7 +554,7 @@ inline rtl_cache_magazine_type * rtl_cache_depot_dequeue( if (depot->m_mag_count > 0) { /* dequeue magazine */ - assert(depot->m_mag_next != nullptr); + assert(depot->m_mag_next); mag = depot->m_mag_next; depot->m_mag_next = mag->m_mag_next; @@ -580,17 +580,17 @@ inline rtl_cache_magazine_type * rtl_cache_depot_exchange_alloc( { rtl_cache_magazine_type * full; - assert((empty == nullptr) || (empty->m_mag_used == 0)); + assert((!empty) || (empty->m_mag_used == 0)); /* dequeue full magazine */ full = rtl_cache_depot_dequeue (&(cache->m_depot_full)); - if ((full != nullptr) && (empty != nullptr)) + if (full && empty) { /* enqueue empty magazine */ rtl_cache_depot_enqueue (&(cache->m_depot_empty), empty); } - assert((full == nullptr) || (full->m_mag_used > 0)); + assert(!full || (full->m_mag_used > 0)); return full; } @@ -605,17 +605,17 @@ inline rtl_cache_magazine_type * rtl_cache_depot_exchange_free( { rtl_cache_magazine_type * empty; - assert((full == nullptr) || (full->m_mag_used > 0)); + assert(!full || (full->m_mag_used > 0)); /* dequeue empty magazine */ empty = rtl_cache_depot_dequeue (&(cache->m_depot_empty)); - if ((empty != nullptr) && (full != nullptr)) + if (empty && full) { /* enqueue full magazine */ rtl_cache_depot_enqueue (&(cache->m_depot_full), full); } - assert((empty == nullptr) || (empty->m_mag_used == 0)); + assert(!empty || (empty->m_mag_used == 0)); return empty; } @@ -627,13 +627,13 @@ bool rtl_cache_depot_populate(rtl_cache_type * cache) { rtl_cache_magazine_type * empty = nullptr; - if (cache->m_magazine_cache != nullptr) + if (cache->m_magazine_cache) { /* allocate new empty magazine */ RTL_MEMORY_LOCK_RELEASE(&(cache->m_depot_lock)); empty = static_cast<rtl_cache_magazine_type*>(rtl_cache_alloc (cache->m_magazine_cache)); RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_depot_lock)); - if (empty != nullptr) + if (empty) { /* enqueue (new) empty magazine */ rtl_cache_depot_enqueue (&(cache->m_depot_empty), empty); @@ -700,8 +700,8 @@ rtl_cache_type * rtl_cache_activate( int flags ) { - assert(cache != nullptr); - if (cache != nullptr) + assert(cache); + if (cache) { sal_Size slabsize; @@ -767,8 +767,8 @@ rtl_cache_type * rtl_cache_activate( if (cache->m_slab_size > source->m_quantum) { - assert(gp_cache_slab_cache != nullptr); - assert(gp_cache_bufctl_cache != nullptr); + assert(gp_cache_slab_cache); + assert(gp_cache_bufctl_cache); cache->m_features |= RTL_CACHE_FEATURE_HASH; cache->m_ntypes = cache->m_slab_size / cache->m_type_size; @@ -793,7 +793,7 @@ rtl_cache_type * rtl_cache_activate( /* magazine layer */ if (!(flags & RTL_CACHE_FLAG_NOMAGAZINE)) { - assert(gp_cache_magazine_cache != nullptr); + assert(gp_cache_magazine_cache); cache->m_magazine_cache = gp_cache_magazine_cache; } @@ -817,7 +817,7 @@ void rtl_cache_deactivate(rtl_cache_type * cache) (void)active; /* cleanup magazine layer */ - if (cache->m_magazine_cache != nullptr) + if (cache->m_magazine_cache) { rtl_cache_type * mag_cache; rtl_cache_magazine_type * mag; @@ -827,14 +827,15 @@ void rtl_cache_deactivate(rtl_cache_type * cache) cache->m_magazine_cache = nullptr; /* cleanup cpu layer */ - if ((mag = cache->m_cpu_curr) != nullptr) + if ((mag = cache->m_cpu_curr)) { // coverity[missing_lock] cache->m_cpu_curr = nullptr; rtl_cache_magazine_clear (cache, mag); rtl_cache_free (mag_cache, mag); } - if ((mag = cache->m_cpu_prev) != nullptr) + + if ((mag = cache->m_cpu_prev)) { // coverity[missing_lock] cache->m_cpu_prev = nullptr; @@ -843,12 +844,13 @@ void rtl_cache_deactivate(rtl_cache_type * cache) } /* cleanup depot layer */ - while ((mag = rtl_cache_depot_dequeue(&(cache->m_depot_full))) != nullptr) + while ((mag = rtl_cache_depot_dequeue(&(cache->m_depot_full)))) { rtl_cache_magazine_clear (cache, mag); rtl_cache_free (mag_cache, mag); } - while ((mag = rtl_cache_depot_dequeue(&(cache->m_depot_empty))) != nullptr) + + while ((mag = rtl_cache_depot_dequeue(&(cache->m_depot_empty)))) { rtl_cache_magazine_clear (cache, mag); rtl_cache_free (mag_cache, mag); @@ -865,7 +867,7 @@ void rtl_cache_deactivate(rtl_cache_type * cache) for (i = 0; i < n; i++) { rtl_cache_bufctl_type * bufctl; - while ((bufctl = cache->m_hash_table[i]) != nullptr) + while ((bufctl = cache->m_hash_table[i])) { /* pop from hash table */ cache->m_hash_table[i] = bufctl->m_next; @@ -940,7 +942,7 @@ rtl_cache_type * SAL_CALL rtl_cache_create( try_alloc: result = static_cast<rtl_cache_type*>(rtl_arena_alloc (gp_cache_arena, &size)); - if (result != nullptr) + if (result) { rtl_cache_type * cache = result; (void) rtl_cache_constructor (cache); @@ -948,7 +950,7 @@ try_alloc: if (!source) { /* use default arena */ - assert(gp_default_arena != nullptr); + assert(gp_default_arena); source = gp_default_arena; } @@ -964,7 +966,7 @@ try_alloc: flags ); - if (result == nullptr) + if (!result) { /* activation failed */ rtl_cache_deactivate (cache); @@ -972,7 +974,7 @@ try_alloc: rtl_arena_free (gp_cache_arena, cache, size); } } - else if (gp_cache_arena == nullptr) + else if (!gp_cache_arena) { ensureCacheSingleton(); if (gp_cache_arena) @@ -986,7 +988,7 @@ try_alloc: void SAL_CALL rtl_cache_destroy(rtl_cache_type * cache) SAL_THROW_EXTERN_C() { - if (cache != nullptr) + if (cache) { rtl_cache_deactivate (cache); rtl_cache_destructor (cache); @@ -998,15 +1000,15 @@ void * SAL_CALL rtl_cache_alloc(rtl_cache_type * cache) SAL_THROW_EXTERN_C() { void * obj = nullptr; - if (cache == nullptr) + if (!cache) return nullptr; if (alloc_mode == AllocMode::SYSTEM) { obj = rtl_allocateMemory(cache->m_type_size); - if ((obj != nullptr) && (cache->m_constructor != nullptr)) + if (obj && cache->m_constructor) { - if (!((cache->m_constructor)(obj, cache->m_userarg))) + if (!(cache->m_constructor)(obj, cache->m_userarg)) { /* construction failure */ rtl_freeMemory(obj); @@ -1017,7 +1019,7 @@ void * SAL_CALL rtl_cache_alloc(rtl_cache_type * cache) SAL_THROW_EXTERN_C() } RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_depot_lock)); - if (SAL_LIKELY(cache->m_cpu_curr != nullptr)) + if (SAL_LIKELY(cache->m_cpu_curr)) { for (;;) { @@ -1025,7 +1027,7 @@ void * SAL_CALL rtl_cache_alloc(rtl_cache_type * cache) SAL_THROW_EXTERN_C() rtl_cache_magazine_type *curr, *prev, *temp; curr = cache->m_cpu_curr; - if ((curr != nullptr) && (curr->m_mag_used > 0)) + if (curr && (curr->m_mag_used > 0)) { obj = curr->m_objects[--curr->m_mag_used]; cache->m_cpu_stats.m_alloc += 1; @@ -1035,7 +1037,7 @@ void * SAL_CALL rtl_cache_alloc(rtl_cache_type * cache) SAL_THROW_EXTERN_C() } prev = cache->m_cpu_prev; - if ((prev != nullptr) && (prev->m_mag_used > 0)) + if (prev && (prev->m_mag_used > 0)) { temp = cache->m_cpu_curr; cache->m_cpu_curr = cache->m_cpu_prev; @@ -1045,7 +1047,7 @@ void * SAL_CALL rtl_cache_alloc(rtl_cache_type * cache) SAL_THROW_EXTERN_C() } temp = rtl_cache_depot_exchange_alloc (cache, prev); - if (temp != nullptr) + if (temp) { cache->m_cpu_prev = cache->m_cpu_curr; cache->m_cpu_curr = temp; @@ -1061,10 +1063,10 @@ void * SAL_CALL rtl_cache_alloc(rtl_cache_type * cache) SAL_THROW_EXTERN_C() /* alloc buffer from slab layer */ obj = rtl_cache_slab_alloc (cache); - if ((obj != nullptr) && (cache->m_constructor != nullptr)) + if (obj && (cache->m_constructor)) { /* construct object */ - if (!((cache->m_constructor)(obj, cache->m_userarg))) + if (!(cache->m_constructor)(obj, cache->m_userarg)) { /* construction failure */ rtl_cache_slab_free (cache, obj); @@ -1079,11 +1081,11 @@ void SAL_CALL rtl_cache_free( void * obj ) SAL_THROW_EXTERN_C() { - if ((obj != nullptr) && (cache != nullptr)) + if (obj && cache) { if (alloc_mode == AllocMode::SYSTEM) { - if (cache->m_destructor != nullptr) + if (cache->m_destructor) { /* destruct object */ (cache->m_destructor)(obj, cache->m_userarg); @@ -1100,7 +1102,7 @@ void SAL_CALL rtl_cache_free( rtl_cache_magazine_type *curr, *prev, *temp; curr = cache->m_cpu_curr; - if ((curr != nullptr) && (curr->m_mag_used < curr->m_mag_size)) + if (curr && (curr->m_mag_used < curr->m_mag_size)) { curr->m_objects[curr->m_mag_used++] = obj; cache->m_cpu_stats.m_free += 1; @@ -1110,7 +1112,7 @@ void SAL_CALL rtl_cache_free( } prev = cache->m_cpu_prev; - if ((prev != nullptr) && (prev->m_mag_used == 0)) + if (prev && (prev->m_mag_used == 0)) { temp = cache->m_cpu_curr; cache->m_cpu_curr = cache->m_cpu_prev; @@ -1120,7 +1122,7 @@ void SAL_CALL rtl_cache_free( } temp = rtl_cache_depot_exchange_free (cache, prev); - if (temp != nullptr) + if (temp) { cache->m_cpu_prev = cache->m_cpu_curr; cache->m_cpu_curr = temp; @@ -1140,7 +1142,7 @@ void SAL_CALL rtl_cache_free( RTL_MEMORY_LOCK_RELEASE(&(cache->m_depot_lock)); /* no space for constructed object in magazine layer */ - if (cache->m_destructor != nullptr) + if (cache->m_destructor) { /* destruct object */ (cache->m_destructor)(obj, cache->m_userarg); @@ -1269,7 +1271,7 @@ static void rtl_cache_depot_wsupdate( for (; npurge > 0; npurge--) { rtl_cache_magazine_type * mag = rtl_cache_depot_dequeue (depot); - if (mag != nullptr) + if (mag) { RTL_MEMORY_LOCK_RELEASE(&(cache->m_depot_lock)); rtl_cache_magazine_clear (cache, mag); @@ -1285,7 +1287,7 @@ static void rtl_cache_depot_wsupdate( */ static void rtl_cache_wsupdate(rtl_cache_type * cache) { - if (cache->m_magazine_cache != nullptr) + if (cache->m_magazine_cache) { RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_depot_lock)); @@ -1342,7 +1344,7 @@ void rtl_cache_init() } { /* cache: internal arena */ - assert(gp_cache_arena == nullptr); + assert(!gp_cache_arena); gp_cache_arena = rtl_arena_create ( "rtl_cache_internal_arena", @@ -1353,16 +1355,16 @@ void rtl_cache_init() rtl_arena_free, 0 /* flags */ ); - assert(gp_cache_arena != nullptr); + assert(gp_cache_arena); /* check 'gp_default_arena' initialization */ - assert(gp_default_arena != nullptr); + assert(gp_default_arena); } { /* cache: magazine cache */ static rtl_cache_type g_cache_magazine_cache; - assert(gp_cache_magazine_cache == nullptr); + assert(!gp_cache_magazine_cache); (void) rtl_cache_constructor (&g_cache_magazine_cache); gp_cache_magazine_cache = rtl_cache_activate ( @@ -1376,7 +1378,7 @@ void rtl_cache_init() gp_default_arena, /* source */ RTL_CACHE_FLAG_NOMAGAZINE /* during bootstrap; activated below */ ); - assert(gp_cache_magazine_cache != nullptr); + assert(gp_cache_magazine_cache); /* activate magazine layer */ g_cache_magazine_cache.m_magazine_cache = gp_cache_magazine_cache; @@ -1385,7 +1387,7 @@ void rtl_cache_init() /* cache: slab (struct) cache */ static rtl_cache_type g_cache_slab_cache; - assert(gp_cache_slab_cache == nullptr); + assert(!gp_cache_slab_cache); (void) rtl_cache_constructor (&g_cache_slab_cache); gp_cache_slab_cache = rtl_cache_activate ( @@ -1399,13 +1401,13 @@ void rtl_cache_init() gp_default_arena, /* source */ 0 /* flags: none */ ); - assert(gp_cache_slab_cache != nullptr); + assert(gp_cache_slab_cache); } { /* cache: bufctl cache */ static rtl_cache_type g_cache_bufctl_cache; - assert(gp_cache_bufctl_cache == nullptr); + assert(!gp_cache_bufctl_cache); (void) rtl_cache_constructor (&g_cache_bufctl_cache); gp_cache_bufctl_cache = rtl_cache_activate ( @@ -1419,7 +1421,7 @@ void rtl_cache_init() gp_default_arena, /* source */ 0 /* flags: none */ ); - assert(gp_cache_bufctl_cache != nullptr); + assert(gp_cache_bufctl_cache); } rtl_cache_wsupdate_init(); @@ -1427,34 +1429,37 @@ void rtl_cache_init() void rtl_cache_fini() { - if (gp_cache_arena != nullptr) + if (gp_cache_arena) { rtl_cache_type * cache, * head; rtl_cache_wsupdate_fini(); - if (gp_cache_bufctl_cache != nullptr) + if (gp_cache_bufctl_cache) { cache = gp_cache_bufctl_cache; gp_cache_bufctl_cache = nullptr; rtl_cache_deactivate (cache); rtl_cache_destructor (cache); } - if (gp_cache_slab_cache != nullptr) + + if (gp_cache_slab_cache) { cache = gp_cache_slab_cache; gp_cache_slab_cache = nullptr; rtl_cache_deactivate (cache); rtl_cache_destructor (cache); } - if (gp_cache_magazine_cache != nullptr) + + if (gp_cache_magazine_cache) { cache = gp_cache_magazine_cache; gp_cache_magazine_cache = nullptr; rtl_cache_deactivate (cache); rtl_cache_destructor (cache); } - if (gp_cache_arena != nullptr) + + if (gp_cache_arena) { rtl_arena_destroy (gp_cache_arena); gp_cache_arena = nullptr; diff --git a/sal/rtl/alloc_global.cxx b/sal/rtl/alloc_global.cxx index a16550589960..b0d3adbf928a 100644 --- a/sal/rtl/alloc_global.cxx +++ b/sal/rtl/alloc_global.cxx @@ -93,12 +93,12 @@ try_alloc: else addr = static_cast<char*>(rtl_arena_alloc (gp_alloc_arena, &size)); - if (addr != nullptr) + if (addr) { reinterpret_cast<sal_Size*>(addr)[0] = size; p = addr + RTL_MEMALIGN; } - else if (gp_alloc_arena == nullptr) + else if (!gp_alloc_arena) { ensureMemorySingleton(); if (gp_alloc_arena) @@ -113,7 +113,7 @@ try_alloc: void SAL_CALL rtl_freeMemory_CUSTOM (void * p) SAL_THROW_EXTERN_C() { - if (p != nullptr) + if (p) { char * addr = static_cast<char*>(p) - RTL_MEMALIGN; sal_Size size = reinterpret_cast<sal_Size*>(addr)[0]; @@ -129,13 +129,13 @@ void * SAL_CALL rtl_reallocateMemory_CUSTOM (void * p, sal_Size n) SAL_THROW_EXT { if (n > 0) { - if (p != nullptr) + if (p) { void * p_old = p; sal_Size n_old = reinterpret_cast<sal_Size*>( static_cast<char*>(p) - RTL_MEMALIGN )[0] - RTL_MEMALIGN; p = rtl_allocateMemory (n); - if (p != nullptr) + if (p) { memcpy (p, p_old, (n < n_old) ? n : n_old); rtl_freeMemory (p_old); @@ -146,7 +146,7 @@ void * SAL_CALL rtl_reallocateMemory_CUSTOM (void * p, sal_Size n) SAL_THROW_EXT p = rtl_allocateMemory (n); } } - else if (p != nullptr) + else if (p) { rtl_freeMemory (p); p = nullptr; @@ -161,7 +161,7 @@ void rtl_memory_init() #if !defined(FORCE_SYSALLOC) { /* global memory arena */ - assert(gp_alloc_arena == nullptr); + assert(!gp_alloc_arena); gp_alloc_arena = rtl_arena_create ( "rtl_alloc_arena", @@ -172,7 +172,7 @@ void rtl_memory_init() rtl_arena_free, 0 /* flags */ ); - assert(gp_alloc_arena != nullptr); + assert(gp_alloc_arena); } { sal_Size size; @@ -210,7 +210,7 @@ void rtl_memory_fini() /* cleanup g_alloc_caches */ for (i = 0, n = RTL_MEMORY_CACHED_SIZES; i < n; i++) { - if (g_alloc_caches[i] != nullptr) + if (g_alloc_caches[i]) { rtl_cache_destroy (g_alloc_caches[i]); g_alloc_caches[i] = nullptr; @@ -218,7 +218,7 @@ void rtl_memory_fini() } /* cleanup gp_alloc_arena */ - if (gp_alloc_arena != nullptr) + if (gp_alloc_arena) { rtl_arena_destroy (gp_alloc_arena); gp_alloc_arena = nullptr; @@ -312,14 +312,14 @@ void SAL_CALL rtl_freeMemory(void * p) SAL_THROW_EXTERN_C() void * SAL_CALL rtl_allocateZeroMemory(sal_Size n) SAL_THROW_EXTERN_C() { void * p = rtl_allocateMemory (n); - if (p != nullptr) + if (p) memset (p, 0, n); return p; } void SAL_CALL rtl_freeZeroMemory(void * p, sal_Size n) SAL_THROW_EXTERN_C() { - if (p != nullptr) + if (p) { rtl_secureZeroMemory (p, n); rtl_freeMemory (p); commit e29ee03d1aff5fd8ff2a2af01f49bc036e612f6e Author: Chris Sherlock <chris.sherloc...@gmail.com> Date: Sat Jul 22 22:07:41 2017 +1000 rtl: remove comment cruft from alloc files Change-Id: Ibac120af6879739091aacefef5c773649e222f85 diff --git a/sal/rtl/alloc_arena.cxx b/sal/rtl/alloc_arena.cxx index a0b16d57ec83..0e4aed5e2a31 100644 --- a/sal/rtl/alloc_arena.cxx +++ b/sal/rtl/alloc_arena.cxx @@ -27,15 +27,9 @@ #include <string.h> #include <stdio.h> -/* ================================================================= * - * - * arena internals. - * - * ================================================================= */ - -/** g_arena_list - * @internal - */ +/** + @internal +*/ struct rtl_arena_list_st { rtl_memory_lock_type m_lock; @@ -44,51 +38,40 @@ struct rtl_arena_list_st static rtl_arena_list_st g_arena_list; -/** gp_arena_arena - * provided for arena_type allocations, and hash_table resizing. - * - * @internal - */ +/** + provided for arena_type allocations, and hash_table resizing. + + @internal +*/ static rtl_arena_type * gp_arena_arena = nullptr; -/** gp_machdep_arena - * - * Low level virtual memory (pseudo) arena - * (platform dependent implementation) - * - * @internal +/** + Low level virtual memory (pseudo) arena + (platform dependent implementation) + + @internal */ static rtl_arena_type * gp_machdep_arena = nullptr; -/** gp_default_arena - */ rtl_arena_type * gp_default_arena = nullptr; namespace { -void * -SAL_CALL rtl_machdep_alloc ( +void * SAL_CALL rtl_machdep_alloc( rtl_arena_type * pArena, sal_Size * pSize ); -void -SAL_CALL rtl_machdep_free ( +void SAL_CALL rtl_machdep_free( rtl_arena_type * pArena, void * pAddr, sal_Size nSize ); -sal_Size -rtl_machdep_pagesize(); - -/* ================================================================= */ +sal_Size rtl_machdep_pagesize(); -/** rtl_arena_segment_constructor() - */ -int -rtl_arena_segment_constructor (void * obj) +int rtl_arena_segment_constructor(void * obj) { rtl_arena_segment_type * segment = static_cast<rtl_arena_segment_type*>(obj); @@ -98,10 +81,7 @@ rtl_arena_segment_constructor (void * obj) return 1; } -/** rtl_arena_segment_destructor() - */ -void -rtl_arena_segment_destructor (void * obj) +void rtl_arena_segment_destructor(void * obj) { rtl_arena_segment_type * segment = static_cast< rtl_arena_segment_type * >( obj); @@ -110,16 +90,10 @@ rtl_arena_segment_destructor (void * obj) (void) segment; // avoid warnings } -/* ================================================================= */ - -/** rtl_arena_segment_populate() - * - * @precond arena->m_lock acquired. +/** + @precond arena->m_lock acquired. */ -bool -rtl_arena_segment_populate ( - rtl_arena_type * arena -) +bool rtl_arena_segment_populate(rtl_arena_type * arena) { rtl_arena_segment_type *span; sal_Size size = rtl_machdep_pagesize(); @@ -152,14 +126,12 @@ rtl_arena_segment_populate ( return (span != nullptr); } -/** rtl_arena_segment_get() - * - * @precond arena->m_lock acquired. - * @precond (*ppSegment == 0) - */ -inline void -rtl_arena_segment_get ( - rtl_arena_type * arena, +/** + @precond arena->m_lock acquired. + @precond (*ppSegment == 0) +*/ +inline void rtl_arena_segment_get( + rtl_arena_type * arena, rtl_arena_segment_type ** ppSegment ) { @@ -175,14 +147,12 @@ rtl_arena_segment_get ( } } -/** rtl_arena_segment_put() - * - * @precond arena->m_lock acquired. - * @postcond (*ppSegment == 0) +/** + @precond arena->m_lock acquired. + @postcond (*ppSegment == 0) */ -inline void -rtl_arena_segment_put ( - rtl_arena_type * arena, +inline void rtl_arena_segment_put( + rtl_arena_type * arena, rtl_arena_segment_type ** ppSegment ) { @@ -205,13 +175,11 @@ rtl_arena_segment_put ( (*ppSegment) = nullptr; } -/** rtl_arena_freelist_insert() - * - * @precond arena->m_lock acquired. - */ -inline void -rtl_arena_freelist_insert ( - rtl_arena_type * arena, +/** + @precond arena->m_lock acquired. +*/ +inline void rtl_arena_freelist_insert ( + rtl_arena_type * arena, rtl_arena_segment_type * segment ) { @@ -224,13 +192,11 @@ rtl_arena_freelist_insert ( arena->m_freelist_bitmap |= head->m_size; } -/** rtl_arena_freelist_remove() - * - * @precond arena->m_lock acquired. - */ -inline void -rtl_arena_freelist_remove ( - rtl_arena_type * arena, +/** + @precond arena->m_lock acquired. +*/ +inline void rtl_arena_freelist_remove( + rtl_arena_type * arena, rtl_arena_segment_type * segment ) { @@ -246,24 +212,18 @@ rtl_arena_freelist_remove ( QUEUE_REMOVE_NAMED(segment, f); } -/* ================================================================= */ - -/** RTL_ARENA_HASH_INDEX() - */ #define RTL_ARENA_HASH_INDEX_IMPL(a, s, q, m) \ ((((a) + ((a) >> (s)) + ((a) >> ((s) << 1))) >> (q)) & (m)) #define RTL_ARENA_HASH_INDEX(arena, addr) \ RTL_ARENA_HASH_INDEX_IMPL((addr), (arena)->m_hash_shift, (arena)->m_quantum_shift, ((arena)->m_hash_size - 1)) -/** rtl_arena_hash_rescale() - * - * @precond arena->m_lock released. - */ -void -rtl_arena_hash_rescale ( +/** + @precond arena->m_lock released. +*/ +void rtl_arena_hash_rescale( rtl_arena_type * arena, - sal_Size new_size + sal_Size new_size ) { assert(new_size != 0); @@ -286,15 +246,6 @@ rtl_arena_hash_rescale ( old_table = arena->m_hash_table; old_size = arena->m_hash_size; - // SAL_INFO( - // "sal.rtl", - // "rtl_arena_hash_rescale(" << arena->m_name << "): nseg: " - // << (arena->m_stats.m_alloc - arena->m_stats.m_free) << " (ave: " - // << ((arena->m_stats.m_alloc - arena->m_stats.m_free) - // >> arena->m_hash_shift) - // << "), frees: " << arena->m_stats.m_free << " [old_size: " - // << old_size << ", new_size: " << new_size << ']'); - arena->m_hash_table = new_table; arena->m_hash_size = new_size; arena->m_hash_shift = highbit(arena->m_hash_size) - 1; @@ -327,12 +278,11 @@ rtl_arena_hash_rescale ( } } -/** rtl_arena_hash_insert() - * ...and update stats. - */ -inline void -rtl_arena_hash_insert ( - rtl_arena_type * arena, +/** + Insert arena hash, and update stats. +*/ +inline void rtl_arena_hash_insert( + rtl_arena_type * arena, rtl_arena_segment_type * segment ) { @@ -347,14 +297,13 @@ rtl_arena_hash_insert ( arena->m_stats.m_mem_alloc += segment->m_size; } -/** rtl_arena_hash_remove() - * ...and update stats. - */ -rtl_arena_segment_type * -rtl_arena_hash_remove ( +/** + Remove arena hash, and update stats. +*/ +rtl_arena_segment_type * rtl_arena_hash_remove( rtl_arena_type * arena, - sal_uIntPtr addr, - sal_Size size + sal_uIntPtr addr, + sal_Size size ) { rtl_arena_segment_type *segment, **segpp; @@ -408,18 +357,15 @@ rtl_arena_hash_remove ( return segment; } -/* ================================================================= */ +/** + allocate (and remove) segment from freelist -/** rtl_arena_segment_alloc() - * allocate (and remove) segment from freelist - * - * @precond arena->m_lock acquired - * @precond (*ppSegment == 0) - */ -bool -rtl_arena_segment_alloc ( - rtl_arena_type * arena, - sal_Size size, + @precond arena->m_lock acquired + @precond (*ppSegment == 0) +*/ +bool rtl_arena_segment_alloc( + rtl_arena_type * arena, + sal_Size size, rtl_arena_segment_type ** ppSegment ) { @@ -471,16 +417,15 @@ dequeue_and_leave: return (*ppSegment != nullptr); } -/** rtl_arena_segment_create() - * import new (span) segment from source arena - * - * @precond arena->m_lock acquired - * @precond (*ppSegment == 0) - */ -int -rtl_arena_segment_create ( - rtl_arena_type * arena, - sal_Size size, +/** + import new (span) segment from source arena + + @precond arena->m_lock acquired + @precond (*ppSegment == 0) +*/ +int rtl_arena_segment_create( + rtl_arena_type * arena, + sal_Size size, rtl_arena_segment_type ** ppSegment ) { @@ -526,15 +471,14 @@ rtl_arena_segment_create ( return 0; } -/** rtl_arena_segment_coalesce() - * mark as free and join with adjacent free segment(s) - * - * @precond arena->m_lock acquired - * @precond segment marked 'used' - */ -void -rtl_arena_segment_coalesce ( - rtl_arena_type * arena, +/** + mark as free and join with adjacent free segment(s) + + @precond arena->m_lock acquired + @precond segment marked 'used' +*/ +void rtl_arena_segment_coalesce( + rtl_arena_type * arena, rtl_arena_segment_type * segment ) { @@ -580,12 +524,7 @@ rtl_arena_segment_coalesce ( } } -/* ================================================================= */ - -/** rtl_arena_constructor() - */ -void -rtl_arena_constructor (void * obj) +void rtl_arena_constructor(void * obj) { rtl_arena_type * arena = static_cast<rtl_arena_type*>(obj); rtl_arena_segment_type * head; @@ -623,10 +562,7 @@ rtl_arena_constructor (void * obj) arena->m_hash_shift = highbit(arena->m_hash_size) - 1; } -/** rtl_arena_destructor() - */ -void -rtl_arena_destructor (void * obj) +void rtl_arena_destructor(void * obj) { rtl_arena_type * arena = static_cast<rtl_arena_type*>(obj); rtl_arena_segment_type * head; @@ -663,21 +599,16 @@ rtl_arena_destructor (void * obj) assert(arena->m_hash_shift == highbit(arena->m_hash_size) - 1); } -/* ================================================================= */ - -/** rtl_arena_activate() - */ #if defined __GNUC__ && __GNUC__ >= 7 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-truncation" #endif -rtl_arena_type * -rtl_arena_activate ( - rtl_arena_type * arena, - const char * name, - sal_Size quantum, - sal_Size quantum_cache_max, - rtl_arena_type * source_arena, +rtl_arena_type * rtl_arena_activate( + rtl_arena_type * arena, + const char * name, + sal_Size quantum, + sal_Size quantum_cache_max, + rtl_arena_type * source_arena, void * (SAL_CALL * source_alloc)(rtl_arena_type *, sal_Size *), void (SAL_CALL * source_free) (rtl_arena_type *, void *, sal_Size) ) @@ -733,12 +664,7 @@ rtl_arena_activate ( return arena; } -/** rtl_arena_deactivate() - */ -void -rtl_arena_deactivate ( - rtl_arena_type * arena -) +void rtl_arena_deactivate(rtl_arena_type * arena) { rtl_arena_segment_type * head, * segment; @@ -768,23 +694,10 @@ rtl_arena_deactivate ( } /* check for leaked segments */ - // SAL_INFO( - // "sal.rtl", - // "rtl_arena_deactivate(" << arena->m_name << "): allocs: " - // << arena->m_stats.m_alloc << ", frees: " << arena->m_stats.m_free - // << "; total: " << arena->m_stats.m_mem_total << ", used: " - // << arena->m_stats.m_mem_alloc); if (arena->m_stats.m_alloc > arena->m_stats.m_free) { sal_Size i, n; - // SAL_INFO( - // "sal.rtl", - // "rtl_arena_deactivate(" << arena->m_name << "): cleaning up " - // << (arena->m_stats.m_alloc - arena->m_stats.m_free) - // << " leaked segment(s) [" << arena->m_stats.m_mem_alloc - // << " bytes]"); - /* cleanup still used segment(s) */ for (i = 0, n = arena->m_hash_size; i < n; i++) { @@ -806,13 +719,13 @@ rtl_arena_deactivate ( /* cleanup hash table */ if (arena->m_hash_table != arena->m_hash_table_0) { - rtl_arena_free ( + rtl_arena_free( gp_arena_arena, arena->m_hash_table, arena->m_hash_size * sizeof(rtl_arena_segment_type*)); arena->m_hash_table = arena->m_hash_table_0; - arena->m_hash_size = RTL_ARENA_HASH_SIZE; + arena->m_hash_size = RTL_ARENA_HASH_SIZE; arena->m_hash_shift = highbit(arena->m_hash_size) - 1; } @@ -861,17 +774,9 @@ rtl_arena_deactivate ( } } -} //namespace -/* ================================================================= * - * - * arena implementation. - * - * ================================================================= */ +} // namespace -/** rtl_arena_create() - */ -rtl_arena_type * -SAL_CALL rtl_arena_create ( +rtl_arena_type * SAL_CALL rtl_arena_create( const char * name, sal_Size quantum, sal_Size quantum_cache_max, @@ -926,12 +831,7 @@ try_alloc: return result; } -/** rtl_arena_destroy() - */ -void -SAL_CALL rtl_arena_destroy ( - rtl_arena_type * arena -) SAL_THROW_EXTERN_C() +void SAL_CALL rtl_arena_destroy(rtl_arena_type * arena) SAL_THROW_EXTERN_C() { if (arena != nullptr) { @@ -941,10 +841,7 @@ SAL_CALL rtl_arena_destroy ( } } -/** rtl_arena_alloc() - */ -void * -SAL_CALL rtl_arena_alloc ( +void * SAL_CALL rtl_arena_alloc( rtl_arena_type * arena, sal_Size * pSize ) SAL_THROW_EXTERN_C() @@ -1013,10 +910,7 @@ SAL_CALL rtl_arena_alloc ( return addr; } -/** rtl_arena_free() - */ -void -SAL_CALL rtl_arena_free ( +void SAL_CALL rtl_arena_free ( rtl_arena_type * arena, void * addr, sal_Size size @@ -1096,12 +990,6 @@ SAL_CALL rtl_arena_free ( } } -/* ================================================================= * - * - * machdep internals. - * - * ================================================================= */ - #if defined(SAL_UNX) #include <sys/mman.h> #elif defined(SAL_W32) @@ -1111,10 +999,7 @@ SAL_CALL rtl_arena_free ( namespace { -/** rtl_machdep_alloc() - */ -void * -SAL_CALL rtl_machdep_alloc ( +void * SAL_CALL rtl_machdep_alloc( rtl_arena_type * pArena, sal_Size * pSize ) @@ -1136,7 +1021,7 @@ SAL_CALL rtl_machdep_alloc ( size -= (pArena->m_quantum + pArena->m_quantum); /* "red-zone" pages */ #else /* default allocation granularity */ - if(pArena->m_quantum < (64 << 10)) + if (pArena->m_quantum < (64 << 10)) { size = RTL_MEMORY_P2ROUNDUP(size, (64 << 10)); } @@ -1164,10 +1049,7 @@ SAL_CALL rtl_machdep_alloc ( return nullptr; } -/** rtl_machdep_free() - */ -void -SAL_CALL rtl_machdep_free ( +void SAL_CALL rtl_machdep_free( rtl_arena_type * pArena, void * pAddr, sal_Size nSize @@ -1186,8 +1068,7 @@ SAL_CALL rtl_machdep_free ( #endif /* (SAL_UNX || SAL_W32) */ } -sal_Size -rtl_machdep_pagesize() +sal_Size rtl_machdep_pagesize() { #if defined(SAL_UNX) #if defined(FREEBSD) || defined(NETBSD) || defined(DRAGONFLY) @@ -1204,14 +1085,7 @@ rtl_machdep_pagesize() } //namespace -/* ================================================================= * - * - * arena initialization. - * - * ================================================================= */ - -void -rtl_arena_init() +void rtl_arena_init() { { /* list of arenas */ @@ -1259,7 +1133,7 @@ rtl_arena_init() assert(gp_arena_arena == nullptr); rtl_arena_constructor (&g_arena_arena); - gp_arena_arena = rtl_arena_activate ( + gp_arena_arena = rtl_arena_activate( &g_arena_arena, "rtl_arena_internal_arena", 64, /* quantum */ @@ -1270,13 +1144,9 @@ rtl_arena_init() ); assert(gp_arena_arena != nullptr); } - // SAL_INFO("sal.rtl", "rtl_arena_init completed"); } -/* ================================================================= */ - -void -rtl_arena_fini() +void rtl_arena_fini() { if (gp_arena_arena != nullptr) { @@ -1287,19 +1157,10 @@ rtl_arena_fini() for (arena = head->m_arena_next; arena != head; arena = arena->m_arena_next) { - // SAL_INFO( - // "sal.rtl", - // "rtl_arena_fini(" << arena->m_name << "): allocs: " - // << arena->m_stats.m_alloc << ", frees: " - // << arena->m_stats.m_free << "; total: " - // << arena->m_stats.m_mem_total << ", used: " - // << arena->m_stats.m_mem_alloc); + // noop } RTL_MEMORY_LOCK_RELEASE(&(g_arena_list.m_lock)); } - // SAL_INFO("sal.rtl", "rtl_arena_fini completed"); } -/* ================================================================= */ - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/rtl/alloc_cache.cxx b/sal/rtl/alloc_cache.cxx index d2c5fc5c8745..4dfa1eb966c4 100644 --- a/sal/rtl/alloc_cache.cxx +++ b/sal/rtl/alloc_cache.cxx @@ -32,13 +32,7 @@ #include <sys/time.h> #endif -/* ================================================================= * - * - * cache internals. - * - * ================================================================= */ - -/** g_cache_list +/** * @internal */ struct rtl_cache_list_st @@ -58,32 +52,28 @@ struct rtl_cache_list_st static rtl_cache_list_st g_cache_list; -/** gp_cache_arena - * provided for cache_type allocations, and hash_table resizing. - * - * @internal - */ +/** + provided for cache_type allocations, and hash_table resizing. + + @internal +*/ static rtl_arena_type * gp_cache_arena = nullptr; -/** gp_cache_magazine_cache - * @internal - */ +/** + @internal +*/ static rtl_cache_type * gp_cache_magazine_cache = nullptr; -/** gp_cache_slab_cache - * @internal - */ +/** + @internal +*/ static rtl_cache_type * gp_cache_slab_cache = nullptr; -/** gp_cache_bufctl_cache - * @internal - */ +/** + @internal +*/ static rtl_cache_type * gp_cache_bufctl_cache = nullptr; -/* ================================================================= */ - -/** RTL_CACHE_HASH_INDEX() - */ #define RTL_CACHE_HASH_INDEX_IMPL(a, s, q, m) \ ((((a) + ((a) >> (s)) + ((a) >> ((s) << 1))) >> (q)) & (m)) @@ -93,8 +83,7 @@ static rtl_cache_type * gp_cache_bufctl_cache = nullptr; namespace { -void -rtl_cache_hash_rescale ( +void rtl_cache_hash_rescale( rtl_cache_type * cache, sal_Size new_size ) @@ -117,16 +106,6 @@ rtl_cache_hash_rescale ( old_table = cache->m_hash_table; old_size = cache->m_hash_size; - // SAL_INFO( - // "sal.rtl", - // "rtl_cache_hash_rescale(" << cache->m_name << "): nbuf: " - // << (cache->m_slab_stats.m_alloc - cache->m_slab_stats.m_free) - // << " (ave: " - // << ((cache->m_slab_stats.m_alloc - cache->m_slab_stats.m_free) - // >> cache->m_hash_shift) - // << "), frees: " << cache->m_slab_stats.m_free << " [old_size: " - // << old_size << ", new_size: " << new_size << ']'); - cache->m_hash_table = new_table; cache->m_hash_size = new_size; const auto bit = highbit(cache->m_hash_size); @@ -160,8 +139,7 @@ rtl_cache_hash_rescale ( } } -inline sal_uIntPtr -rtl_cache_hash_insert ( +inline sal_uIntPtr rtl_cache_hash_insert( rtl_cache_type * cache, rtl_cache_bufctl_type * bufctl ) @@ -176,10 +154,7 @@ rtl_cache_hash_insert ( return bufctl->m_addr; } -/** rtl_cache_hash_remove() - */ -rtl_cache_bufctl_type * -rtl_cache_hash_remove ( +rtl_cache_bufctl_type * rtl_cache_hash_remove( rtl_cache_type * cache, sal_uIntPtr addr ) @@ -228,17 +203,10 @@ rtl_cache_hash_remove ( return bufctl; } -/* ================================================================= */ - -/** RTL_CACHE_SLAB() - */ #define RTL_CACHE_SLAB(addr, size) \ ((reinterpret_cast<rtl_cache_slab_type*>(RTL_MEMORY_P2END(reinterpret_cast<sal_uIntPtr>(addr), (size)))) - 1) -/** rtl_cache_slab_constructor() - */ -int -rtl_cache_slab_constructor (void * obj, SAL_UNUSED_PARAMETER void *) +int rtl_cache_slab_constructor(void * obj, SAL_UNUSED_PARAMETER void *) { rtl_cache_slab_type * slab = static_cast<rtl_cache_slab_type*>(obj); @@ -248,10 +216,7 @@ rtl_cache_slab_constructor (void * obj, SAL_UNUSED_PARAMETER void *) return 1; } -/** rtl_cache_slab_destructor() - */ -void -rtl_cache_slab_destructor (void * obj, SAL_UNUSED_PARAMETER void *) +void rtl_cache_slab_destructor(void * obj, SAL_UNUSED_PARAMETER void *) { rtl_cache_slab_type * slab = static_cast< rtl_cache_slab_type * >(obj); assert(QUEUE_STARTED_NAMED(slab, slab_)); // assure removed from queue(s) @@ -259,14 +224,10 @@ rtl_cache_slab_destructor (void * obj, SAL_UNUSED_PARAMETER void *) (void) slab; // avoid warnings } -/** rtl_cache_slab_create() - * - * @precond cache->m_slab_lock released. - */ -rtl_cache_slab_type * -rtl_cache_slab_create ( - rtl_cache_type * cache -) +/** + @precond cache->m_slab_lock released. +*/ +rtl_cache_slab_type * rtl_cache_slab_create(rtl_cache_type * cache) { rtl_cache_slab_type * slab = nullptr; void * addr; @@ -306,12 +267,10 @@ rtl_cache_slab_create ( return slab; } -/** rtl_cache_slab_destroy() - * - * @precond cache->m_slab_lock released. - */ -void -rtl_cache_slab_destroy ( +/** + @precond cache->m_slab_lock released. +*/ +void rtl_cache_slab_destroy( rtl_cache_type * cache, rtl_cache_slab_type * slab ) @@ -352,14 +311,10 @@ rtl_cache_slab_destroy ( } } -/** rtl_cache_slab_populate() - * - * @precond cache->m_slab_lock acquired. - */ -bool -rtl_cache_slab_populate ( - rtl_cache_type * cache -) +/** + @precond cache->m_slab_lock acquired. +*/ +bool rtl_cache_slab_populate(rtl_cache_type * cache) { rtl_cache_slab_type * slab; @@ -385,16 +340,10 @@ rtl_cache_slab_populate ( return (slab != nullptr); } -/* ================================================================= */ - -/** rtl_cache_slab_alloc() - * - * Allocate a buffer from slab layer; used by magazine layer. - */ -void * -rtl_cache_slab_alloc ( - rtl_cache_type * cache -) +/** + Allocate a buffer from slab layer; used by magazine layer. +*/ +void * rtl_cache_slab_alloc (rtl_cache_type * cache) { void * addr = nullptr; rtl_cache_slab_type * head; @@ -471,12 +420,10 @@ rtl_cache_slab_alloc ( return addr; } -/** rtl_cache_slab_free() - * - * Return a buffer to slab layer; used by magazine layer. - */ -void -rtl_cache_slab_free ( +/** + Return a buffer to slab layer; used by magazine layer. +*/ +void rtl_cache_slab_free( rtl_cache_type * cache, void * addr ) @@ -538,12 +485,7 @@ rtl_cache_slab_free ( RTL_MEMORY_LOCK_RELEASE(&(cache->m_slab_lock)); } -/* ================================================================= */ - -/** rtl_cache_magazine_constructor() - */ -int -rtl_cache_magazine_constructor (void * obj, SAL_UNUSED_PARAMETER void *) +int rtl_cache_magazine_constructor(void * obj, SAL_UNUSED_PARAMETER void *) { rtl_cache_magazine_type * mag = static_cast<rtl_cache_magazine_type*>(obj); /* @@@ sal_Size size = (sal_Size)(arg); @@@ */ @@ -555,10 +497,7 @@ rtl_cache_magazine_constructor (void * obj, SAL_UNUSED_PARAMETER void *) return 1; } -/** rtl_cache_magazine_destructor() - */ -void -rtl_cache_magazine_destructor (void * obj, SAL_UNUSED_PARAMETER void *) +void rtl_cache_magazine_destructor(void * obj, SAL_UNUSED_PARAMETER void *) { rtl_cache_magazine_type * mag = static_cast< rtl_cache_magazine_type * >( obj); @@ -567,10 +506,7 @@ rtl_cache_magazine_destructor (void * obj, SAL_UNUSED_PARAMETER void *) (void) mag; // avoid warnings } -/** rtl_cache_magazine_clear() - */ -void -rtl_cache_magazine_clear ( +void rtl_cache_magazine_clear( rtl_cache_type * cache, rtl_cache_magazine_type * mag ) @@ -591,14 +527,10 @@ rtl_cache_magazine_clear ( } } -/* ================================================================= */ - -/** rtl_cache_depot_enqueue() - * - * @precond cache->m_depot_lock acquired. - */ -inline void -rtl_cache_depot_enqueue ( +/** + @precond cache->m_depot_lock acquired. +*/ +inline void rtl_cache_depot_enqueue( rtl_cache_depot_type * depot, rtl_cache_magazine_type * mag ) @@ -611,12 +543,10 @@ rtl_cache_depot_enqueue ( depot->m_mag_count++; } -/** rtl_cache_depot_dequeue() - * - * @precond cache->m_depot_lock acquired. - */ -inline rtl_cache_magazine_type * -rtl_cache_depot_dequeue ( +/** + @precond cache->m_depot_lock acquired. +*/ +inline rtl_cache_magazine_type * rtl_cache_depot_dequeue( rtl_cache_depot_type * depot ) { @@ -640,12 +570,10 @@ rtl_cache_depot_dequeue ( return mag; } -/** rtl_cache_depot_exchange_alloc() - * - * @precond cache->m_depot_lock acquired. - */ -inline rtl_cache_magazine_type * -rtl_cache_depot_exchange_alloc ( +/** + @precond cache->m_depot_lock acquired. +*/ +inline rtl_cache_magazine_type * rtl_cache_depot_exchange_alloc( rtl_cache_type * cache, rtl_cache_magazine_type * empty ) @@ -667,12 +595,10 @@ rtl_cache_depot_exchange_alloc ( return full; } -/** rtl_cache_depot_exchange_free() - * - * @precond cache->m_depot_lock acquired. - */ -inline rtl_cache_magazine_type * -rtl_cache_depot_exchange_free ( +/** + @precond cache->m_depot_lock acquired. +*/ +inline rtl_cache_magazine_type * rtl_cache_depot_exchange_free( rtl_cache_type * cache, rtl_cache_magazine_type * full ) @@ -694,14 +620,10 @@ rtl_cache_depot_exchange_free ( return empty; } -/** rtl_cache_depot_populate() - * - * @precond cache->m_depot_lock acquired. - */ -bool -rtl_cache_depot_populate ( - rtl_cache_type * cache -) +/** + @precond cache->m_depot_lock acquired. +*/ +bool rtl_cache_depot_populate(rtl_cache_type * cache) { rtl_cache_magazine_type * empty = nullptr; @@ -720,12 +642,7 @@ rtl_cache_depot_populate ( return (empty != nullptr); } -/* ================================================================= */ - -/** rtl_cache_constructor() - */ -int -rtl_cache_constructor (void * obj) +int rtl_cache_constructor(void * obj) { rtl_cache_type * cache = static_cast<rtl_cache_type*>(obj); @@ -750,10 +667,7 @@ rtl_cache_constructor (void * obj) return 1; } -/** rtl_cache_destructor() - */ -void -rtl_cache_destructor (void * obj) +void rtl_cache_destructor(void * obj) { rtl_cache_type * cache = static_cast<rtl_cache_type*>(obj); @@ -774,12 +688,7 @@ rtl_cache_destructor (void * obj) RTL_MEMORY_LOCK_DESTROY(&(cache->m_depot_lock)); } -/* ================================================================= */ - -/** rtl_cache_activate() - */ -rtl_cache_type * -rtl_cache_activate ( +rtl_cache_type * rtl_cache_activate( rtl_cache_type * cache, const char * name, size_t objsize, @@ -896,12 +805,7 @@ rtl_cache_activate ( return cache; } -/** rtl_cache_deactivate() - */ -void -rtl_cache_deactivate ( - rtl_cache_type * cache -) +void rtl_cache_deactivate(rtl_cache_type * cache) { /* remove from cache list */ RTL_MEMORY_LOCK_ACQUIRE(&(g_cache_list.m_lock)); @@ -951,29 +855,9 @@ rtl_cache_deactivate ( } } - // SAL_INFO( - // "sal.rtl", - // "rtl_cache_deactivate(" << cache->m_name << "): [slab]: allocs: " - // << cache->m_slab_stats.m_alloc << ", frees: " - // << cache->m_slab_stats.m_free << "; total: " - // << cache->m_slab_stats.m_mem_total << ", used: " - // << cache->m_slab_stats.m_mem_alloc << "; [cpu]: allocs: " - // << cache->m_cpu_stats.m_alloc << ", frees: " - // << cache->m_cpu_stats.m_free << "; [total]: allocs: " - // << (cache->m_slab_stats.m_alloc + cache->m_cpu_stats.m_alloc) - // << ", frees: " - // << (cache->m_slab_stats.m_free + cache->m_cpu_stats.m_free)); - /* cleanup slab layer */ if (cache->m_slab_stats.m_alloc > cache->m_slab_stats.m_free) { - // SAL_INFO( - // "sal.rtl", - // "rtl_cache_deactivate(" << cache->m_name << "): cleaning up " - // << (cache->m_slab_stats.m_alloc - cache->m_slab_stats.m_free) - // << " leaked buffer(s) [" << cache->m_slab_stats.m_mem_alloc - // << " bytes] [" << cache->m_slab_stats.m_mem_total << " total]"); - if (cache->m_features & RTL_CACHE_FEATURE_HASH) { /* cleanup bufctl(s) for leaking buffer(s) */ @@ -1039,16 +923,7 @@ rtl_cache_deactivate ( } //namespace -/* ================================================================= * - * - * cache implementation. - * - * ================================================================= */ - -/** rtl_cache_create() - */ -rtl_cache_type * -SAL_CALL rtl_cache_create ( +rtl_cache_type * SAL_CALL rtl_cache_create( const char * name, sal_Size objsize, sal_Size objalign, @@ -1109,11 +984,7 @@ try_alloc: return result; } -/** rtl_cache_destroy() - */ -void SAL_CALL rtl_cache_destroy ( - rtl_cache_type * cache -) SAL_THROW_EXTERN_C() +void SAL_CALL rtl_cache_destroy(rtl_cache_type * cache) SAL_THROW_EXTERN_C() { if (cache != nullptr) { @@ -1123,12 +994,7 @@ void SAL_CALL rtl_cache_destroy ( } } -/** rtl_cache_alloc() - */ -void * -SAL_CALL rtl_cache_alloc ( - rtl_cache_type * cache -) SAL_THROW_EXTERN_C() +void * SAL_CALL rtl_cache_alloc(rtl_cache_type * cache) SAL_THROW_EXTERN_C() { void * obj = nullptr; @@ -1208,10 +1074,7 @@ SAL_CALL rtl_cache_alloc ( return obj; } -/** rtl_cache_free() - */ -void -SAL_CALL rtl_cache_free ( +void SAL_CALL rtl_cache_free( rtl_cache_type * cache, void * obj ) SAL_THROW_EXTERN_C() @@ -1290,8 +1153,7 @@ SAL_CALL rtl_cache_free ( #if defined(SAL_UNX) -void SAL_CALL -rtl_secureZeroMemory (void *Ptr, sal_Size Bytes) SAL_THROW_EXTERN_C() +void SAL_CALL rtl_secureZeroMemory(void *Ptr, sal_Size Bytes) SAL_THROW_EXTERN_C() { //currently glibc doesn't implement memset_s volatile char *p = static_cast<volatile char*>(Ptr); @@ -1299,11 +1161,9 @@ rtl_secureZeroMemory (void *Ptr, sal_Size Bytes) SAL_THROW_EXTERN_C() *p++ = 0; } -static void * -rtl_cache_wsupdate_all (void * arg); +static void * rtl_cache_wsupdate_all(void * arg); -static void -rtl_cache_wsupdate_init() +static void rtl_cache_wsupdate_init() { RTL_MEMORY_LOCK_ACQUIRE(&(g_cache_list.m_lock)); g_cache_list.m_update_done = 0; @@ -1317,8 +1177,7 @@ rtl_cache_wsupdate_init() RTL_MEMORY_LOCK_RELEASE(&(g_cache_list.m_lock)); } -static void -rtl_cache_wsupdate_wait (unsigned int seconds) +static void rtl_cache_wsupdate_wait(unsigned int seconds) { if (seconds > 0) { @@ -1336,8 +1195,7 @@ rtl_cache_wsupdate_wait (unsigned int seconds) } } -static void -rtl_cache_wsupdate_fini() +static void rtl_cache_wsupdate_fini() { RTL_MEMORY_LOCK_ACQUIRE(&(g_cache_list.m_lock)); g_cache_list.m_update_done = 1; @@ -1348,21 +1206,16 @@ rtl_cache_wsupdate_fini() pthread_join (g_cache_list.m_update_thread, nullptr); } -/* ================================================================= */ - #elif defined(SAL_W32) -void SAL_CALL -rtl_secureZeroMemory (void *Ptr, sal_Size Bytes) SAL_THROW_EXTERN_C() +void SAL_CALL rtl_secureZeroMemory(void *Ptr, sal_Size Bytes) SAL_THROW_EXTERN_C() { RtlSecureZeroMemory(Ptr, Bytes); } -static DWORD WINAPI -rtl_cache_wsupdate_all (void * arg); +static DWORD WINAPI rtl_cache_wsupdate_all(void * arg); -static void -rtl_cache_wsupdate_init() +static void rtl_cache_wsupdate_init() { DWORD dwThreadId; @@ -1375,8 +1228,7 @@ rtl_cache_wsupdate_init() RTL_MEMORY_LOCK_RELEASE(&(g_cache_list.m_lock)); } -static void -rtl_cache_wsupdate_wait (unsigned int seconds) +static void rtl_cache_wsupdate_wait(unsigned int seconds) { if (seconds > 0) { @@ -1386,8 +1238,7 @@ rtl_cache_wsupdate_wait (unsigned int seconds) } } -static void -rtl_cache_wsupdate_fini() +static void rtl_cache_wsupdate_fini() { RTL_MEMORY_LOCK_ACQUIRE(&(g_cache_list.m_lock)); g_cache_list.m_update_done = 1; @@ -1399,15 +1250,12 @@ rtl_cache_wsupdate_fini() #endif /* SAL_UNX || SAL_W32 */ -/* ================================================================= */ +/** + update depot stats and purge excess magazines. -/** rtl_cache_depot_wsupdate() - * update depot stats and purge excess magazines. - * - * @precond cache->m_depot_lock acquired - */ -static void -rtl_cache_depot_wsupdate ( + @precond cache->m_depot_lock acquired +*/ +static void rtl_cache_depot_wsupdate( rtl_cache_type * cache, rtl_cache_depot_type * depot ) @@ -1432,30 +1280,15 @@ rtl_cache_depot_wsupdate ( // coverity[missing_unlock] } -/** rtl_cache_wsupdate() - * - * @precond cache->m_depot_lock released - */ -static void -rtl_cache_wsupdate ( - rtl_cache_type * cache -) +/** + @precond cache->m_depot_lock released +*/ +static void rtl_cache_wsupdate(rtl_cache_type * cache) { if (cache->m_magazine_cache != nullptr) { RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_depot_lock)); - // SAL_INFO( - // "sal.rtl", - // "rtl_cache_wsupdate(" << cache->m_name - // << ") [depot: count, curr_min, prev_min] full: " - // << cache->m_depot_full.m_mag_count << ", " - // << cache->m_depot_full.m_curr_min << ", " - // << cache->m_depot_full.m_prev_min << "; empty: " - // << cache->m_depot_empty.m_mag_count << ", " - // << cache->m_depot_empty.m_curr_min << ", " - // << cache->m_depot_empty.m_prev_min); - rtl_cache_depot_wsupdate (cache, &(cache->m_depot_full)); rtl_cache_depot_wsupdate (cache, &(cache->m_depot_empty)); @@ -1463,15 +1296,12 @@ rtl_cache_wsupdate ( } } -/** rtl_cache_wsupdate_all() - * - */ #if defined(SAL_UNX) static void * #elif defined(SAL_W32) static DWORD WINAPI #endif /* SAL_UNX || SAL_W32 */ -rtl_cache_wsupdate_all (void * arg) +rtl_cache_wsupdate_all(void * arg) { osl::Thread::setName("rtl_cache_wsupdate_all"); unsigned int seconds = sal::static_int_cast< unsigned int >( @@ -1503,14 +1333,7 @@ rtl_cache_wsupdate_all (void * arg) #endif } -/* ================================================================= * - * - * cache initialization. - * - * ================================================================= */ - -void -rtl_cache_init() +void rtl_cache_init() { { /* list of caches */ @@ -1600,13 +1423,9 @@ rtl_cache_init() } rtl_cache_wsupdate_init(); - // SAL_INFO("sal.rtl", "rtl_cache_init completed"); } -/* ================================================================= */ - -void -rtl_cache_fini() +void rtl_cache_fini() { if (gp_cache_arena != nullptr) { @@ -1645,24 +1464,10 @@ rtl_cache_fini() head = &(g_cache_list.m_cache_head); for (cache = head->m_cache_next; cache != head; cache = cache->m_cache_next) { - // SAL_INFO( - // "sal.rtl", - // "rtl_cache_fini(" << cache->m_name << ") [slab]: allocs: " - // << cache->m_slab_stats.m_alloc << ", frees: " - // << cache->m_slab_stats.m_free << "; total: " - // << cache->m_slab_stats.m_mem_total << ", used: " - // << cache->m_slab_stats.m_mem_alloc << "; [cpu]: allocs: " - // << cache->m_cpu_stats.m_alloc << ", frees: " - // << cache->m_cpu_stats.m_free << "; [total]: allocs: " - // << (cache->m_slab_stats.m_alloc ... etc. - the rest is truncated _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits