[rtems-libbsd commit] mDNS: Use mutex for mDNSPosix platform

Sebastian Huber sebh at rtems.org
Thu Jan 30 15:35:15 UTC 2014


Module:    rtems-libbsd
Branch:    master
Commit:    0543f16e4caa9d146bef31f0b6b86dbc1f3db6c6
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=0543f16e4caa9d146bef31f0b6b86dbc1f3db6c6

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Jan 23 15:28:23 2014 +0100

mDNS: Use mutex for mDNSPosix platform

---

 mDNSResponder/mDNSPosix/mDNSPosix.c |   17 +++++++++++++++++
 mDNSResponder/mDNSPosix/mDNSPosix.h |    6 ++++++
 2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/mDNSResponder/mDNSPosix/mDNSPosix.c b/mDNSResponder/mDNSPosix/mDNSPosix.c
index 953bf64..06a8d47 100755
--- a/mDNSResponder/mDNSPosix/mDNSPosix.c
+++ b/mDNSResponder/mDNSPosix/mDNSPosix.c
@@ -1220,6 +1220,9 @@ mDNSexport mStatus mDNSPlatformInit(mDNS *const m)
 {
     int err = 0;
     struct sockaddr sa;
+#ifdef __rtems__
+    pthread_mutexattr_t attr;
+#endif /* __rtems__ */
     assert(m != NULL);
 
     if (mDNSPlatformInit_CanReceiveUnicast()) m->CanReceiveUnicastOn5353 = mDNStrue;
@@ -1237,6 +1240,12 @@ mDNSexport mStatus mDNSPlatformInit(mDNS *const m)
     if (m->hostlabel.c[0] == 0) MakeDomainLabelFromLiteralString(&m->hostlabel, "Computer");
 
     mDNS_SetFQDN(m);
+#ifdef __rtems__
+    if (err == mStatus_NoError) err = pthread_mutexattr_init(&attr);
+    if (err == mStatus_NoError) err = pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
+    if (err == mStatus_NoError) err = pthread_mutex_init(&m->p->mutex, &attr);
+    if (err == mStatus_NoError) err = pthread_mutexattr_destroy(&attr);
+#endif /* __rtems__ */
 
     sa.sa_family = AF_INET;
     m->p->unicastSocket4 = -1;
@@ -1306,14 +1315,22 @@ mDNSexport mStatus mDNSPlatformPosixRefreshInterfaceList(mDNS *const m)
 // the platform from reentering mDNS core code.
 mDNSexport void    mDNSPlatformLock   (const mDNS *const m)
 {
+#ifndef __rtems__
     (void) m;   // Unused
+#else /* __rtems__ */
+    pthread_mutex_lock(&m->p->mutex);
+#endif /* __rtems__ */
 }
 
 // mDNS core calls this routine when it release the lock taken by
 // mDNSPlatformLock and allow the platform to reenter mDNS core code.
 mDNSexport void    mDNSPlatformUnlock (const mDNS *const m)
 {
+#ifndef __rtems__
     (void) m;   // Unused
+#else /* __rtems__ */
+    pthread_mutex_unlock(&m->p->mutex);
+#endif /* __rtems__ */
 }
 
 #if COMPILER_LIKES_PRAGMA_MARK
diff --git a/mDNSResponder/mDNSPosix/mDNSPosix.h b/mDNSResponder/mDNSPosix/mDNSPosix.h
index f9fcea7..f6dab9e 100755
--- a/mDNSResponder/mDNSPosix/mDNSPosix.h
+++ b/mDNSResponder/mDNSPosix/mDNSPosix.h
@@ -20,6 +20,9 @@
 
 #include <signal.h>
 #include <sys/time.h>
+#ifdef __rtems__
+#include <pthread.h>
+#endif /* __rtems__ */
 
 #ifdef  __cplusplus
 extern "C" {
@@ -54,6 +57,9 @@ struct mDNS_PlatformSupport_struct
 #if HAVE_IPV6
     int unicastSocket6;
 #endif
+#ifdef __rtems__
+    pthread_mutex_t mutex;
+#endif /* __rtems__ */
 };
 
 #define uDNS_SERVERS_FILE "/etc/resolv.conf"




More information about the vc mailing list