I'm glad you've managed to join the list, Mark.

The basic approach seems to me a good one. There are a couple of
implementation details that may or may not need discussion.

First, this approach uses a linked list, where the current XMLDeleter model
uses a RefVector. A linked list seems likely to be simple and efficient, but
maybe there's a compelling reason to use a vector that I'm unaware of.

Second, I think that the XMLRegisterCleanup objects should be dynamic rather
than static. The XMLDeleter model makes sense to me: when you perform some
initialization (presumably lazy initialization of global data), you create
and register the corresponding cleanup object. Terminate() then does the
cleanup and deletes each cleanup object. The main advantage to this is that
you call only the required cleanup functions, which can assume that the
corresponding initialization has occurred. Using the static list, all
cleanup functions will always be called, even if the corresponding
initialization never took place. Furthermore, there may be construction
order problems with the static list. The outlined code assumes that
gXMLCleanupList is initialized to NULL somewhere before the
XMLRegisterCleanup constructor is called for the first time. I'm not sure
you can guarantee this happens in the required order.

-jesse-

-----Original Message-----
From: Mark Weaver [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 07, 2001 10:51 AM
To: [EMAIL PROTECTED]
Subject: FW: Problem initializing and terminating XMLPlatformUtils


I've been in discussions outside the list about this, these are my thoughts
on a possible solution - any comments welcome.

Thanks,

Mark

-----Original Message-----
From: Mark Weaver [mailto:[EMAIL PROTECTED]]
Sent: 06 September 2001 14:00
To: [EMAIL PROTECTED]
Subject: RE: Problem initializing and terminating XMLPlatformUtils


Hi,

I've made a partial fix that suited my needs that notifies classes that
lazy data has been cleaned up, it's a little inelegant though (you need to
manually maintain a list of classes to call).  My preferred method would
be to have something like this (sorry about the code, it's just a quick
sketch):

class XMLRegisterCleanup;
extern XMLRegisterCleanup* gXMLCleanupList;

class XMLRegisterCleanup
{
public:
        typedef void (*XMLCleanupFn)();

        XMLRegisterCleanup* next() { return m_nextCleanup; }
        void doCleanup() {
                if (m_cleanupFn) m_cleanupFn();
        }

private:
        XMLRegisterCleanup(XMLCleanupFn cleanupFn) :
                m_cleanupFn(cleanupFn)
        {
                m_nextCleanup = gXMLCleanupList;
                gXMLCleanupList = this;
        }

        XMLCleanupFn m_cleanupFn;
        XMLRegisterCleanup* m_nextCleanup;
};

then, in each module you do:

void myCleanupFunction()
{
        /* free/reset data */
}

/* register my cleanup */
static XMLRegisterCleanup gCleaner(myCleanupFunction);

and finally, in PlatformUtils::Terminate you have:

XMLRegisterCleanup* currCleanup = gXMLCleanupList;
while (currCleanup) {
        currCleanup->clean();
        currCleanup = currCleanup->next();
}

This should simplify the process of implementing new cleanups.

I am happy to implement this, if this is deemed to be the right method, or
to use some other method if pointed in the right direction.  If I read you
correctly, I should also remove the use of XMLDeleterFor<> on these kinds
of objects (e.g. the lazily created mutexes) - I guess this would be
neater than having the object deleted in a location which wasn't the
cleanup function!

Now I have a few questions:

1) How do you subscribe to the mailing list? I've tried sending mail to
the help address & subscribe but I don't seem to be getting any response
2) Who do I submit the patches too, when completed?

Thanks,

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to