svn commit: r233345 - head/lib/libc/gen
Ed Schouten
ed at FreeBSD.org
Fri Mar 23 08:26:32 UTC 2012
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);
More information about the svn-src-all
mailing list