bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug #18217] glibc: `__libc_once'


From: Barry deFreese
Subject: Re: [bug #18217] glibc: `__libc_once'
Date: Mon, 04 Dec 2006 22:55:10 -0500
User-agent: Thunderbird 1.5.0.8 (Windows/20061025)



Thomas Schwinge wrote:
Follow-up Comment #2, bug #18217 (project hurd):

Roland: ``Uli abused the macros.  To support the use he wants, __libc_once
should be revamped in all its implementations to return a value or have a
variant that does (value says whether fn just ran).''

Is there any reason this wouldn't work?

Current code:

/* Use mutexes as once control variables. */

struct __libc_once
 {
   __libc_lock_t lock;
   int done;
 };

#define __libc_once_define(CLASS,NAME) \
 CLASS struct __libc_once NAME = { MUTEX_INITIALIZER, 0 }

/* Call handler iff the first call.  */
#define __libc_once(ONCE_CONTROL, INIT_FUNCTION) \
do { \ __libc_lock_lock (ONCE_CONTROL.lock); \ if (!ONCE_CONTROL.done) \ (INIT_FUNCTION) (); \ ONCE_CONTROL.done = 1; \ __libc_lock_unlock (ONCE_CONTROL.lock); \
 } while (0)

Change to:

*Remove struct

#define __libc_once_define(CLASS,NAME) \
   CLASS int NAME = MUTEX_INITIALIZER

/* Call handler iff the first call.  */
#define __libc_once(ONCE_CONTROL, INIT_FUNCTION) \
   do {
     __libc_lock_lock(ONCE_CONTROL);
     if ((ONCE_CONTROL) == MUTEX_INITIALIZER)
       (INIT_FUNCTION)();
     ONCE_CONTROL = 1;
     __libc_lock_unlock(ONCE_CONTROL);
   } while (0)

Or am I waaay off as usual?

Thanks!

Barry deFreese (aka bddebian)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]