Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-02-22 11:36:36 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-02-22 11:45:22 +0300
commitb6f8afc13a3116ecbc2c96199076d5d184ddce5a (patch)
tree0d1d293a56601be48b3d42383fafc8c4810519d4 /intern/clog
parent4da53fc3e3025e2d0c337ef4b1aee8f5a7d2c80c (diff)
C logging: make pthread use optional
There is no need for threading for makesrna/makesdna, disable it to avoid hassles linking build time utilities.
Diffstat (limited to 'intern/clog')
-rw-r--r--intern/clog/CMakeLists.txt3
-rw-r--r--intern/clog/clog.c23
2 files changed, 24 insertions, 2 deletions
diff --git a/intern/clog/CMakeLists.txt b/intern/clog/CMakeLists.txt
index e752ffdb623..479723c4cd6 100644
--- a/intern/clog/CMakeLists.txt
+++ b/intern/clog/CMakeLists.txt
@@ -32,4 +32,7 @@ set(SRC
CLG_log.h
)
+# Disabled for makesdna/makesrna.
+add_definitions(-DWITH_CLOG_PTHREADS)
+
blender_add_lib(bf_intern_clog "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/intern/clog/clog.c b/intern/clog/clog.c
index 586cb6963c9..4bc277f8ef2 100644
--- a/intern/clog/clog.c
+++ b/intern/clog/clog.c
@@ -23,7 +23,13 @@
#include <string.h>
#include <stdint.h>
#include <assert.h>
-#include <pthread.h>
+
+/* Disable for small single threaded programs
+ * to avoid having to link with pthreads. */
+#ifdef WITH_CLOG_PTHREADS
+# include <pthread.h>
+# include "atomic_ops.h"
+#endif
/* For 'isatty' to check for color. */
#if defined(__unix__) || defined(__APPLE__) || defined(__HAIKU__)
@@ -40,7 +46,6 @@
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
-#include "atomic_ops.h"
/* Only other dependency (could use regular malloc too). */
#include "MEM_guardedalloc.h"
@@ -71,7 +76,9 @@ typedef struct CLG_IDFilter {
typedef struct CLogContext {
/** Single linked list of types. */
CLG_LogType *types;
+#ifdef WITH_CLOG_PTHREADS
pthread_mutex_t types_lock;
+#endif
/* exclude, include filters. */
CLG_IDFilter *filters[2];
@@ -578,7 +585,9 @@ static void CLG_ctx_level_set(CLogContext *ctx, int level)
static CLogContext *CLG_ctx_init(void)
{
CLogContext *ctx = MEM_callocN(sizeof(*ctx), __func__);
+#ifdef WITH_CLOG_PTHREADS
pthread_mutex_init(&ctx->types_lock, NULL);
+#endif
ctx->use_color = true;
ctx->default_type.level = 1;
CLG_ctx_output_set(ctx, stdout);
@@ -601,7 +610,9 @@ static void CLG_ctx_free(CLogContext *ctx)
MEM_freeN(item);
}
}
+#ifdef WITH_CLOG_PTHREADS
pthread_mutex_destroy(&ctx->types_lock);
+#endif
MEM_freeN(ctx);
}
@@ -678,16 +689,24 @@ void CLG_level_set(int level)
void CLG_logref_init(CLG_LogRef *clg_ref)
{
+#ifdef WITH_CLOG_PTHREADS
/* Only runs once when initializing a static type in most cases. */
pthread_mutex_lock(&g_ctx->types_lock);
+#endif
if (clg_ref->type == NULL) {
CLG_LogType *clg_ty = clg_ctx_type_find_by_name(g_ctx, clg_ref->identifier);
if (clg_ty == NULL) {
clg_ty = clg_ctx_type_register(g_ctx, clg_ref->identifier);
}
+#ifdef WITH_CLOG_PTHREADS
atomic_cas_ptr((void **)&clg_ref->type, clg_ref->type, clg_ty);
+#else
+ clg_ref->type = clg_ty;
+#endif
}
+#ifdef WITH_CLOG_PTHREADS
pthread_mutex_unlock(&g_ctx->types_lock);
+#endif
}
/** \} */