aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2021-01-24 21:46:44 +0100
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2021-01-24 21:46:44 +0100
commit1aaabd1e19f1efcc7f925a40a9784af97a276aa2 (patch)
treecec8f29286f1f9c48a69f71bfca4846aa98ca834
parentcfaccf1ee3bb0a231b9a3373d1e896afaeb6ac3b (diff)
downloadembedlog-1aaabd1e19f1efcc7f925a40a9784af97a276aa2.tar.gz
embedlog-1aaabd1e19f1efcc7f925a40a9784af97a276aa2.tar.bz2
embedlog-1aaabd1e19f1efcc7f925a40a9784af97a276aa2.zip
examples/print-thread-safe.c: add new example code
Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
-rw-r--r--examples/Makefile.am4
-rw-r--r--examples/print-thread-safe.c24
2 files changed, 28 insertions, 0 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 8128f32..38c5963 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -3,24 +3,28 @@ VLDFLAGS =
VLDADD = $(top_builddir)/src/libembedlog.la
EXTRA_PROGRAMS = print_to_file \
+ print_thread_safe \
print_options \
print_simple \
print_memory \
print_tty
print_to_file_SOURCES = print-to-file.c
+print_thread_safe_SOURCES = print-thread-safe.c
print_options_SOURCES = print-options.c
print_simple_SOURCES = print-simple.c
print_memory_SOURCES = print-memory.c
print_tty_SOURCES = print-tty.c
print_to_file_LDFLAGS = $(VLDFLAGS)
+print_thread_safe_LDFLAGS = $(VLDFLAGS)
print_options_LDFLAGS = $(VLDFLAGS)
print_simple_LDFLAGS = $(VLDFLAGS)
print_memory_LDFLAGS = $(VLDFLAGS)
print_tty_LDFLAGS = $(VLDFLAGS)
print_to_file_LDADD = $(VLDADD)
+print_thread_safe_LDADD = $(VLDADD)
print_options_LDADD = $(VLDADD)
print_simple_LDADD = $(VLDADD)
print_memory_LDADD = $(VLDADD)
diff --git a/examples/print-thread-safe.c b/examples/print-thread-safe.c
new file mode 100644
index 0000000..b8813d4
--- /dev/null
+++ b/examples/print-thread-safe.c
@@ -0,0 +1,24 @@
+/* ==========================================================================
+ Licensed under BSD 2clause license See LICENSE file for more information
+ Author: Michał Łyszczek <michal.lyszczek@bofc.pl>
+ ========================================================================== */
+
+#include "embedlog.h"
+
+int main(void)
+{
+ el_init();
+
+ if (el_option(EL_THREAD_SAFE, 1) != 0)
+ {
+ el_perror(ELF, "Failed to enable thread safety");
+ goto error;
+ }
+
+ el_print(ELI, "Yeaaa.... there is no really good way to show");
+ el_print(ELI, "how pthread works in action, so this just checks");
+ el_print(ELI, "whether locking works at all");
+
+error:
+ el_cleanup();
+}