Message ID | 20170104172042.GP2016@ovn.org |
---|---|
State | Not Applicable |
Headers | show |
> -----Original Message----- > From: Ben Pfaff [mailto:blp@ovn.org] > Sent: Wednesday, January 4, 2017 7:21 PM > To: Alin Serdean <aserdean@cloudbasesolutions.com> > Cc: dev@openvswitch.org > Subject: Re: [ovs-dev] [PATCH] Windows tests: Applications abort when > using threading (ovs_rwlock_init) > > On Wed, Dec 28, 2016 at 10:27:17PM +0000, Alin Serdean wrote: > > Commit number: 1a15f390afd66efd161db78b86600832214dfb3c > > > https://github.com/openvswitch/ovs/commit/1a15f390afd66efd161db78b86 > 60 > > 0832214dfb3c switched from `NULL` to `attr`. According to POSIX > > documentation this is correct, unfortunately on Windows the current > > implementation of pthreads does not support a pre-initialized > > attribute. Please see a fork of the implementation > > https://github.com/GerHobbelt/pthread- > win32/blob/19fd5054b29af1b4e3b32 > > 78bfffbb6274c6c89f5/pthread_rwlock_init.c#L59-L63 > > This is the same implementation as the official version found under: > > ftp://sourceware.org/pub/pthreads-win32/) > > Thanks. > > I didn't like that this was Windows-specific, since it was possible to make it > generic. > > I changed the patch to the following, and applied it to master. > [Alin Serdean] Much nicer. Thanks!
diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c index 058c434..1f4995b 100644 --- a/lib/ovs-thread.c +++ b/lib/ovs-thread.c @@ -230,21 +230,27 @@ void ovs_rwlock_init(const struct ovs_rwlock *l_) { struct ovs_rwlock *l = CONST_CAST(struct ovs_rwlock *, l_); - pthread_rwlockattr_t attr; int error; l->where = "<unlocked>"; - xpthread_rwlockattr_init(&attr); #ifdef PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP + pthread_rwlockattr_t attr; + xpthread_rwlockattr_init(&attr); xpthread_rwlockattr_setkind_np( &attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP); -#endif error = pthread_rwlock_init(&l->lock, &attr); + xpthread_rwlockattr_destroy(&attr); +#else + /* It is important to avoid passing a rwlockattr in this case because + * Windows pthreads 2.9.1 (and earlier) fail and abort if passed one, even + * one without any special attributes. */ + error = pthread_rwlock_init(&l->lock, NULL); +#endif + if (OVS_UNLIKELY(error)) { ovs_abort(error, "pthread_rwlock_init failed"); } - xpthread_rwlockattr_destroy(&attr); } /* Provides an error-checking wrapper around pthread_cond_wait().