[PATCH] reorganize list handling of fixable pthread objects

Robert Collins rbcollins@cygwin.com
Wed Mar 19 12:36:00 GMT 2003


On Wed, 2003-03-19 at 21:56, Thomas Pfaff wrote:
> I think that the code could be simplified by making callback a pointer to
> member function.
> 
> void forEach (void (ListNode::*callback) ())
> {
>   ListNode *aNode = head;
>   while (aNode)
>     {
>       (aNode->*callback) ();
>       aNode = aNode->next;
>     }
> }
> 
> With this change you do not need a static to member wrapper function like
> pthread_key::saveAKey.
> 
> You could write
> 
> void pthread_key::fixup_before_fork()
> {
>   keys.forEach (&pthread_key::saveKeyToBuffer);
> }
> 
> void pthread_key::fixup_after_fork()
> {
>   keys.forEach (&pthread_key::recreateKeyFromBuffer);
> }
> 
> void pthread_key::runAllDestructors ()
> {
>   keys.forEach (&pthread_key::runDestructor);
> }
> 
> instead.

For some reason, I forgot that I put in the 'poor mans generic
programming' initially. It just stood out in the patch.

Using a member pointer like that still requires each function to have
the same signature. The for_each I sketched below allows arbitrary
callbacks like using a member function does, but computes them at
compile time which allows for more efficient binary output.

Please apply your patch.

Rob

-- 
GPG key available at: <http://users.bigpond.net.au/robertc/keys.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20030319/e3fce3d8/attachment.sig>


More information about the Cygwin-patches mailing list