From 30ce5ccd62446349d432ff65d3fe8d46872423c8 Mon Sep 17 00:00:00 2001
From: Yi Zhao <yi.zhao@windriver.com>
Date: Wed, 18 Jan 2017 14:59:39 +0800
Subject: [PATCH] fix error for expansion of macro in thread.h

The parameter declaration is missing in expansion of macro
which cause the build error:
| In file included from src/freeradius-devel/libradius.h:80:0,
|                  from src/lib/log.c:26:
| src/lib/log.c: In function '__fr_thread_local_destroy_fr_strerror_buffer':
| src/lib/log.c:37:31: error: 'fr_strerror_buffer' undeclared (first use in this function)
|  fr_thread_local_setup(char *, fr_strerror_buffer) /* macro */
|                                ^

Add the missing declaration in macro.

Upstream-Status: Pending

Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
---
 src/include/threads.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/include/threads.h b/src/include/threads.h
index e36d81dac0..2bcb6aadcb 100644
--- a/src/include/threads.h
+++ b/src/include/threads.h
@@ -89,7 +89,7 @@ static _t __fr_thread_local_init_##_n(pthread_destructor_t func)\
 #  define fr_thread_local_get(_n) _n
 #elif defined(HAVE_PTHREAD_H)
 #  include <pthread.h>
-#  define fr_thread_local_setup(_t, _n) \
+#  define fr_thread_local_setup(_t, _n) static __thread _t _n;\
 static pthread_key_t __fr_thread_local_key_##_n;\
 static pthread_once_t __fr_thread_local_once_##_n = PTHREAD_ONCE_INIT;\
 static pthread_destructor_t __fr_thread_local_destructor_##_n = NULL;\
@@ -100,17 +100,17 @@ static void __fr_thread_local_destroy_##_n(UNUSED void *unused)\
 static void __fr_thread_local_key_init_##_n(void)\
 {\
 	(void) pthread_key_create(&__fr_thread_local_key_##_n, __fr_thread_local_destroy_##_n);\
-	(void) pthread_setspecific(__fr_thread_local_key_##_n, &(_n));\
 }\
 static _t __fr_thread_local_init_##_n(pthread_destructor_t func)\
 {\
 	__fr_thread_local_destructor_##_n = func;\
 	if (_n) return _n; \
 	(void) pthread_once(&__fr_thread_local_once_##_n, __fr_thread_local_key_init_##_n);\
+	(void) pthread_setspecific(__fr_thread_local_key_##_n, &(_n));\
 	return _n;\
 }
-#  define fr_thread_local_init(_n, _f)			__fr_thread_local_init_##_n(_f)
-#  define fr_thread_local_set(_n, _v)			__fr_thread_local_set_##_n(_v)
-#  define fr_thread_local_get(_n)			__fr_thread_local_get_##_n()
+#  define fr_thread_local_init(_n, _f)	__fr_thread_local_init_##_n(_f)
+#  define fr_thread_local_set(_n, _v) ((int)!((_n = _v) || 1))
+#  define fr_thread_local_get(_n) _n
 #endif
 #endif
-- 
2.25.1

