Skip to content

Commit

Permalink
ovs-thread: Avoid pthread_rwlockattr_t on Windows.
Browse files Browse the repository at this point in the history
A recent commit fixed ovs_rwlock_init() to pass the pthread_rwlockattr_t
that it initialized to pthread_rwlock_init().  According to POSIX
documentation this is correct, but 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/19fd5054b29af1b4e3b3278bfffbb6274c6c89f5/pthread_rwlock_init.c#L59-L63
This is the same implementation as the official version found under:
ftp://sourceware.org/pub/pthreads-win32/)

A short debug output from `vswitch` to confirm the above:

>k
 Index  Function
--------------------------------------------------------------------------------
*1      ovs-vswitchd.exe!ovs_rwlock_init(const ovs_rwlock * l_=0x000001721c7da250)
 2      ovs-vswitchd.exe!open_dpif_backer(const char * type=0x000001721c7d8d60, dpif_backer * * backerp=0x000001721c7d89c0)
 3      ovs-vswitchd.exe!construct(ofproto * ofproto_=0x000001721c7d87d0)
 4      ovs-vswitchd.exe!ofproto_create(const char * datapath_name=0x000001721c7d86e0, const char * datapath_type=0x000001721c7d8750, ofproto * * ofprotop=0x000001721c7d80b8)
 5      ovs-vswitchd.exe!bridge_reconfigure(const ovsrec_open_vswitch * ovs_cfg=0x000001721c7e05b0)
 6      ovs-vswitchd.exe!bridge_run()
 7      ovs-vswitchd.exe!main(int argc=6, char * * argv=0x000001721c729e10)
 8      [External Code]

>? error
22
https://github.com/openvswitch/ovs/blob/master/lib/ovs-thread.c#L243

This patch is critical because the majority (over 800) of the unit tests
are failing.

Fixes: 1a15f39 ("lib/ovs-thread: set prefer writer lock for ovs_rwlock_init()")
Signed-off-by: Alin Gabriel Serdean <[email protected]>
Acked-by: Shashank Ram <[email protected]>
[[email protected] changed the details of the approach]
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
Alin Serdean authored and blp committed Jan 4, 2017
1 parent 36924d6 commit 1e4eecb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/ovs-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down

0 comments on commit 1e4eecb

Please sign in to comment.