STORM-864: As as developer, I would like an object oriented wrapper to make safe use of memory pools easier
Review Request #99 - Created Jan. 17, 2011 and submitted
Aleric Inglewood | Reviewers | ||
viewer | |||
STORM-864 | |||
None | viewer-development |
Please see http://jira.secondlife.com/browse/STORM-864 I made a mercurial repository available for testing here: hg clone https://bitbucket.org/aleric/viewer-development-storm-864 From the commit message: Introduces a LLThreadLocalData class that can be accessed through the static LLThread::tldata(). Currently this object contains two (public) thread-local objects: a LLAPRRootPool and a LLVolatileAPRPool. The first is the general memory pool used by this thread (and this thread alone), while the second is intended for short lived memory allocations (needed for APR). The advantages of not mixing those two is that the latter is used most frequently, and as a result of it's nature can be destroyed and reconstructed on a "regular" basis. This patch adds LLAPRPool (completely replacing the old one), which is a wrapper around apr_pool_t* and has complete thread-safity checking. Whenever an apr call requires memory for some resource, a memory pool in the form of an LLAPRPool object can be created with the same life-time as this resource; assuring clean up of the memory no sooner, but also not much later than the life-time of the resource that needs the memory. Many, many function calls and constructors had the pool parameter simply removed (it is no longer the concern of the developer, if you don't write code that actually does an libapr call then you are no longer bothered with memory pools at all). However, I kept the notion of short-lived and long-lived allocations alive (see my remark in the jira here: https://jira.secondlife.com/browse/STORM-864?focusedCommentId=235356&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-235356 which requires that the LLAPRFile API needs to allow the user to specify how long they think a file will stay open. By choosing 'short_lived' as default for the constructor that immediately opens a file, the number of instances where this needs to be specified is drastically reduced however (obviously, any automatic LLAPRFile is short lived).
Compiles and viewer functions normally. The new classes (LLAPRPool, LLThreadLocalData) and the LLAPRFile changes have been tested a lot more extensive, since they have been used as-is for months in imprudence and before that in my own viewer (since April). However, the patch contains changes to code elsewhere (to adapt it to the new API) that is rather new in this source tree. Note that changes with regard to LLAPRFile already have been in Snowglobe since version 1.1 (with some minor changes) including the method used to make thread-local data available.
Posted (Jan. 18, 2011, 4:30 a.m.)
I don't feel really qualified to review this, thus just some minor remarks from me:
-
doc/contributions.txt (Diff revision 1) -
This sorting of contribution entries is not related the issue at hand and should thus happen in a separate commit, if at all. Current policy is to not re-sort existing entries at all, to not mislead Oz' metric gathering tools. See Oz' comment on https://codereview.secondlife.com/r/78/ and his clarification in this thread: https://lists.secondlife.com/pipermail/opensource-dev/2011-January/thread.html#5329 I guess this policy might change again once the tools have been made more robust. Please postpone re-sorting jira entries until then.
-
indra/llcommon/llaprpool.h (Diff revision 1) -
I think this comment line is noteworthy enough to show it on doxygen, too. Maybe even within an \attention or \warning .
-
indra/llcommon/llaprpool.h (Diff revision 1) -
Parameters and their behavior can be documented in doxygen with \param . See http://www.doxygen.nl/commands.html#cmdparam
-
indra/llcommon/llaprpool.h (Diff revision 1) -
This could be made a doxygen comment.
-
indra/llcommon/llaprpool.h (Diff revision 1) -
This should probably be a doxygen comment.
-
indra/llcommon/llaprpool.h (Diff revision 1) -
Why include only the first line in doxygen?
-
indra/llcommon/llscopedvolatileaprpool.h (Diff revision 1) -
The first "it's" should be "its".
-
indra/llcommon/llscopedvolatileaprpool.h (Diff revision 1) -
Consider exposing this comment via doxygen.
-
indra/llcommon/llscopedvolatileaprpool.h (Diff revision 1) -
Another candidate for a \warning or \attention ?
-
indra/llcommon/llthread.h (Diff revision 1) -
Another candidate for doxygen. \return could be used.
-
indra/llcommon/llthread.h (Diff revision 1) -
Consider using one line per statement, here.
-
indra/llcommon/llthread.h (Diff revision 1) -
It looks like the #if MUTEX_DEBUG is almost redundant here. I think it will only have an effect when RELEASE_SHOW_ASSERT is set or SHOW_ASSERT has been manually set. Are you sure you want to suppress this specific assertion in these cases?
-
indra/llcommon/llthread.cpp (Diff revision 1) -
Worth inlining?
Review request changed
Updated (Jan. 29, 2011, 9:10 a.m.)
-
- added Diff r2
This new diff incorporates the changes as discussed above, and is updated to be based on revision fe7fe04ccc9a (Fri Jan 28 21:23:35 2011 -0700). I also added comments in this version on every line that correctly uses apr_pool_t, so it's easy to just do a grep on apr_pool_t and check if nobody accidently used that instead of LLAPRPool (in the future). I made this patch (again) available as mercurial repository, here: hg clone https://bitbucket.org/aleric/viewer-development-storm-864 (that is the same name as before, but be warned that I destroyed the old one and created a new repository).
Posted (Jan. 31, 2011, 7:56 p.m.)
First pass and I couldn't see anything wrong with the new structure. It simplifies the code using APR quite a bit and surely makes it more resilient. I'll do a pull and build on a test repo before giving my stamp of approval. It also surely needs to be reviewed by Bao who dealt with that code quite a bit and might have more pointed comments.
-
indra/llcommon/llapr.cpp (Diff revision 2) -
Use "its reference count"
-
indra/llcommon/llaprpool.h (Diff revision 2) -
Ooops! Wrong license. We now use LGPL. Please shange to "license=viewerlgpl"
-
indra/llcommon/llaprpool.h (Diff revision 2) -
The rest of the license should be changed too. Please take example on any currently shipped file for an appropriate header.
-
indra/llcommon/llaprpool.h (Diff revision 2) -
Use "its subpools"
-
indra/llcommon/llaprpool.h (Diff revision 2) -
Use "its parents"
-
indra/llcommon/llaprpool.cpp (Diff revision 2) -
Same comment wrt license as before: use LGPL.
-
indra/llcommon/llaprpool.cpp (Diff revision 2) -
K,it's just a paranoid assert. Still, I'm curious how you came up with the (*4) value. Also, not much point using bitshift here (I know: old habits... :)
-
indra/llcommon/llscopedvolatileaprpool.h (Diff revision 2) -
Same comment on license: use LGPL
Posted (Feb. 2, 2011, 6:30 p.m.)
-
indra/llcommon/llaprpool.h (Diff revision 2) -
I think it's be more clear to use an explicit name like "getAPRPool()" rather than the function operator here. It produces hard to read code in a couple of places and it's just plain unclear what "myPool()" really does.
-
indra/llmessage/llpumpio.cpp (Diff revision 2) -
An example where the use of operator() is particularly unsightly...
Other reviews