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)
_______________________________________________
Bug-hurd mailing list
Bug-hurd@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-hurd