diff options
author | Dave Parks <davep@lindenlab.com> | 2009-11-24 23:21:57 -0600 |
---|---|---|
committer | Dave Parks <davep@lindenlab.com> | 2009-11-24 23:21:57 -0600 |
commit | e264f00c833805e1f813bc1d0b2cfd7a1bf7b272 (patch) | |
tree | 1a64a520502d2ed2c7dadc2316e543ae9e9a91d2 /indra/llcommon | |
parent | c9e153c182dae9472a2b87cddfec8c47b30b06b9 (diff) | |
parent | 5b5354c933aa7b1ceeb307853c24fba28d4e31bf (diff) |
Merge
Diffstat (limited to 'indra/llcommon')
-rw-r--r-- | indra/llcommon/CMakeLists.txt | 44 | ||||
-rw-r--r-- | indra/llcommon/llassettype.h | 5 | ||||
-rw-r--r-- | indra/llcommon/llchat.h | 2 | ||||
-rw-r--r-- | indra/llcommon/llclickaction.h | 5 | ||||
-rw-r--r-- | indra/llcommon/lleventapi.cpp | 30 | ||||
-rw-r--r-- | indra/llcommon/lleventapi.h | 66 | ||||
-rw-r--r-- | indra/llcommon/lleventdispatcher.cpp | 26 | ||||
-rw-r--r-- | indra/llcommon/lleventdispatcher.h | 76 | ||||
-rw-r--r-- | indra/llcommon/llevents.h | 2 | ||||
-rw-r--r-- | indra/llcommon/llfoldertype.cpp | 3 | ||||
-rw-r--r-- | indra/llcommon/llfoldertype.h | 17 | ||||
-rw-r--r-- | indra/llcommon/llinstancetracker.h | 112 | ||||
-rw-r--r-- | indra/llcommon/llpreprocessor.h | 1 | ||||
-rw-r--r-- | indra/llcommon/llprocesslauncher.h | 8 | ||||
-rw-r--r-- | indra/llcommon/llqueuedthread.cpp | 1 | ||||
-rw-r--r-- | indra/llcommon/llsys.cpp | 129 | ||||
-rw-r--r-- | indra/llcommon/llthread.cpp | 18 | ||||
-rw-r--r-- | indra/llcommon/llthread.h | 5 | ||||
-rw-r--r-- | indra/llcommon/lltimer.cpp | 12 | ||||
-rw-r--r-- | indra/llcommon/tests/llinstancetracker_test.cpp | 160 | ||||
-rw-r--r-- | indra/llcommon/tests/lltreeiterators_test.cpp | 3 |
21 files changed, 585 insertions, 140 deletions
diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index f785698612..416303342a 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -1,3 +1,4 @@ + # -*- cmake -*- project(llcommon) @@ -6,11 +7,10 @@ include(00-Common) include(LLCommon) include(Linking) include(Boost) -include (Pth) - -if (WINDOWS) - include(CopyWinLibs) -endif (WINDOWS) +include(Pth) +include(LLSharedLibs) +include(GooglePerfTools) +include(Copy3rdPartyLibs) include_directories( ${EXPAT_INCLUDE_DIRS} @@ -42,6 +42,7 @@ set(llcommon_SOURCE_FILES llerror.cpp llerrorthread.cpp llevent.cpp + lleventapi.cpp lleventcoro.cpp lleventdispatcher.cpp lleventfilter.cpp @@ -141,6 +142,7 @@ set(llcommon_HEADER_FILES llerrorlegacy.h llerrorthread.h llevent.h + lleventapi.h lleventcoro.h lleventdispatcher.h lleventfilter.h @@ -243,35 +245,7 @@ list(APPEND llcommon_SOURCE_FILES ${llcommon_HEADER_FILES}) if(LLCOMMON_LINK_SHARED) add_library (llcommon SHARED ${llcommon_SOURCE_FILES}) - - if(SHARED_LIB_STAGING_DIR) - # *FIX:Mani --- - # llcommon.dll get written to the DLL staging directory. - # Also this directory is shared with RunBuildTest.cmake, y'know, for the tests. - set_target_properties(llcommon PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${SHARED_LIB_STAGING_DIR}) - if(NOT WINDOWS) - get_target_property(LLCOMMON_PATH llcommon LOCATION) - get_filename_component(LLCOMMON_FILE ${LLCOMMON_PATH} NAME) - add_custom_command( - TARGET llcommon POST_BUILD - COMMAND ${CMAKE_COMMAND} - ARGS - -E - copy_if_different - ${LLCOMMON_PATH} - ${SHARED_LIB_STAGING_DIR}/${CMAKE_CFG_INTDIR}/${LLCOMMON_FILE} - COMMENT "Copying llcommon to the staging folder." - ) - endif(NOT WINDOWS) - endif(SHARED_LIB_STAGING_DIR) - - if (DARWIN) - set_target_properties(llcommon PROPERTIES - BUILD_WITH_INSTALL_RPATH 1 - INSTALL_NAME_DIR "@executable_path/../Resources" - ) - endif(DARWIN) - + ll_stage_sharedlib(llcommon) else(LLCOMMON_LINK_SHARED) add_library (llcommon ${llcommon_SOURCE_FILES}) endif(LLCOMMON_LINK_SHARED) @@ -286,6 +260,7 @@ target_link_libraries( ${BOOST_PROGRAM_OPTIONS_LIBRARY} ${BOOST_REGEX_LIBRARY} ${PTH_LIBRARIES} + ${GOOGLE_PERFTOOLS_LIBRARIES} ) add_dependencies(llcommon stage_third_party_libs) @@ -305,6 +280,7 @@ LL_ADD_INTEGRATION_TEST(lldate "" "${test_libs}") LL_ADD_INTEGRATION_TEST(lldependencies "" "${test_libs}") LL_ADD_INTEGRATION_TEST(llerror "" "${test_libs}") LL_ADD_INTEGRATION_TEST(llframetimer "" "${test_libs}") +LL_ADD_INTEGRATION_TEST(llinstancetracker "" "${test_libs}") LL_ADD_INTEGRATION_TEST(lllazy "" "${test_libs}") LL_ADD_INTEGRATION_TEST(llrand "" "${test_libs}") LL_ADD_INTEGRATION_TEST(llsdserialize "" "${test_libs}") diff --git a/indra/llcommon/llassettype.h b/indra/llcommon/llassettype.h index ec2290d30e..c7bbc2e74a 100644 --- a/indra/llcommon/llassettype.h +++ b/indra/llcommon/llassettype.h @@ -78,11 +78,6 @@ public: // Holds a collection of inventory items. // It's treated as an item in the inventory and therefore needs a type. - AT_ROOT_CATEGORY = 9, - // A user's root inventory category. - // We decided to expose it visually, so it seems logical to fold - // it into the asset types. - AT_LSL_TEXT = 10, AT_LSL_BYTECODE = 11, // The LSL is the scripting language. diff --git a/indra/llcommon/llchat.h b/indra/llcommon/llchat.h index acd0da61a4..5af7991006 100644 --- a/indra/llcommon/llchat.h +++ b/indra/llcommon/llchat.h @@ -84,6 +84,7 @@ public: mAudible(CHAT_AUDIBLE_FULLY), mMuted(FALSE), mTime(0.0), + mTimeStr(), mPosAgent(), mURL(), mChatStyle(CHAT_STYLE_NORMAL) @@ -97,6 +98,7 @@ public: EChatAudible mAudible; BOOL mMuted; // pass muted chat to maintain list of chatters F64 mTime; // viewer only, seconds from viewer start + std::string mTimeStr; LLVector3 mPosAgent; std::string mURL; EChatStyle mChatStyle; diff --git a/indra/llcommon/llclickaction.h b/indra/llcommon/llclickaction.h index 8048724575..d4ffbf8634 100644 --- a/indra/llcommon/llclickaction.h +++ b/indra/llcommon/llclickaction.h @@ -33,7 +33,7 @@ #ifndef LL_LLCLICKACTION_H #define LL_LLCLICKACTION_H - +// DO NOT CHANGE THE SEQUENCE OF THIS LIST!! const U8 CLICK_ACTION_NONE = 0; const U8 CLICK_ACTION_TOUCH = 0; const U8 CLICK_ACTION_SIT = 1; @@ -42,5 +42,6 @@ const U8 CLICK_ACTION_PAY = 3; const U8 CLICK_ACTION_OPEN = 4; const U8 CLICK_ACTION_PLAY = 5; const U8 CLICK_ACTION_OPEN_MEDIA = 6; - +const U8 CLICK_ACTION_ZOOM = 7; +// DO NOT CHANGE THE SEQUENCE OF THIS LIST!! #endif diff --git a/indra/llcommon/lleventapi.cpp b/indra/llcommon/lleventapi.cpp new file mode 100644 index 0000000000..1dd104da8f --- /dev/null +++ b/indra/llcommon/lleventapi.cpp @@ -0,0 +1,30 @@ +/** + * @file lleventapi.cpp + * @author Nat Goodspeed + * @date 2009-11-10 + * @brief Implementation for lleventapi. + * + * $LicenseInfo:firstyear=2009&license=viewergpl$ + * Copyright (c) 2009, Linden Research, Inc. + * $/LicenseInfo$ + */ + +// Precompiled header +#include "linden_common.h" +// associated header +#include "lleventapi.h" +// STL headers +// std headers +// external library headers +// other Linden headers + +LLEventAPI::LLEventAPI(const std::string& name, const std::string& desc, const std::string& field): + lbase(name, field), + ibase(name), + mDesc(desc) +{ +} + +LLEventAPI::~LLEventAPI() +{ +} diff --git a/indra/llcommon/lleventapi.h b/indra/llcommon/lleventapi.h new file mode 100644 index 0000000000..96d1b03be8 --- /dev/null +++ b/indra/llcommon/lleventapi.h @@ -0,0 +1,66 @@ +/** + * @file lleventapi.h + * @author Nat Goodspeed + * @date 2009-10-28 + * @brief LLEventAPI is the base class for every class that wraps a C++ API + * in an event API + * (see https://wiki.lindenlab.com/wiki/Incremental_Viewer_Automation/Event_API). + * + * $LicenseInfo:firstyear=2009&license=viewergpl$ + * Copyright (c) 2009, Linden Research, Inc. + * $/LicenseInfo$ + */ + +#if ! defined(LL_LLEVENTAPI_H) +#define LL_LLEVENTAPI_H + +#include "lleventdispatcher.h" +#include "llinstancetracker.h" +#include <string> + +/** + * LLEventAPI not only provides operation dispatch functionality, inherited + * from LLDispatchListener -- it also gives us event API introspection. + * Deriving from LLInstanceTracker lets us enumerate instances. + */ +class LL_COMMON_API LLEventAPI: public LLDispatchListener, + public LLInstanceTracker<LLEventAPI, std::string> +{ + typedef LLDispatchListener lbase; + typedef LLInstanceTracker<LLEventAPI, std::string> ibase; + +public: + /** + * @param name LLEventPump name on which this LLEventAPI will listen. This + * also serves as the LLInstanceTracker instance key. + * @param desc Documentation string shown to a client trying to discover + * available event APIs. + * @param field LLSD::Map key used by LLDispatchListener to look up the + * subclass method to invoke [default "op"]. + */ + LLEventAPI(const std::string& name, const std::string& desc, const std::string& field="op"); + virtual ~LLEventAPI(); + + /// Get the string name of this LLEventAPI + std::string getName() const { return ibase::getKey(); } + /// Get the documentation string + std::string getDesc() const { return mDesc; } + + /** + * Publish only selected add() methods from LLEventDispatcher. + * Every LLEventAPI add() @em must have a description string. + */ + template <typename CALLABLE> + void add(const std::string& name, + const std::string& desc, + CALLABLE callable, + const LLSD& required=LLSD()) + { + LLEventDispatcher::add(name, desc, callable, required); + } + +private: + std::string mDesc; +}; + +#endif /* ! defined(LL_LLEVENTAPI_H) */ diff --git a/indra/llcommon/lleventdispatcher.cpp b/indra/llcommon/lleventdispatcher.cpp index 6b1413d054..5fa6059718 100644 --- a/indra/llcommon/lleventdispatcher.cpp +++ b/indra/llcommon/lleventdispatcher.cpp @@ -36,9 +36,11 @@ LLEventDispatcher::~LLEventDispatcher() } /// Register a callable by name -void LLEventDispatcher::add(const std::string& name, const Callable& callable, const LLSD& required) +void LLEventDispatcher::add(const std::string& name, const std::string& desc, + const Callable& callable, const LLSD& required) { - mDispatch[name] = DispatchMap::mapped_type(callable, required); + mDispatch.insert(DispatchMap::value_type(name, + DispatchMap::mapped_type(callable, desc, required))); } void LLEventDispatcher::addFail(const std::string& name, const std::string& classname) const @@ -98,14 +100,14 @@ bool LLEventDispatcher::attemptCall(const std::string& name, const LLSD& event) } // Found the name, so it's plausible to even attempt the call. But first, // validate the syntax of the event itself. - std::string mismatch(llsd_matches(found->second.second, event)); + std::string mismatch(llsd_matches(found->second.mRequired, event)); if (! mismatch.empty()) { LL_ERRS("LLEventDispatcher") << "LLEventDispatcher(" << mDesc << ") calling '" << name << "': bad request: " << mismatch << LL_ENDL; } // Event syntax looks good, go for it! - (found->second.first)(event); + (found->second.mFunc)(event); return true; // tell caller we were able to call } @@ -116,7 +118,21 @@ LLEventDispatcher::Callable LLEventDispatcher::get(const std::string& name) cons { return Callable(); } - return found->second.first; + return found->second.mFunc; +} + +LLSD LLEventDispatcher::getMetadata(const std::string& name) const +{ + DispatchMap::const_iterator found = mDispatch.find(name); + if (found == mDispatch.end()) + { + return LLSD(); + } + LLSD meta; + meta["name"] = name; + meta["desc"] = found->second.mDesc; + meta["required"] = found->second.mRequired; + return meta; } LLDispatchListener::LLDispatchListener(const std::string& pumpname, const std::string& key): diff --git a/indra/llcommon/lleventdispatcher.h b/indra/llcommon/lleventdispatcher.h index 5a86b90bff..c8c4fe0c3c 100644 --- a/indra/llcommon/lleventdispatcher.h +++ b/indra/llcommon/lleventdispatcher.h @@ -19,6 +19,7 @@ #include <map> #include <boost/function.hpp> #include <boost/bind.hpp> +#include <boost/iterator/transform_iterator.hpp> #include <typeinfo> #include "llevents.h" @@ -44,7 +45,10 @@ public: * is used to validate the structure of each incoming event (see * llsd_matches()). */ - void add(const std::string& name, const Callable& callable, const LLSD& required=LLSD()); + void add(const std::string& name, + const std::string& desc, + const Callable& callable, + const LLSD& required=LLSD()); /** * Special case: a subclass of this class can pass an unbound member @@ -52,18 +56,32 @@ public: * <tt>boost::bind()</tt> expression. */ template <class CLASS> - void add(const std::string& name, void (CLASS::*method)(const LLSD&), + void add(const std::string& name, + const std::string& desc, + void (CLASS::*method)(const LLSD&), const LLSD& required=LLSD()) { - addMethod<CLASS>(name, method, required); + addMethod<CLASS>(name, desc, method, required); } /// Overload for both const and non-const methods template <class CLASS> - void add(const std::string& name, void (CLASS::*method)(const LLSD&) const, + void add(const std::string& name, + const std::string& desc, + void (CLASS::*method)(const LLSD&) const, const LLSD& required=LLSD()) { - addMethod<CLASS>(name, method, required); + addMethod<CLASS>(name, desc, method, required); + } + + /// Convenience: for LLEventDispatcher, not every callable needs a + /// documentation string. + template <typename CALLABLE> + void add(const std::string& name, + CALLABLE callable, + const LLSD& required=LLSD()) + { + add(name, "", callable, required); } /// Unregister a callable @@ -80,13 +98,51 @@ public: /// @a required prototype specified at add() time, die with LL_ERRS. void operator()(const LLSD& event) const; + /// @name Iterate over defined names + //@{ + typedef std::pair<std::string, std::string> NameDesc; + +private: + struct DispatchEntry + { + DispatchEntry(const Callable& func, const std::string& desc, const LLSD& required): + mFunc(func), + mDesc(desc), + mRequired(required) + {} + Callable mFunc; + std::string mDesc; + LLSD mRequired; + }; + typedef std::map<std::string, DispatchEntry> DispatchMap; + +public: + /// We want the flexibility to redefine what data we store per name, + /// therefore our public interface doesn't expose DispatchMap iterators, + /// or DispatchMap itself, or DispatchEntry. Instead we explicitly + /// transform each DispatchMap item to NameDesc on dereferencing. + typedef boost::transform_iterator<NameDesc(*)(const DispatchMap::value_type&), DispatchMap::const_iterator> const_iterator; + const_iterator begin() const + { + return boost::make_transform_iterator(mDispatch.begin(), makeNameDesc); + } + const_iterator end() const + { + return boost::make_transform_iterator(mDispatch.end(), makeNameDesc); + } + //@} + /// Fetch the Callable for the specified name. If no such name was /// registered, return an empty() Callable. Callable get(const std::string& name) const; + /// Get information about a specific Callable + LLSD getMetadata(const std::string& name) const; + private: template <class CLASS, typename METHOD> - void addMethod(const std::string& name, const METHOD& method, const LLSD& required) + void addMethod(const std::string& name, const std::string& desc, + const METHOD& method, const LLSD& required) { CLASS* downcast = dynamic_cast<CLASS*>(this); if (! downcast) @@ -95,7 +151,7 @@ private: } else { - add(name, boost::bind(method, downcast, _1), required); + add(name, desc, boost::bind(method, downcast, _1), required); } } void addFail(const std::string& name, const std::string& classname) const; @@ -103,8 +159,12 @@ private: bool attemptCall(const std::string& name, const LLSD& event) const; std::string mDesc, mKey; - typedef std::map<std::string, std::pair<Callable, LLSD> > DispatchMap; DispatchMap mDispatch; + + static NameDesc makeNameDesc(const DispatchMap::value_type& item) + { + return NameDesc(item.first, item.second.mDesc); + } }; /** diff --git a/indra/llcommon/llevents.h b/indra/llcommon/llevents.h index 192d79b27d..f52cf33fd8 100644 --- a/indra/llcommon/llevents.h +++ b/indra/llcommon/llevents.h @@ -45,10 +45,12 @@ #include "llsingleton.h" #include "lldependencies.h" +/*==========================================================================*| // override this to allow binding free functions with more parameters #ifndef LLEVENTS_LISTENER_ARITY #define LLEVENTS_LISTENER_ARITY 10 #endif +|*==========================================================================*/ // hack for testing #ifndef testable diff --git a/indra/llcommon/llfoldertype.cpp b/indra/llcommon/llfoldertype.cpp index 9107b11597..079e670b1a 100644 --- a/indra/llcommon/llfoldertype.cpp +++ b/indra/llcommon/llfoldertype.cpp @@ -72,8 +72,7 @@ LLFolderDictionary::LLFolderDictionary() addEntry(LLFolderType::FT_CLOTHING, new FolderEntry("clothing", TRUE)); addEntry(LLFolderType::FT_OBJECT, new FolderEntry("object", TRUE)); addEntry(LLFolderType::FT_NOTECARD, new FolderEntry("notecard", TRUE)); - addEntry(LLFolderType::FT_CATEGORY, new FolderEntry("category", TRUE)); - addEntry(LLFolderType::FT_ROOT_CATEGORY, new FolderEntry("root", TRUE)); + addEntry(LLFolderType::FT_ROOT_INVENTORY, new FolderEntry("root_inv", TRUE)); addEntry(LLFolderType::FT_LSL_TEXT, new FolderEntry("lsltext", TRUE)); addEntry(LLFolderType::FT_BODYPART, new FolderEntry("bodypart", TRUE)); addEntry(LLFolderType::FT_TRASH, new FolderEntry("trash", TRUE)); diff --git a/indra/llcommon/llfoldertype.h b/indra/llcommon/llfoldertype.h index 5374ffd829..7aa77f7f7e 100644 --- a/indra/llcommon/llfoldertype.h +++ b/indra/llcommon/llfoldertype.h @@ -52,23 +52,18 @@ public: FT_LANDMARK = 3, - // FT_SCRIPT = 4, - FT_CLOTHING = 5, FT_OBJECT = 6, FT_NOTECARD = 7, - FT_CATEGORY = 8, - - FT_ROOT_CATEGORY = 9, + FT_ROOT_INVENTORY = 8, + // We'd really like to change this to 9 since AT_CATEGORY is 8, + // but "My Inventory" has been type 8 for a long time. FT_LSL_TEXT = 10, - // FT_LSL_BYTECODE = 11, - // FT_TEXTURE_TGA = 12, - FT_BODYPART = 13, FT_TRASH = 14, @@ -77,16 +72,10 @@ public: FT_LOST_AND_FOUND = 16, - // FT_SOUND_WAV = 17, - // FT_IMAGE_TGA = 18, - // FT_IMAGE_JPEG = 19, - FT_ANIMATION = 20, FT_GESTURE = 21, - // FT_SIMSTATE = 22, - FT_FAVORITE = 23, FT_ENSEMBLE_START = 26, diff --git a/indra/llcommon/llinstancetracker.h b/indra/llcommon/llinstancetracker.h index ea50acbbc5..11fe523651 100644 --- a/indra/llcommon/llinstancetracker.h +++ b/indra/llcommon/llinstancetracker.h @@ -38,42 +38,73 @@ #include "string_table.h" #include <boost/utility.hpp> - -// This mix-in class adds support for tracking all instances of the specified class parameter T -// The (optional) key associates a value of type KEY with a given instance of T, for quick lookup -// If KEY is not provided, then instances are stored in a simple set -// *NOTE: see explicit specialization below for default KEY==T* case +#include <boost/function.hpp> +#include <boost/bind.hpp> +#include <boost/iterator/transform_iterator.hpp> +#include <boost/iterator/indirect_iterator.hpp> + +/// This mix-in class adds support for tracking all instances of the specified class parameter T +/// The (optional) key associates a value of type KEY with a given instance of T, for quick lookup +/// If KEY is not provided, then instances are stored in a simple set +/// @NOTE: see explicit specialization below for default KEY==T* case template<typename T, typename KEY = T*> class LLInstanceTracker : boost::noncopyable { + typedef typename std::map<KEY, T*> InstanceMap; + typedef boost::function<const KEY&(typename InstanceMap::value_type&)> KeyGetter; + typedef boost::function<T*(typename InstanceMap::value_type&)> InstancePtrGetter; public: - typedef typename std::map<KEY, T*>::iterator instance_iter; - typedef typename std::map<KEY, T*>::const_iterator instance_const_iter; - - static T* getInstance(const KEY& k) { instance_iter found = getMap().find(k); return (found == getMap().end()) ? NULL : found->second; } + /// Dereferencing key_iter gives you a const KEY& + typedef boost::transform_iterator<KeyGetter, typename InstanceMap::iterator> key_iter; + /// Dereferencing instance_iter gives you a T& + typedef boost::indirect_iterator< boost::transform_iterator<InstancePtrGetter, typename InstanceMap::iterator> > instance_iter; + + static T* getInstance(const KEY& k) + { + typename InstanceMap::const_iterator found = getMap_().find(k); + return (found == getMap_().end()) ? NULL : found->second; + } - static instance_iter beginInstances() { return getMap().begin(); } - static instance_iter endInstances() { return getMap().end(); } - static S32 instanceCount() { return getMap().size(); } + static key_iter beginKeys() + { + return boost::make_transform_iterator(getMap_().begin(), + boost::bind(&InstanceMap::value_type::first, _1)); + } + static key_iter endKeys() + { + return boost::make_transform_iterator(getMap_().end(), + boost::bind(&InstanceMap::value_type::first, _1)); + } + static instance_iter beginInstances() + { + return instance_iter(boost::make_transform_iterator(getMap_().begin(), + boost::bind(&InstanceMap::value_type::second, _1))); + } + static instance_iter endInstances() + { + return instance_iter(boost::make_transform_iterator(getMap_().end(), + boost::bind(&InstanceMap::value_type::second, _1))); + } + static S32 instanceCount() { return getMap_().size(); } protected: - LLInstanceTracker(KEY key) { add(key); } - virtual ~LLInstanceTracker() { remove(); } - virtual void setKey(KEY key) { remove(); add(key); } + LLInstanceTracker(KEY key) { add_(key); } + virtual ~LLInstanceTracker() { remove_(); } + virtual void setKey(KEY key) { remove_(); add_(key); } virtual const KEY& getKey() const { return mKey; } private: - void add(KEY key) + void add_(KEY key) { mKey = key; - getMap()[key] = static_cast<T*>(this); + getMap_()[key] = static_cast<T*>(this); } - void remove() { getMap().erase(mKey); } + void remove_() { getMap_().erase(mKey); } - static std::map<KEY, T*>& getMap() + static InstanceMap& getMap_() { if (! sInstances) { - sInstances = new std::map<KEY, T*>; + sInstances = new InstanceMap; } return *sInstances; } @@ -81,41 +112,48 @@ private: private: KEY mKey; - static std::map<KEY, T*>* sInstances; + static InstanceMap* sInstances; }; -// explicit specialization for default case where KEY is T* -// use a simple std::set<T*> +/// explicit specialization for default case where KEY is T* +/// use a simple std::set<T*> template<typename T> class LLInstanceTracker<T, T*> { + typedef typename std::set<T*> InstanceSet; public: - typedef typename std::set<T*>::iterator instance_iter; - typedef typename std::set<T*>::const_iterator instance_const_iter; - - static instance_iter beginInstances() { return getSet().begin(); } - static instance_iter endInstances() { return getSet().end(); } - static S32 instanceCount() { return getSet().size(); } + /// Dereferencing key_iter gives you a T* (since T* is the key) + typedef typename InstanceSet::iterator key_iter; + /// Dereferencing instance_iter gives you a T& + typedef boost::indirect_iterator<key_iter> instance_iter; + + /// for completeness of analogy with the generic implementation + static T* getInstance(T* k) { return k; } + static key_iter beginKeys() { return getSet_().begin(); } + static key_iter endKeys() { return getSet_().end(); } + static instance_iter beginInstances() { return instance_iter(getSet_().begin()); } + static instance_iter endInstances() { return instance_iter(getSet_().end()); } + static S32 instanceCount() { return getSet_().size(); } protected: - LLInstanceTracker() { getSet().insert(static_cast<T*>(this)); } - virtual ~LLInstanceTracker() { getSet().erase(static_cast<T*>(this)); } + LLInstanceTracker() { getSet_().insert(static_cast<T*>(this)); } + virtual ~LLInstanceTracker() { getSet_().erase(static_cast<T*>(this)); } - LLInstanceTracker(const LLInstanceTracker& other) { getSet().insert(static_cast<T*>(this)); } + LLInstanceTracker(const LLInstanceTracker& other) { getSet_().insert(static_cast<T*>(this)); } - static std::set<T*>& getSet() // called after getReady() but before go() + static InstanceSet& getSet_() // called after getReady() but before go() { if (! sInstances) { - sInstances = new std::set<T*>; + sInstances = new InstanceSet; } return *sInstances; } - static std::set<T*>* sInstances; + static InstanceSet* sInstances; }; -template <typename T, typename KEY> std::map<KEY, T*>* LLInstanceTracker<T, KEY>::sInstances = NULL; -template <typename T> std::set<T*>* LLInstanceTracker<T, T*>::sInstances = NULL; +template <typename T, typename KEY> typename LLInstanceTracker<T, KEY>::InstanceMap* LLInstanceTracker<T, KEY>::sInstances = NULL; +template <typename T> typename LLInstanceTracker<T, T*>::InstanceSet* LLInstanceTracker<T, T*>::sInstances = NULL; #endif diff --git a/indra/llcommon/llpreprocessor.h b/indra/llcommon/llpreprocessor.h index 48244480b1..bb3301df9f 100644 --- a/indra/llcommon/llpreprocessor.h +++ b/indra/llcommon/llpreprocessor.h @@ -122,6 +122,7 @@ #pragma warning( 3 : 4264 ) // "'virtual_function' : no override available for virtual member function from base 'class'; function is hidden" #pragma warning( 3 : 4265 ) // "class has virtual functions, but destructor is not virtual" #pragma warning( 3 : 4266 ) // 'function' : no override available for virtual member function from base 'type'; function is hidden +#pragma warning (disable : 4180) // qualifier applied to function type has no meaning; ignored #pragma warning( disable : 4284 ) // silly MS warning deep inside their <map> include file #pragma warning( disable : 4503 ) // 'decorated name length exceeded, name was truncated'. Does not seem to affect compilation. #pragma warning( disable : 4800 ) // 'BOOL' : forcing value to bool 'true' or 'false' (performance warning) diff --git a/indra/llcommon/llprocesslauncher.h b/indra/llcommon/llprocesslauncher.h index 880562157f..929d547f6e 100644 --- a/indra/llcommon/llprocesslauncher.h +++ b/indra/llcommon/llprocesslauncher.h @@ -70,6 +70,14 @@ public: // This needs to be called periodically on Mac/Linux to clean up zombie processes. static void reap(void); + + // Accessors for platform-specific process ID +#if LL_WINDOWS + HANDLE getProcessHandle() { return mProcessHandle; }; +#else + pid_t getProcessID() { return mProcessID; }; +#endif + private: std::string mExecutable; std::string mWorkingDir; diff --git a/indra/llcommon/llqueuedthread.cpp b/indra/llcommon/llqueuedthread.cpp index e7ad571a90..eacbbb3ee0 100644 --- a/indra/llcommon/llqueuedthread.cpp +++ b/indra/llcommon/llqueuedthread.cpp @@ -96,6 +96,7 @@ void LLQueuedThread::shutdown() if (req->getStatus() == STATUS_QUEUED || req->getStatus() == STATUS_INPROGRESS) { ++active_count; + req->setStatus(STATUS_ABORTED); // avoid assert in deleteRequest } req->deleteRequest(); } diff --git a/indra/llcommon/llsys.cpp b/indra/llcommon/llsys.cpp index 3652eeba72..cba8cf85b0 100644 --- a/indra/llcommon/llsys.cpp +++ b/indra/llcommon/llsys.cpp @@ -76,6 +76,75 @@ extern int errno; static const S32 CPUINFO_BUFFER_SIZE = 16383; LLCPUInfo gSysCPU; +#if LL_WINDOWS +#ifndef DLLVERSIONINFO
+typedef struct _DllVersionInfo
+{
+ DWORD cbSize;
+ DWORD dwMajorVersion;
+ DWORD dwMinorVersion;
+ DWORD dwBuildNumber;
+ DWORD dwPlatformID;
+}DLLVERSIONINFO;
+#endif
+
+#ifndef DLLGETVERSIONPROC
+typedef int (FAR WINAPI *DLLGETVERSIONPROC) (DLLVERSIONINFO *);
+#endif
+
+bool get_shell32_dll_version(DWORD& major, DWORD& minor, DWORD& build_number)
+{
+ bool result = false;
+ const U32 BUFF_SIZE = 32767;
+ WCHAR tempBuf[BUFF_SIZE];
+ if(GetSystemDirectory((LPWSTR)&tempBuf, BUFF_SIZE))
+ {
+
+ std::basic_string<WCHAR> shell32_path(tempBuf);
+
+ // Shell32.dll contains the DLLGetVersion function.
+ // according to msdn its not part of the API
+ // so you have to go in and get it.
+ // http://msdn.microsoft.com/en-us/library/bb776404(VS.85).aspx
+ shell32_path += TEXT("\\shell32.dll");
+
+ HMODULE hDllInst = LoadLibrary(shell32_path.c_str()); //load the DLL
+ if(hDllInst)
+ { // Could successfully load the DLL
+ DLLGETVERSIONPROC pDllGetVersion;
+ /*
+ You must get this function explicitly because earlier versions of the DLL
+ don't implement this function. That makes the lack of implementation of the
+ function a version marker in itself.
+ */
+ pDllGetVersion = (DLLGETVERSIONPROC) GetProcAddress(hDllInst,
+ "DllGetVersion");
+
+ if(pDllGetVersion)
+ {
+ // DLL supports version retrieval function
+ DLLVERSIONINFO dvi;
+
+ ZeroMemory(&dvi, sizeof(dvi));
+ dvi.cbSize = sizeof(dvi);
+ HRESULT hr = (*pDllGetVersion)(&dvi);
+
+ if(SUCCEEDED(hr))
+ { // Finally, the version is at our hands
+ major = dvi.dwMajorVersion;
+ minor = dvi.dwMinorVersion;
+ build_number = dvi.dwBuildNumber;
+ result = true;
+ }
+ }
+
+ FreeLibrary(hDllInst); // Release DLL
+ }
+ }
+ return result;
+}
+#endif // LL_WINDOWS + LLOSInfo::LLOSInfo() : mMajorVer(0), mMinorVer(0), mBuild(0) { @@ -98,6 +167,11 @@ LLOSInfo::LLOSInfo() : mMinorVer = osvi.dwMinorVersion; mBuild = osvi.dwBuildNumber; + DWORD shell32_major, shell32_minor, shell32_build; + bool got_shell32_version = get_shell32_dll_version(shell32_major, + shell32_minor, + shell32_build); + switch(osvi.dwPlatformId) { case VER_PLATFORM_WIN32_NT: @@ -122,8 +196,22 @@ LLOSInfo::LLOSInfo() : else mOSStringSimple = "Microsoft Windows Server 2003 "; } - else if(osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0) + else if(osvi.dwMajorVersion == 6 && osvi.dwMinorVersion <= 1) { + if(osvi.dwMinorVersion == 0) + { + mOSStringSimple = "Microsoft Windows Vista "; + } + else if(osvi.dwMinorVersion == 1) + { + mOSStringSimple = "Microsoft Windows 7 "; + } + + if(osvi.wProductType != VER_NT_WORKSTATION) + { + mOSStringSimple += "Server "; + } + ///get native system info if available.. typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); ///function pointer for loading GetNativeSystemInfo SYSTEM_INFO si; //System Info object file contains architecture info @@ -141,32 +229,13 @@ LLOSInfo::LLOSInfo() : //of windows than this code does (in case it is needed for the future) if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 ) //check for 64 bit { - if(osvi.wProductType == VER_NT_WORKSTATION) - mOSStringSimple = "Microsoft Windows Vista 64-bit "; - else - mOSStringSimple = "Microsoft Windows Vista Server 64-bit "; + mOSStringSimple += "64-bit "; } else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL ) { - if(osvi.wProductType == VER_NT_WORKSTATION) - mOSStringSimple = "Microsoft Windows Vista 32-bit "; - else - mOSStringSimple = "Microsoft Windows Vista Server 32-bit "; - } - else // PROCESSOR_ARCHITECTURE_IA64 || PROCESSOR_ARCHITECTURE_UNKNOWN not checked - { - if(osvi.wProductType == VER_NT_WORKSTATION) - mOSStringSimple = "Microsoft Windows Vista "; - else - mOSStringSimple = "Microsoft Windows Vista Server "; + mOSStringSimple += "32-bit "; } } - else if(osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1) - { - if(osvi.wProductType == VER_NT_WORKSTATION) - mOSStringSimple = "Microsoft Windows 7 "; - else mOSStringSimple = "Microsoft Windows 7 Server "; - } else // Use the registry on early versions of Windows NT. { mOSStringSimple = "Microsoft Windows (unrecognized) "; @@ -211,6 +280,7 @@ LLOSInfo::LLOSInfo() : csdversion.c_str(), (osvi.dwBuildNumber & 0xffff)); } + mOSString = mOSStringSimple + tmpstr; } break; @@ -240,6 +310,21 @@ LLOSInfo::LLOSInfo() : mOSString = mOSStringSimple; break; } + + std::string compatibility_mode; + if(got_shell32_version) + { + if(osvi.dwMajorVersion != shell32_major + || osvi.dwMinorVersion != shell32_minor) + { + compatibility_mode = llformat(" compatibility mode. real ver: %d.%d (Build %d)", + shell32_major, + shell32_minor, + shell32_build); + } + } + mOSString += compatibility_mode; + #else struct utsname un; if(uname(&un) != -1) diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp index 920d8c0977..37370e44e7 100644 --- a/indra/llcommon/llthread.cpp +++ b/indra/llcommon/llthread.cpp @@ -291,8 +291,8 @@ LLMutex::LLMutex(apr_pool_t *poolp) : LLMutex::~LLMutex() { -#if _DEBUG - llassert(!isLocked()); // better not be locked! +#if MUTEX_DEBUG + llassert_always(!isLocked()); // better not be locked! #endif apr_thread_mutex_destroy(mAPRMutexp); mAPRMutexp = NULL; @@ -306,10 +306,24 @@ LLMutex::~LLMutex() void LLMutex::lock() { apr_thread_mutex_lock(mAPRMutexp); +#if MUTEX_DEBUG + // Have to have the lock before we can access the debug info + U32 id = LLThread::currentID(); + if (mIsLocked[id] != FALSE) + llerrs << "Already locked in Thread: " << id << llendl; + mIsLocked[id] = TRUE; +#endif } void LLMutex::unlock() { +#if MUTEX_DEBUG + // Access the debug info while we have the lock + U32 id = LLThread::currentID(); + if (mIsLocked[id] != TRUE) + llerrs << "Not locked in Thread: " << id << llendl; + mIsLocked[id] = FALSE; +#endif apr_thread_mutex_unlock(mAPRMutexp); } diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h index 932d96d940..d8aa90de2e 100644 --- a/indra/llcommon/llthread.h +++ b/indra/llcommon/llthread.h @@ -128,6 +128,8 @@ protected: //============================================================================ +#define MUTEX_DEBUG (LL_DEBUG || LL_RELEASE_WITH_DEBUG_INFO) + class LL_COMMON_API LLMutex { public: @@ -142,6 +144,9 @@ protected: apr_thread_mutex_t *mAPRMutexp; apr_pool_t *mAPRPoolp; BOOL mIsLocalPool; +#if MUTEX_DEBUG + std::map<U32, BOOL> mIsLocked; +#endif }; // Actually a condition/mutex pair (since each condition needs to be associated with a mutex). diff --git a/indra/llcommon/lltimer.cpp b/indra/llcommon/lltimer.cpp index ea5b0c03ef..ef3e8dbc94 100644 --- a/indra/llcommon/lltimer.cpp +++ b/indra/llcommon/lltimer.cpp @@ -583,13 +583,13 @@ void LLEventTimer::updateClass() std::list<LLEventTimer*> completed_timers; for (instance_iter iter = beginInstances(); iter != endInstances(); ) { - LLEventTimer* timer = *iter++; - F32 et = timer->mEventTimer.getElapsedTimeF32(); - if (timer->mEventTimer.getStarted() && et > timer->mPeriod) { - timer->mEventTimer.reset(); - if ( timer->tick() ) + LLEventTimer& timer = *iter++; + F32 et = timer.mEventTimer.getElapsedTimeF32(); + if (timer.mEventTimer.getStarted() && et > timer.mPeriod) { + timer.mEventTimer.reset(); + if ( timer.tick() ) { - completed_timers.push_back( timer ); + completed_timers.push_back( &timer ); } } } diff --git a/indra/llcommon/tests/llinstancetracker_test.cpp b/indra/llcommon/tests/llinstancetracker_test.cpp new file mode 100644 index 0000000000..7415f2d33b --- /dev/null +++ b/indra/llcommon/tests/llinstancetracker_test.cpp @@ -0,0 +1,160 @@ +/** + * @file llinstancetracker_test.cpp + * @author Nat Goodspeed + * @date 2009-11-10 + * @brief Test for llinstancetracker. + * + * $LicenseInfo:firstyear=2009&license=viewergpl$ + * Copyright (c) 2009, Linden Research, Inc. + * $/LicenseInfo$ + */ + +// Precompiled header +#include "linden_common.h" +// associated header +#include "llinstancetracker.h" +// STL headers +#include <string> +#include <vector> +#include <set> +#include <algorithm> // std::sort() +// std headers +// external library headers +#include <boost/scoped_ptr.hpp> +// other Linden headers +#include "../test/lltut.h" + +struct Keyed: public LLInstanceTracker<Keyed, std::string> +{ + Keyed(const std::string& name): + LLInstanceTracker<Keyed, std::string>(name), + mName(name) + {} + std::string mName; +}; + +struct Unkeyed: public LLInstanceTracker<Unkeyed> +{ +}; + +/***************************************************************************** +* TUT +*****************************************************************************/ +namespace tut +{ + struct llinstancetracker_data + { + }; + typedef test_group<llinstancetracker_data> llinstancetracker_group; + typedef llinstancetracker_group::object object; + llinstancetracker_group llinstancetrackergrp("llinstancetracker"); + + template<> template<> + void object::test<1>() + { + ensure_equals(Keyed::instanceCount(), 0); + { + Keyed one("one"); + ensure_equals(Keyed::instanceCount(), 1); + Keyed* found = Keyed::getInstance("one"); + ensure("couldn't find stack Keyed", found); + ensure_equals("found wrong Keyed instance", found, &one); + { + boost::scoped_ptr<Keyed> two(new Keyed("two")); + ensure_equals(Keyed::instanceCount(), 2); + Keyed* found = Keyed::getInstance("two"); + ensure("couldn't find heap Keyed", found); + ensure_equals("found wrong Keyed instance", found, two.get()); + } + ensure_equals(Keyed::instanceCount(), 1); + } + Keyed* found = Keyed::getInstance("one"); + ensure("Keyed key lives too long", ! found); + ensure_equals(Keyed::instanceCount(), 0); + } + + template<> template<> + void object::test<2>() + { + ensure_equals(Unkeyed::instanceCount(), 0); + { + Unkeyed one; + ensure_equals(Unkeyed::instanceCount(), 1); + Unkeyed* found = Unkeyed::getInstance(&one); + ensure_equals(found, &one); + { + boost::scoped_ptr<Unkeyed> two(new Unkeyed); + ensure_equals(Unkeyed::instanceCount(), 2); + Unkeyed* found = Unkeyed::getInstance(two.get()); + ensure_equals(found, two.get()); + } + ensure_equals(Unkeyed::instanceCount(), 1); + } + ensure_equals(Unkeyed::instanceCount(), 0); + } + + template<> template<> + void object::test<3>() + { + Keyed one("one"), two("two"), three("three"); + // We don't want to rely on the underlying container delivering keys + // in any particular order. That allows us the flexibility to + // reimplement LLInstanceTracker using, say, a hash map instead of a + // std::map. We DO insist that every key appear exactly once. + typedef std::vector<std::string> StringVector; + StringVector keys(Keyed::beginKeys(), Keyed::endKeys()); + std::sort(keys.begin(), keys.end()); + StringVector::const_iterator ki(keys.begin()); + ensure_equals(*ki++, "one"); + ensure_equals(*ki++, "three"); + ensure_equals(*ki++, "two"); + // Use ensure() here because ensure_equals would want to display + // mismatched values, and frankly that wouldn't help much. + ensure("didn't reach end", ki == keys.end()); + + // Use a somewhat different approach to order independence with + // beginInstances(): explicitly capture the instances we know in a + // set, and delete them as we iterate through. + typedef std::set<Keyed*> InstanceSet; + InstanceSet instances; + instances.insert(&one); + instances.insert(&two); + instances.insert(&three); + for (Keyed::instance_iter ii(Keyed::beginInstances()), iend(Keyed::endInstances()); + ii != iend; ++ii) + { + Keyed& ref = *ii; + ensure_equals("spurious instance", instances.erase(&ref), 1); + } + ensure_equals("unreported instance", instances.size(), 0); + } + + template<> template<> + void object::test<4>() + { + Unkeyed one, two, three; + typedef std::set<Unkeyed*> KeySet; + KeySet keys; + keys.insert(&one); + keys.insert(&two); + keys.insert(&three); + for (Unkeyed::key_iter ki(Unkeyed::beginKeys()), kend(Unkeyed::endKeys()); + ki != kend; ++ki) + { + ensure_equals("spurious key", keys.erase(*ki), 1); + } + ensure_equals("unreported key", keys.size(), 0); + + KeySet instances; + instances.insert(&one); + instances.insert(&two); + instances.insert(&three); + for (Unkeyed::instance_iter ii(Unkeyed::beginInstances()), iend(Unkeyed::endInstances()); + ii != iend; ++ii) + { + Unkeyed& ref = *ii; + ensure_equals("spurious instance", instances.erase(&ref), 1); + } + ensure_equals("unreported instance", instances.size(), 0); + } +} // namespace tut diff --git a/indra/llcommon/tests/lltreeiterators_test.cpp b/indra/llcommon/tests/lltreeiterators_test.cpp index d6d9f68110..31c70b4daa 100644 --- a/indra/llcommon/tests/lltreeiterators_test.cpp +++ b/indra/llcommon/tests/lltreeiterators_test.cpp @@ -35,9 +35,6 @@ // Precompiled header #include "linden_common.h" -#if LL_WINDOWS -#pragma warning (disable : 4180) // qualifier applied to function type has no meaning; ignored -#endif // STL headers // std headers |