[rhmessaging-commits] rhmessaging commits: r1828 - store/trunk/cpp/lib.
Gordon Sim
gsim at redhat.com
Wed Apr 2 07:41:22 EDT 2008
rhmessaging-commits at lists.jboss.org wrote:
> Author: kpvdr
> Date: 2008-04-01 16:18:44 -0400 (Tue, 01 Apr 2008)
> New Revision: 1828
[...]
> ===================================================================
> --- store/trunk/cpp/lib/JournalImpl.cpp 2008-04-01 19:04:26 UTC (rev 1827)
> +++ store/trunk/cpp/lib/JournalImpl.cpp 2008-04-01 20:18:44 UTC (rev 1828)
> @@ -34,6 +34,7 @@
> using namespace rhm::journal;
>
> qpid::broker::Timer* JournalImpl::journalTimerPtr = 0;
> +u_int32_t JournalImpl::cnt = 0;
>
> void InactivityFireEvent::fire() { if (parent) parent->flushFire(); }
> void GetEventsFireEvent::fire() {
> @@ -64,6 +65,7 @@
> if (journalTimerPtr == 0)
> journalTimerPtr = new qpid::broker::Timer;
> assert (journalTimerPtr != 0);
> + cnt++;
> journalTimerPtr->start();
> journalTimerPtr->add(inactivityFireEventPtr);
>
> @@ -98,7 +100,7 @@
> ::free(_datap);
> _datap = 0;
> }
> - if (journalTimerPtr)
> + if (journalTimerPtr && --cnt == 0)
> {
> delete journalTimerPtr;
> journalTimerPtr = 0;
I believe this change is not threadsafe (unless there is some hiigher
level scheme to prevent Journal instance constructors/destructors being
called concurrently).
Perhaps a lazily initialised shared pointer might be a nice way of doing
that, with each journal instance taking a shared_ptr instance on
construction. If we had a factory class it could hold the singleton
instance via a weak_ptr and provide a method to get an instance. This
method would need to be locked to prevent multiple instances being
created; it would check whether the weak_ptr was valid, and if not
create an instance an initialise it.
More information about the rhmessaging-commits
mailing list