sdm: Set robust attribute on mutex object

Off-target SDM tests use a virtual driver which cancels
pthreads at the end of a test. We see instances where various
worker threads are left waiting on mutexes owned by threads that have
exited, although as per source code we are signalling the mutex before
cancel.

In order to robustly handle this situation, we want to set the robust attribute
on the pthread mutex when run in off-target mode. This will gracefully
set any such "orphaned" mutexes to signalled state so that other threads
are not blocked.

We are not setting this robust attribute for on-target version as robust
attribute comes with the requirement that users of pthread mutex
handle the case where owner is dead and transfer ownership explicitly
by calling pthread_make_consistent. Without this special handling, any
such orphaned mutexes will always remain in signalled state that can
cause synchronization to fail. Since this will impact existing
code, we want to limit the impact to off-target only. Please refer
man page for more details
http://manpages.ubuntu.com/manpages/bionic/man3/pthread_mutexattr_setrobust.3.html

Change-Id: I9005d9a8f996afb84b2f144c13db24d9cbe291b6
diff --git a/sdm/include/utils/locker.h b/sdm/include/utils/locker.h
index e0d91cb..48958bc 100755
--- a/sdm/include/utils/locker.h
+++ b/sdm/include/utils/locker.h
@@ -126,7 +126,14 @@
   };
 
   Locker() : sequence_wait_(0) {
+#ifdef SDM_VIRTUAL_DRIVER
+    pthread_mutexattr_t attr;
+    pthread_mutexattr_init(&attr);
+    pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST);
+    pthread_mutex_init(&mutex_, &attr);
+#else
     pthread_mutex_init(&mutex_, 0);
+#endif
     pthread_condattr_init(&cond_attr_);
     pthread_condattr_setclock(&cond_attr_, CLOCK_MONOTONIC);
     pthread_cond_init(&condition_, &cond_attr_);