Hi, On Saturday 06 June 2015 14:20:38 Richard W.M. Jones wrote:
Since each ACQUIRE_LOCK/RELEASE_LOCK call must balance, this code is difficult to debug. Enable DEBUG_LOCK to add some prints which can help.
There's some way this could be simplified:
const char * guestfs_last_error (guestfs_h *g) { - return g->last_error; + const char *r; + + ACQUIRE_LOCK (g); + r = unlocked_last_error (g); + RELEASE_LOCK (g); + return r; +}
(picking this because it is the first ACQUIRE_LOCK ... RELEASE_LOCK pattern in the patch) there could be an extra macro to do a "stack lock", using the cleanup attribute we use already; something like: static inline guestfs_h *acquire_lock (guestfs_h *g) { ACQUIRE_LOCK (g); return g; } static inline void cleanup_release_lock (void *ptr) { guestfs_h *g = * (guestfs_h **) ptr; RELEASE_LOCK (g); } #define STACK_LOCK (g) \ __attribute__((cleanup(cleanup_release_lock))) \ guestfs_h *_stack_lock_ = acquire_lock (g) then the function above could look like: const char * guestfs_last_error (guestfs_h *g) { STACK_LOCK (g); return g->last_error; } This would have the drawback of requiring __attribute__((cleanup)) to work, although that could mean we could drop the code handling its lack. -- Pino Toscano