aboutsummaryrefslogtreecommitdiff
path: root/qemu-char.c
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2013-03-27 20:29:39 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2013-04-04 19:21:25 -0500
commit44c473decd4de5559487430f876de53c607b1e9d (patch)
tree8b00d24b4297565dd29de621891b38e32f1706a3 /qemu-char.c
parent4dbb9ed3263e0f48282a2fc3d05099ba63e5b0e2 (diff)
qemu-char: Add qemu_chr_fe_claim / _release helper functions
Add qemu_chr_fe_claim / _release helper functions for properly dealing with avail_connections. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Message-id: 1364412581-3672-2-git-send-email-hdegoede@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'qemu-char.c')
-rw-r--r--qemu-char.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/qemu-char.c b/qemu-char.c
index 505a773330..100f9a968c 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -3452,6 +3452,29 @@ int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond,
return tag;
}
+int qemu_chr_fe_claim(CharDriverState *s)
+{
+ if (s->avail_connections < 1) {
+ return -1;
+ }
+ s->avail_connections--;
+ return 0;
+}
+
+void qemu_chr_fe_claim_no_fail(CharDriverState *s)
+{
+ if (qemu_chr_fe_claim(s) != 0) {
+ fprintf(stderr, "%s: error chardev \"%s\" already used\n",
+ __func__, s->label);
+ exit(1);
+ }
+}
+
+void qemu_chr_fe_release(CharDriverState *s)
+{
+ s->avail_connections++;
+}
+
void qemu_chr_delete(CharDriverState *chr)
{
QTAILQ_REMOVE(&chardevs, chr, next);