]> xenbits.xensource.com Git - people/julieng/freebsd.git/commitdiff
xencons lock
authorJulien Grall <julien.grall@citrix.com>
Sat, 3 Oct 2015 18:27:39 +0000 (19:27 +0100)
committerJulien Grall <julien.grall@citrix.com>
Sat, 3 Oct 2015 18:45:01 +0000 (19:45 +0100)
sys/dev/xen/console/xen_console.c

index 81079608092d9b67024148d21eee15899f139c82..1091f4a4da1b28afa6a7f4fdd59bd76a73c107f1 100644 (file)
@@ -101,18 +101,20 @@ struct xencons_priv {
  * The lock is not used when the kernel is panicing as it will never recover
  * and we want to output no matter what it costs.
  */
-#define CN_LOCK(cons)                                                  \
-               do {                                                    \
-                       if (panicstr == NULL)                           \
-                               mtx_lock_spin(&(cons)->mtx);            \
-               } while (0)
-#define CN_UNLOCK(cons)                                                        \
-               do {                                                    \
-                       if (panicstr == NULL)                           \
-                               mtx_unlock_spin(&(cons)->mtx);          \
-               } while (0)
-#define CN_LOCK_ASSERT(cons)   mtx_assert(&(cons)->mtx, MA_OWNED)
-#define CN_LOCK_DESTROY(cons)  mtx_destroy(&(cons)->mtx)
+static inline void xencons_lock(struct xencons_priv *cons)
+{
+       if (panicstr == NULL)
+               mtx_lock_spin(&cons->mtx);
+
+}
+
+static inline void xencons_unlock(struct xencons_priv *cons)
+{
+       if (panicstr == NULL )
+               mtx_lock_spin(&cons->mtx);
+}
+
+#define xencons_lock_assert(cons)      mtx_assert(&(cons)->mtx, MA_OWNED)
 
 /*
  * Data for the main console
@@ -225,7 +227,7 @@ static int
 xencons_read_hypervisor(struct xencons_priv *cons, const char *buffer,
                        unsigned int size)
 {
-       CN_LOCK_ASSERT(cons);
+       xencons_lock_assert(cons);
 
        return HYPERVISOR_console_io(CONSOLEIO_read, size, buffer);
 }
@@ -305,7 +307,7 @@ xencons_write_ring(struct xencons_priv *cons, const char *buffer,
        XENCONS_RING_IDX wcons, wprod;
        int sent;
 
-       CN_LOCK_ASSERT(cons);
+       xencons_lock_assert(cons);
 
        /* The console page may have not yet been initialized for HVM domain */
        if (__predict_false(!intf))
@@ -340,7 +342,7 @@ xencons_read_ring(struct xencons_priv *cons, char *buffer, unsigned int size)
        XENCONS_RING_IDX rcons, rprod;
        unsigned int rsz;
 
-       CN_LOCK_ASSERT(cons);
+       xencons_lock_assert(cons);
 
        /* The console page may have not yet been initialized for HVM domain */
        if (__predict_false(!intf))
@@ -421,14 +423,14 @@ xencons_rx(struct xencons_priv *cons)
        static char buf[16];
        int sz;
 
-       CN_LOCK(cons);
+       xencons_lock(cons);
        while ((sz = xencons_read(cons, buf, sizeof(buf))) > 0) {
                int i;
 
                for (i = 0; i < sz; i++)
                        cons->rbuf[RBUF_MASK(cons->rp++)] = buf[i];
        }
-       CN_UNLOCK(cons);
+       xencons_unlock(cons);
 }
 
 /* Return true if the write buffer is full */
@@ -437,9 +439,9 @@ xencons_tx_full(struct xencons_priv *cons)
 {
        unsigned int used;
 
-       CN_LOCK(cons);
+       xencons_lock(cons);
        used = cons->wp - cons->wc;
-       CN_UNLOCK(cons);
+       xencons_unlock(cons);
 
        return (used >= WBUF_SIZE);
 }
@@ -449,7 +451,7 @@ xencons_tx_flush(struct xencons_priv *cons, int force)
 {
        int        sz;
 
-       CN_LOCK(cons);
+       xencons_lock(cons);
        while (cons->wc != cons->wp) {
                int sent;
                sz = cons->wp - cons->wc;
@@ -474,16 +476,16 @@ xencons_tx_flush(struct xencons_priv *cons, int force)
 
                cons->wc += sent;
        }
-       CN_UNLOCK(cons);
+       xencons_unlock(cons);
 }
 
 static bool
 xencons_putc(struct xencons_priv *cons, int c, bool force_flush)
 {
-       CN_LOCK(cons);
+       xencons_lock(cons);
        if ((cons->wp - cons->wc) < WBUF_SIZE)
                cons->wbuf[WBUF_MASK(cons->wp++)] = c;
-       CN_UNLOCK(cons);
+       xencons_unlock(cons);
 
        xencons_tx_flush(cons, force_flush);
 
@@ -495,7 +497,7 @@ xencons_getc(struct xencons_priv *cons)
 {
        int ret;
 
-       CN_LOCK(cons);
+       xencons_lock(cons);
        if (cons->rp != cons->rc) {
                /* We need to return only one char */
                ret = (int)cons->rbuf[RBUF_MASK(cons->rc)];
@@ -503,7 +505,7 @@ xencons_getc(struct xencons_priv *cons)
        }
        else
                ret = -1;
-       CN_UNLOCK(cons);
+       xencons_unlock(cons);
 
        return ret;
 }