[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 1/2] rfifolock: add recursive FIFO lock
From: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-devel] [PATCH 1/2] rfifolock: add recursive FIFO lock |
Date: |
Fri, 11 Oct 2013 15:35:38 +0200 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Fri, Oct 11, 2013 at 04:55:31PM +0800, Wenchao Xia wrote:
> > +/* Recursive FIFO lock
> > + *
> > + * This lock provides more features than a plain mutex:
> > + *
> > + * 1. Fairness - enforces FIFO order.
> > + * 2. Nesting - can be taken recursively.
> > + * 3. Contention callback - optional, called when thread must wait.
> > + *
> > + * The recursive FIFO lock is heavyweight so prefer other synchronization
> > + * primitives if you do not need its features.
> > + */
> > +typedef struct {
> > + QemuMutex lock; /* protects all fields */
> > +
> > + /* FIFO order */
> > + unsigned int head; /* active ticket number */
> > + unsigned int tail; /* waiting ticket number */
> > + QemuCond cond; /* used to wait for our ticket number */
> > +
> > + /* Nesting */
> > + QemuThread owner_thread; /* thread that currently has ownership */
> > + unsigned int nesting; /* amount of nesting levels */
> > +
> > + /* Contention callback */
> > + void (*cb)(void *); /* called when thread must wait, with
> > ->lock
> > + * held so it may not recursively
> > lock/unlock
> > + */
> > + void *cb_opaque;
> > +} RFifoLock;
> > +
> If you respin, the define can be moved to util/rfifolock.c, leave
> typedef struct RFifoLock RFifoLock;
> in header.
Then the struct cannot be embedded as a field, it would require heap
allocation of all RFifoLocks.
This is why I chose to include the definition in the header file.
Stefan
[Qemu-devel] [PATCH 2/2] aio: add aio_context_acquire() and aio_context_release(), Stefan Hajnoczi, 2013/10/09
Re: [Qemu-devel] [PATCH 0/2] aio: add aio_context_acquire() and aio_context_release(), Paolo Bonzini, 2013/10/09