Commit d02d9c9d used pthread_mutex to avoid interleaving output. However, the standard provides flockfile() for grouping related FILE* I/O that must not be interleaved; and that may be lighter-weight than rolling our own locking.
Signed-off-by: Eric Blake <[email protected]> --- Pushing this one; as a related conversation on another mailing list reminded me about flockfile(). src/errors.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/errors.c b/src/errors.c index c1efae6..471e3ea 100644 --- a/src/errors.c +++ b/src/errors.c @@ -1,5 +1,5 @@ /* nbdkit - * Copyright (C) 2013-2017 Red Hat Inc. + * Copyright (C) 2013-2018 Red Hat Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -44,21 +44,16 @@ #include "nbdkit-plugin.h" #include "internal.h" -/* Used to group piecemeal message construction into atomic output. */ -static pthread_mutex_t errors_lock = PTHREAD_MUTEX_INITIALIZER; - static void lock (void) { - int r = pthread_mutex_lock (&errors_lock); - assert (!r); + flockfile (stderr); } static void unlock (void) { - int r = pthread_mutex_unlock (&errors_lock); - assert (!r); + funlockfile (stderr); } /* Called with lock taken. */ -- 2.14.3 _______________________________________________ Libguestfs mailing list [email protected] https://www.redhat.com/mailman/listinfo/libguestfs
