Author: ed
Date: Fri Mar 23 08:26:31 2012
New Revision: 233345
URL: http://svn.freebsd.org/changeset/base/233345

Log:
  Make utmpx(3) thread safe if we support TLS.
  
  Because the utmpx interface is generally not required to be thread-safe,
  but it is nice to have, if easy to do so. Therefore don't make a mess
  out of the code and only use it if __NO_TLS is not defined.

Modified:
  head/lib/libc/gen/getutxent.c
  head/lib/libc/gen/utxdb.c

Modified: head/lib/libc/gen/getutxent.c
==============================================================================
--- head/lib/libc/gen/getutxent.c       Fri Mar 23 07:52:37 2012        
(r233344)
+++ head/lib/libc/gen/getutxent.c       Fri Mar 23 08:26:31 2012        
(r233345)
@@ -38,8 +38,13 @@ __FBSDID("$FreeBSD$");
 #include "utxdb.h"
 #include "un-namespace.h"
 
+#ifdef __NO_TLS
 static FILE *uf = NULL;
 static int udb;
+#else
+static _Thread_local FILE *uf = NULL;
+static _Thread_local int udb;
+#endif
 
 int
 setutxdb(int db, const char *file)

Modified: head/lib/libc/gen/utxdb.c
==============================================================================
--- head/lib/libc/gen/utxdb.c   Fri Mar 23 07:52:37 2012        (r233344)
+++ head/lib/libc/gen/utxdb.c   Fri Mar 23 08:26:31 2012        (r233345)
@@ -126,7 +126,11 @@ utx_to_futx(const struct utmpx *ut, stru
 struct utmpx *
 futx_to_utx(const struct futx *fu)
 {
+#ifdef __NO_TLS
        static struct utmpx *ut;
+#else
+       static _Thread_local struct utmpx *ut;
+#endif
 
        if (ut == NULL) {
                ut = calloc(1, sizeof *ut);
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to