From 0b4b1219459d123d62d4b6e332781416e73e6666 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Wed, 20 Jul 2016 14:56:49 -0700 Subject: MAINT-6570: Changes for LLCheckedHandle plus some timeout issues from AndreyK regarding script compiles/resets. --- indra/llcommon/llhandle.h | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llhandle.h b/indra/llcommon/llhandle.h index 401e4d759a..dfbfb91fc1 100644 --- a/indra/llcommon/llhandle.h +++ b/indra/llcommon/llhandle.h @@ -213,4 +213,89 @@ private: mutable LLRootHandle mHandle; }; +/* + * $TODO: Derive from LLException + */ +struct LLExeceptionStaleHandle : public std::runtime_error +{ +public: + LLExeceptionStaleHandle(): + std::runtime_error("Attempt to access stale handle.") + {} +}; + +/** + * This is a simple wrapper for Handles, allowing direct calls to the underlying + * pointer. The checked handle will throw a LLExeceptionStaleHandle if an attempt + * is made to access the object referenced by the handle and that object has + * been destroyed. + **/ +template +class LLCheckedHandle: private boost::noncopyable +{ +public: + LLCheckedHandle(LLHandle handle): + mHandle(handle) + { } + + /** + * Retrieve the underlying pointer by resolving the handle. If the handle + * returns NULL for the pointer throw an LLExeceptionStaleHandle exception. + */ + T* get() const + { + T* ptr = mHandle.get(); + if (!ptr) + BOOST_THROW_EXCEPTION(LLExeceptionStaleHandle()); + return ptr; + } + + /** + * Test the handle to see if it is still valid. Returns true if it is, + * false if it is not. Does not trow. + */ + bool test() const + { + return (mHandle.get() != NULL); + } + + /** + * Test the underlying handle. If it is no longer valid, throw a LLExeceptionStaleHandle. + */ + void check() const + { + get(); + } + + /** + * Get the contained handle. + */ + LLHandle getHandle() const + { + return mHandle; + } + + /** + * Converts the LLCheckedHandle to a bool. Allows for if (chkdHandle) {} + * Does not throw. + */ + operator bool() const + { + return test(); + } + + /** + * Attempt to call a method or access a member in the structure referenced + * by the handle. If the handle no longer points to a valid structure + * throw a LLExeceptionStaleHandle. + */ + T* operator ->() const + { + return get(); + } + +private: + LLHandle mHandle; +}; + #endif -- cgit v1.2.3 From d0d07ccac565632497c50510714b30503be8aa94 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Wed, 20 Jul 2016 16:45:17 -0700 Subject: Fix for linux build --- indra/llcommon/llhandle.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llhandle.h b/indra/llcommon/llhandle.h index dfbfb91fc1..98ad7af81a 100644 --- a/indra/llcommon/llhandle.h +++ b/indra/llcommon/llhandle.h @@ -28,8 +28,10 @@ #define LLHANDLE_H #include "llpointer.h" +#include #include #include +#include /** * Helper object for LLHandle. Don't instantiate these directly, used @@ -216,7 +218,7 @@ private: /* * $TODO: Derive from LLException */ -struct LLExeceptionStaleHandle : public std::runtime_error +class LLExeceptionStaleHandle : public std::runtime_error { public: LLExeceptionStaleHandle(): -- cgit v1.2.3 From de438e7512de6dacafee592b89c22c0f062062b6 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Thu, 21 Jul 2016 11:35:24 -0700 Subject: MAINT-6570: Feedback from code review. --- indra/llcommon/llhandle.h | 68 +++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 37 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llhandle.h b/indra/llcommon/llhandle.h index 98ad7af81a..8e073aab27 100644 --- a/indra/llcommon/llhandle.h +++ b/indra/llcommon/llhandle.h @@ -28,6 +28,7 @@ #define LLHANDLE_H #include "llpointer.h" +#include "llexception.h" #include #include #include @@ -215,64 +216,53 @@ private: mutable LLRootHandle mHandle; }; -/* - * $TODO: Derive from LLException - */ -class LLExeceptionStaleHandle : public std::runtime_error + + +class LLCheckedHandleBase { public: - LLExeceptionStaleHandle(): - std::runtime_error("Attempt to access stale handle.") - {} + class Stale : public LLException + { + public: + Stale() : + LLException("Attempt to access stale handle.") + {} + }; + +protected: + LLCheckedHandleBase() { } + }; /** * This is a simple wrapper for Handles, allowing direct calls to the underlying - * pointer. The checked handle will throw a LLExeceptionStaleHandle if an attempt + * pointer. The checked handle will throw a Stale if an attempt * is made to access the object referenced by the handle and that object has * been destroyed. **/ template -class LLCheckedHandle: private boost::noncopyable +class LLCheckedHandle: public LLCheckedHandleBase { public: + LLCheckedHandle(LLHandle handle): mHandle(handle) { } /** - * Retrieve the underlying pointer by resolving the handle. If the handle - * returns NULL for the pointer throw an LLExeceptionStaleHandle exception. + * Test the underlying handle. If it is no longer valid, throw a Stale exception. */ - T* get() const + void check() const { T* ptr = mHandle.get(); if (!ptr) - BOOST_THROW_EXCEPTION(LLExeceptionStaleHandle()); - return ptr; + BOOST_THROW_EXCEPTION(Stale()); } /** - * Test the handle to see if it is still valid. Returns true if it is, - * false if it is not. Does not trow. + * Cast back to an appropriate handle */ - bool test() const - { - return (mHandle.get() != NULL); - } - - /** - * Test the underlying handle. If it is no longer valid, throw a LLExeceptionStaleHandle. - */ - void check() const - { - get(); - } - - /** - * Get the contained handle. - */ - LLHandle getHandle() const + operator LLHandle() const { return mHandle; } @@ -281,22 +271,26 @@ public: * Converts the LLCheckedHandle to a bool. Allows for if (chkdHandle) {} * Does not throw. */ - operator bool() const + explicit operator bool() const { - return test(); + return (mHandle.get() != NULL); } /** * Attempt to call a method or access a member in the structure referenced * by the handle. If the handle no longer points to a valid structure - * throw a LLExeceptionStaleHandle. + * throw a Stale. */ T* operator ->() const { - return get(); + T* ptr = mHandle.get(); + if (!ptr) + BOOST_THROW_EXCEPTION(Stale()); + return ptr; } private: + LLHandle mHandle; }; -- cgit v1.2.3 From 694fe9cfc5a63f825bf77f4630c2da57c16171bf Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Thu, 21 Jul 2016 13:03:40 -0700 Subject: explicit not available for conversion operators in Linux yet --- indra/llcommon/llhandle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llhandle.h b/indra/llcommon/llhandle.h index 8e073aab27..feb5f41848 100644 --- a/indra/llcommon/llhandle.h +++ b/indra/llcommon/llhandle.h @@ -271,7 +271,7 @@ public: * Converts the LLCheckedHandle to a bool. Allows for if (chkdHandle) {} * Does not throw. */ - explicit operator bool() const + /*explicit*/ operator bool() const // explicit conversion operator not available with Linux compiler { return (mHandle.get() != NULL); } -- cgit v1.2.3