From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=34436 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OOtnG-0005g4-HK for qemu-devel@nongnu.org; Wed, 16 Jun 2010 10:40:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OOtnF-0003u1-4Y for qemu-devel@nongnu.org; Wed, 16 Jun 2010 10:40:42 -0400 Received: from e5.ny.us.ibm.com ([32.97.182.145]:51935) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OOtnF-0003tk-2K for qemu-devel@nongnu.org; Wed, 16 Jun 2010 10:40:41 -0400 Received: from d01relay01.pok.ibm.com (d01relay01.pok.ibm.com [9.56.227.233]) by e5.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id o5GENgwY029409 for ; Wed, 16 Jun 2010 10:23:42 -0400 Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay01.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o5GEeedP099988 for ; Wed, 16 Jun 2010 10:40:40 -0400 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o5GEedx2009823 for ; Wed, 16 Jun 2010 10:40:40 -0400 Message-ID: <4C18E266.2030800@linux.vnet.ibm.com> Date: Wed, 16 Jun 2010 09:40:38 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <20100616115404.10988.62371.stgit@localhost.localdomain> <20100616115651.10988.91292.stgit@localhost.localdomain> In-Reply-To: <20100616115651.10988.91292.stgit@localhost.localdomain> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH V4 1/3] qemu: Add qemu-barrier support to qemu-thread framework. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gautham R Shenoy Cc: Paolo Bonzini , Qemu-development List , Corentin Chary , Avi Kivity On 06/16/2010 06:56 AM, Gautham R Shenoy wrote: > Signed-off-by: Gautham R Shenoy > I don't see barrier being used and I don't think it ought to be used. threadlets are meant provide a means to execute a synchronous function asynchronously. It should never be necessary to synchronize threadlets using a barrier. Regards, Anthony Liguori > --- > qemu-thread.c | 23 +++++++++++++++++++++++ > qemu-thread.h | 9 +++++++++ > 2 files changed, 32 insertions(+), 0 deletions(-) > > diff --git a/qemu-thread.c b/qemu-thread.c > index 3923db7..7c445b6 100644 > --- a/qemu-thread.c > +++ b/qemu-thread.c > @@ -161,3 +161,26 @@ int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2) > return pthread_equal(thread1->thread, thread2->thread); > } > > +void qemu_barrier_init(QemuBarrier *barr1, int nr_threads) > +{ > + int err; > + > + err = pthread_barrier_init(&barr1->barr, NULL, nr_threads); > + > + if (err) { > + error_exit(err, __func__); > + } > +} > + > +int qemu_barrier_wait(QemuBarrier *barr1) > +{ > + int ret; > + > + ret = pthread_barrier_wait(&barr1->barr); > + > + if (ret != 0&& ret != PTHREAD_BARRIER_SERIAL_THREAD) { > + error_exit(ret, __func__); > + } > + > + return ret; > +} > diff --git a/qemu-thread.h b/qemu-thread.h > index 5ef4a3a..b3d36e0 100644 > --- a/qemu-thread.h > +++ b/qemu-thread.h > @@ -15,9 +15,14 @@ struct QemuThread { > pthread_t thread; > }; > > +struct QemuBarrier { > + pthread_barrier_t barr; > +}; > + > typedef struct QemuMutex QemuMutex; > typedef struct QemuCond QemuCond; > typedef struct QemuThread QemuThread; > +typedef struct QemuBarrier QemuBarrier; > > void qemu_mutex_init(QemuMutex *mutex); > void qemu_mutex_lock(QemuMutex *mutex); > @@ -31,10 +36,14 @@ void qemu_cond_broadcast(QemuCond *cond); > void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex); > int qemu_cond_timedwait(QemuCond *cond, QemuMutex *mutex, uint64_t msecs); > > +void qemu_barrier_init(QemuBarrier *barr, int nr_threads); > + > void qemu_thread_create(QemuThread *thread, > void *(*start_routine)(void*), > void *arg); > void qemu_thread_signal(QemuThread *thread, int sig); > void qemu_thread_self(QemuThread *thread); > int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2); > + > +int qemu_barrier_wait(QemuBarrier *barr); > #endif > >