projects
/
rrdtool.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
added detail
[rrdtool.git]
/
src
/
rrd_thread_safe.c
diff --git
a/src/rrd_thread_safe.c
b/src/rrd_thread_safe.c
index
ca99202
..
074a873
100644
(file)
--- a/
src/rrd_thread_safe.c
+++ b/
src/rrd_thread_safe.c
@@
-24,49
+24,60
@@
static pthread_once_t context_key_once = PTHREAD_ONCE_INIT;
/* Free the thread-specific rrd_context - we might actually use
rrd_free_context instead...
*/
/* Free the thread-specific rrd_context - we might actually use
rrd_free_context instead...
*/
-static void context_destroy_context(void *ctx_)
+static void context_destroy_context(
+ void *ctx_)
{
struct rrd_context *ctx = ctx_;
{
struct rrd_context *ctx = ctx_;
- if (ctx) rrd_free_context(ctx);
+
+ if (ctx)
+ rrd_free_context(ctx);
}
/* Allocate the key */
}
/* Allocate the key */
-static void context_get_key()
+static void context_get_key(
+ )
{
pthread_key_create(&context_key, context_destroy_context);
}
{
pthread_key_create(&context_key, context_destroy_context);
}
-struct rrd_context *rrd_get_context(void) {
+struct rrd_context *rrd_get_context(
+ void)
+{
struct rrd_context *ctx;
pthread_once(&context_key_once, context_get_key);
ctx = pthread_getspecific(context_key);
if (!ctx) {
struct rrd_context *ctx;
pthread_once(&context_key_once, context_get_key);
ctx = pthread_getspecific(context_key);
if (!ctx) {
- ctx = rrd_new_context();
- pthread_setspecific(context_key, ctx);
- }
+
ctx = rrd_new_context();
+
pthread_setspecific(context_key, ctx);
+ }
return ctx;
}
#ifdef HAVE_STRERROR_R
return ctx;
}
#ifdef HAVE_STRERROR_R
-const char *rrd_strerror(int err) {
+const char *rrd_strerror(
+ int err)
+{
struct rrd_context *ctx = rrd_get_context();
struct rrd_context *ctx = rrd_get_context();
- if (strerror_r(err, ctx->lib_errstr, ctx->errlen))
- return "strerror_r faild. sorry!";
- else
- return ctx->lib_errstr;
+
+ if (strerror_r(err, ctx->lib_errstr, ctx->errlen))
+ return "strerror_r failed. sorry!";
+ else
+ return ctx->lib_errstr;
}
#else
#undef strerror
}
#else
#undef strerror
-const char *rrd_strerror(int err) {
+const char *rrd_strerror(
+ int err)
+{
static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
struct rrd_context *ctx;
static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
struct rrd_context *ctx;
+
ctx = rrd_get_context();
pthread_mutex_lock(&mtx);
strncpy(ctx->lib_errstr, strerror(err), ctx->errlen);
ctx = rrd_get_context();
pthread_mutex_lock(&mtx);
strncpy(ctx->lib_errstr, strerror(err), ctx->errlen);
- ctx->lib_errstr[ctx->errlen]
=
'\0';
+ ctx->lib_errstr[ctx->errlen]
=
'\0';
pthread_mutex_unlock(&mtx);
return ctx->lib_errstr;
}
#endif
pthread_mutex_unlock(&mtx);
return ctx->lib_errstr;
}
#endif
-