aboutsummaryrefslogtreecommitdiff
path: root/util/log.c
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2022-04-17 11:29:47 -0700
committerRichard Henderson <richard.henderson@linaro.org>2022-04-20 10:51:11 -0700
commitc60f599bcb9bf9256eb87c1c60add55d23f76de3 (patch)
tree826787db9c46fdd8c85f1e766e789ae186312e23 /util/log.c
parentc59fe6e536adfb2d6f3410f19d592496933f68de (diff)
util/log: Rename qemu_log_lock to qemu_log_trylock
This function can fail, which makes it more like ftrylockfile or pthread_mutex_trylock than flockfile or pthread_mutex_lock, so rename it. To closer match the other trylock functions, release rcu_read_lock along the failure path, so that qemu_log_unlock need not be called on failure. Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20220417183019.755276-8-richard.henderson@linaro.org>
Diffstat (limited to 'util/log.c')
-rw-r--r--util/log.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/util/log.c b/util/log.c
index 1a3121610a..6b7b358573 100644
--- a/util/log.c
+++ b/util/log.c
@@ -36,15 +36,17 @@ static GArray *debug_regions;
/* Lock/unlock output. */
-FILE *qemu_log_lock(void)
+FILE *qemu_log_trylock(void)
{
QemuLogFile *logfile;
+
rcu_read_lock();
logfile = qatomic_rcu_read(&qemu_logfile);
if (logfile) {
qemu_flockfile(logfile->fd);
return logfile->fd;
} else {
+ rcu_read_unlock();
return NULL;
}
}
@@ -53,8 +55,8 @@ void qemu_log_unlock(FILE *fd)
{
if (fd) {
qemu_funlockfile(fd);
+ rcu_read_unlock();
}
- rcu_read_unlock();
}
/* Return the number of characters emitted. */