Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Mar 2012 08:26:32 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r233345 - head/lib/libc/gen
Message-ID:  <201203230826.q2N8QW0m064618@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203230826.q2N8QW0m064618>