summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Canciani <ranma42@gmail.com>2011-10-01 16:35:16 -0700
committerAndrea Canciani <ranma42@gmail.com>2012-07-31 16:57:45 +0200
commit3e4f6534b02de1405bbaa2b64cf11b815fa3747f (patch)
tree59078b7213735b5619081ae41cfa72a144308963
parent4ef59230222be54b3e3051cefc66cf0a8014e24d (diff)
First version of the simpleops library
The library provides atomic operations, mutexes, TLS and init/fini callbacks in a cross-platform fashion.
-rw-r--r--Makefile.am1
-rw-r--r--Makefile.win321
-rw-r--r--atomic/impl/simpleops-atomic-impl-ao.h117
-rw-r--r--atomic/impl/simpleops-atomic-impl-doc.h244
-rw-r--r--atomic/impl/simpleops-atomic-impl-macosx.h142
-rw-r--r--atomic/impl/simpleops-atomic-impl-msvc.h144
-rw-r--r--atomic/impl/simpleops-atomic-impl-mutex.h171
-rw-r--r--atomic/impl/simpleops-atomic-impl-native.h147
-rw-r--r--atomic/impl/simpleops-atomic-impl-no.h147
-rw-r--r--atomic/impl/simpleops-atomic-impl-template.h103
-rw-r--r--atomic/impl/simpleops-atomic-impl.h50
-rw-r--r--atomic/internal/simpleops-atomic-internal-mutex.h56
-rw-r--r--atomic/internal/simpleops-atomic-internal-template.h52
-rw-r--r--atomic/internal/simpleops-atomic-internal.h56
-rw-r--r--atomic/simpleops-atomic.h35
-rw-r--r--compiler/simpleops-compiler-config.h41
-rw-r--r--compiler/simpleops-compiler-types.h180
-rw-r--r--compiler/simpleops-compiler-utils.h98
-rw-r--r--compiler/simpleops-compiler.h35
-rw-r--r--configure.ac19
-rw-r--r--initfini/impl/simpleops-initfini-impl-attr.h56
-rw-r--r--initfini/impl/simpleops-initfini-impl-common-tail.h37
-rw-r--r--initfini/impl/simpleops-initfini-impl-common.h116
-rw-r--r--initfini/impl/simpleops-initfini-impl-doc.h58
-rw-r--r--initfini/impl/simpleops-initfini-impl-msvc.h98
-rw-r--r--initfini/impl/simpleops-initfini-impl-no.h43
-rw-r--r--initfini/impl/simpleops-initfini-impl-pragma.h58
-rw-r--r--initfini/impl/simpleops-initfini-impl-template.h43
-rw-r--r--initfini/impl/simpleops-initfini-impl-win32.h68
-rw-r--r--initfini/impl/simpleops-initfini-impl.h53
-rw-r--r--initfini/simpleops-initfini.h35
-rw-r--r--m4/ax_c___attribute__.m470
-rw-r--r--m4/ax_c_pragma.m466
-rw-r--r--m4/ax_nodiff_compile_ifelse.m457
-rw-r--r--m4/ax_prefix_config_h.m4217
-rw-r--r--m4/ax_pthread.m4288
-rw-r--r--m4/simpleops_atomic.m481
-rw-r--r--m4/simpleops_compiler.m48
-rw-r--r--m4/simpleops_initfini.m413
-rw-r--r--m4/simpleops_mutex.m410
-rw-r--r--m4/simpleops_public.m412
-rw-r--r--m4/simpleops_thread.m49
-rw-r--r--m4/simpleops_tls.m49
-rw-r--r--mutex/impl/simpleops-mutex-impl-beos.h77
-rw-r--r--mutex/impl/simpleops-mutex-impl-doc.h110
-rw-r--r--mutex/impl/simpleops-mutex-impl-no.h70
-rw-r--r--mutex/impl/simpleops-mutex-impl-os2.h79
-rw-r--r--mutex/impl/simpleops-mutex-impl-pthread.h82
-rw-r--r--mutex/impl/simpleops-mutex-impl-template.h70
-rw-r--r--mutex/impl/simpleops-mutex-impl-win32.h78
-rw-r--r--mutex/impl/simpleops-mutex-impl.h49
-rw-r--r--mutex/simpleops-mutex.h35
-rw-r--r--template/impl/simpleops-template-impl-template.h43
-rw-r--r--template/impl/simpleops-template-impl.h48
-rw-r--r--template/internal/simpleops-template-internal-template.h52
-rw-r--r--template/internal/simpleops-template-internal.h59
-rw-r--r--template/simpleops-impl.h40
-rw-r--r--template/simpleops-internal.h39
-rw-r--r--template/simpleops-template.h35
-rw-r--r--template/simpleops.h40
-rw-r--r--thread/impl/simpleops-thread-impl-doc.h90
-rw-r--r--thread/impl/simpleops-thread-impl-no.h59
-rw-r--r--thread/impl/simpleops-thread-impl-pthread.h61
-rw-r--r--thread/impl/simpleops-thread-impl-template.h57
-rw-r--r--thread/impl/simpleops-thread-impl-win32.h123
-rw-r--r--thread/impl/simpleops-thread-impl.h47
-rw-r--r--thread/simpleops-thread.h35
-rw-r--r--tls/impl/simpleops-tls-impl-common-tail.h154
-rw-r--r--tls/impl/simpleops-tls-impl-common.h47
-rw-r--r--tls/impl/simpleops-tls-impl-doc.h61
-rw-r--r--tls/impl/simpleops-tls-impl-no.h55
-rw-r--r--tls/impl/simpleops-tls-impl-pthread.h60
-rw-r--r--tls/impl/simpleops-tls-impl-template.h53
-rw-r--r--tls/impl/simpleops-tls-impl-win32.h62
-rw-r--r--tls/impl/simpleops-tls-impl.h50
-rw-r--r--tls/internal/simpleops-tls-internal-common.h37
-rw-r--r--tls/internal/simpleops-tls-internal-pthread.h58
-rw-r--r--tls/internal/simpleops-tls-internal-template.h52
-rw-r--r--tls/internal/simpleops-tls-internal-win32.h58
-rw-r--r--tls/internal/simpleops-tls-internal.h60
-rw-r--r--tls/req/simpleops-tls-req-template.h42
-rw-r--r--tls/req/simpleops-tls-req-win32.h46
-rw-r--r--tls/req/simpleops-tls-req.h42
-rw-r--r--tls/simpleops-tls.h35
84 files changed, 5794 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..cd8c1fa
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1 @@
+ACLOCAL_AMFLAGS = -I m4
diff --git a/Makefile.win32 b/Makefile.win32
new file mode 100644
index 0000000..2da5801
--- /dev/null
+++ b/Makefile.win32
@@ -0,0 +1 @@
+SIMPLEOPS_LIBS = Kernel32.lib
diff --git a/atomic/impl/simpleops-atomic-impl-ao.h b/atomic/impl/simpleops-atomic-impl-ao.h
new file mode 100644
index 0000000..d1d2732
--- /dev/null
+++ b/atomic/impl/simpleops-atomic-impl-ao.h
@@ -0,0 +1,117 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2007 Chris Wilson
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ * Chris Wilson <chris@chris-wilson.co.uk>
+ */
+
+#ifndef SIMPLEOPS_ATOMIC_IMPL_AO_H
+#define SIMPLEOPS_ATOMIC_IMPL_AO_H
+
+#ifndef SIMPLEOPS_ATOMIC_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_ATOMIC_IMPL && \
+ SIMPLEOPS_HAVE_ATOMIC_OPS_H
+
+#define SIMPLEOPS_HAVE_ATOMIC_IMPL 1
+#define SIMPLEOPS_HAVE_ATOMIC_IMPL_AO 1
+
+#include <atomic_ops.h>
+
+SIMPLEOPS_COMPILE_TIME_ASSERT(sizeof (void *) == sizeof (AO_t));
+
+/* Atomic integer functions */
+typedef AO_t simpleops_atomic_int_t;
+
+
+static simpleops_always_inline simpleops_bool_t
+simpleops_atomic_int_compare_exchange (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t oldv,
+ simpleops_atomic_int_t newv)
+{
+ return AO_compare_and_swap_full (x, oldv, newv);
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_exchange (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t newv)
+{
+ return _InterlockedExchange (x, newv);
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_load (simpleops_atomic_int_t const volatile *x)
+{
+ return AO_load_full (x);
+}
+
+static simpleops_always_inline void
+simpleops_atomic_int_store (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t newv)
+{
+ AO_store_full (x, newv);
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_fetch_add (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t y)
+{
+ return AO_fetch_and_add_full (x, y);
+}
+
+/* Atomic pointer functions */
+static simpleops_always_inline simpleops_bool_t
+simpleops_atomic_ptr_compare_exchange (void * volatile *x,
+ void * const oldv,
+ void * const newv)
+{
+ return AO_compare_and_swap_full ((AO_t *) x, (AO_t) oldv, (AO_t) newv);
+}
+
+static simpleops_always_inline void *
+simpleops_atomic_ptr_exchange (void * volatile *x,
+ void * const newv)
+{
+ return _InterlockedExchangePointer (x, newv);
+}
+
+static simpleops_always_inline void *
+simpleops_atomic_ptr_load (void * const volatile *x)
+{
+ return (void *) AO_load_full ((AO_t * const) x);
+}
+
+static simpleops_always_inline void
+simpleops_atomic_ptr_store (void * volatile *x,
+ void * const newv)
+{
+ AO_store_full ((AO_t *) x, (AO_t) newv)
+}
+
+#endif
+
+#endif
diff --git a/atomic/impl/simpleops-atomic-impl-doc.h b/atomic/impl/simpleops-atomic-impl-doc.h
new file mode 100644
index 0000000..7a98948
--- /dev/null
+++ b/atomic/impl/simpleops-atomic-impl-doc.h
@@ -0,0 +1,244 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2007 Chris Wilson
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ * Chris Wilson <chris@chris-wilson.co.uk>
+ */
+
+#ifndef SIMPLEOPS_ATOMIC_IMPL_DOC_H
+#define SIMPLEOPS_ATOMIC_IMPL_DOC_H
+
+#ifndef SIMPLEOPS_ATOMIC_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_ATOMIC_IMPL && \
+ SIMPLEOPS_DOC
+
+/**
+ * Defined whenever the simpleops library is providing an
+ * implementation of atomic operations.
+ *
+ * Using atomic operations it is possible to avoid race conditions
+ * when performing concurrent access to shared data without the need
+ * for mutexes, which are typically much more expensive.
+ */
+#define SIMPLEOPS_HAVE_ATOMIC_IMPL 1
+
+/**
+ * SIMPLEOPS_HAVE_ATOMIC_IMPL_* identifies which implementation is
+ * being used in the simpleops library to provide atomic operations.
+ */
+#define SIMPLEOPS_HAVE_ATOMIC_IMPL_DOC 1
+
+/* Atomic integer functions */
+/**
+ * The type on which atomic aritmetic operations can be performed.
+ *
+ * It is guaranteed to be able to represent at least all the int
+ * values.
+ */
+typedef int simpleops_atomic_int_t;
+
+/**
+ * Perform an atomic compare and swap on a #simpleops_atomic_int_t.
+ *
+ * If the value pointed by x is oldv, replace it with newv.
+ *
+ * \param[in,out] x the destination.
+ * \param[in] oldv the old value to be found at x.
+ * \param[in] newv the new value to be set at x.
+ *
+ * \return whether the exchange happened.
+ */
+static simpleops_always_inline simpleops_bool_t
+simpleops_atomic_int_compare_exchange (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t oldv,
+ simpleops_atomic_int_t newv)
+{
+ simpleops_bool_t r;
+
+ r = *x == oldv;
+ if (r)
+ *x = newv;
+
+ return r;
+}
+
+/**
+ * Perform an atomic swap on a #simpleops_atomic_int_t.
+ *
+ * Set the value pointed by x to newv.
+ *
+ * \param[in,out] x the destination.
+ * \param[in] newv the new value to be set at x.
+ *
+ * \return the old value at x.
+ */
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_exchange (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t newv)
+{
+ simpleops_atomic_int_t r;
+
+ r = *x;
+ *x = newv;
+
+ return r;
+}
+
+/**
+ * Perform an atomic load on a #simpleops_atomic_int_t.
+ *
+ * \param[in] x a pointer to the #simpleops_atomic_int_t to be read.
+ *
+ * \return the value pointed by x.
+ */
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_load (simpleops_atomic_int_t const volatile *x)
+{
+ simpleops_atomic_int_t r;
+
+ r = *x;
+
+ return r;
+}
+
+/**
+ * Perform an atomic store on a #simpleops_atomic_int_t.
+ *
+ * \param[out] x the destination.
+ * \param[in] newv the value to be set at x.
+ */
+static simpleops_always_inline void
+simpleops_atomic_int_store (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t newv)
+{
+ *x = newv;
+}
+
+/**
+ * Perform an atomic addition.
+ *
+ * Add y to the value pointed by x.
+ *
+ * \param[in,out] x the destination.
+ * \param[in] y the value to be added to the value found at x.
+ *
+ * \return the old value at x.
+ */
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_fetch_add (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t y)
+{
+ simpleops_atomic_int_t r;
+
+ r = *x;
+ *x += y;
+
+ return r;
+}
+
+/* Atomic pointer functions */
+/**
+ * Perform an atomic compare and swap on a pointer.
+ *
+ * If the value pointed by x is oldv, replace it with newv.
+ *
+ * \param[in,out] x the destination.
+ * \param[in] oldv the old value to be found at x.
+ * \param[in] newv the new value to be set at x.
+ *
+ * \return whether the exchange happened.
+ */
+static simpleops_always_inline simpleops_bool_t
+simpleops_atomic_ptr_compare_exchange (void * volatile *x,
+ void * const oldv,
+ void * const newv)
+{
+ simpleops_bool_t r;
+
+ r = *x == oldv;
+ if (r)
+ *x = newv;
+
+ return r;
+}
+
+/**
+ * Perform an atomic swap on a pointer.
+ *
+ * Set the value pointed by x to newv.
+ *
+ * \param[in,out] x the destination.
+ * \param[in] newv the new value to be set at x.
+ *
+ * \return the old value at x.
+ */
+static simpleops_always_inline void *
+simpleops_atomic_ptr_exchange (void * volatile *x,
+ void * const newv)
+{
+ void *r;
+
+ r = *x;
+ *x = newv;
+
+ return r;
+}
+
+/**
+ * Perform an atomic load on a pointer.
+ *
+ * \param[in] x a pointer to the pointer to be read.
+ *
+ * \return the value pointed by x.
+ */
+static simpleops_always_inline void *
+simpleops_atomic_ptr_load (void * const volatile *x)
+{
+ void *r;
+
+ r = *x;
+
+ return r;
+}
+
+/**
+ * Perform an atomic store on a pointer.
+ *
+ * \param[out] x the destination.
+ * \param[in] newv the value to be set at x.
+ */
+static simpleops_always_inline void
+simpleops_atomic_ptr_store (void * volatile *x,
+ void * const newv)
+{
+ *x = newv;
+}
+
+#endif
+
+#endif
diff --git a/atomic/impl/simpleops-atomic-impl-macosx.h b/atomic/impl/simpleops-atomic-impl-macosx.h
new file mode 100644
index 0000000..4848405
--- /dev/null
+++ b/atomic/impl/simpleops-atomic-impl-macosx.h
@@ -0,0 +1,142 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2007 Chris Wilson
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ * Chris Wilson <chris@chris-wilson.co.uk>
+ */
+
+#ifndef SIMPLEOPS_ATOMIC_IMPL_MACOSX_H
+#define SIMPLEOPS_ATOMIC_IMPL_MACOSX_H
+
+#ifndef SIMPLEOPS_ATOMIC_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_ATOMIC_IMPL && \
+ SIMPLEOPS_HAVE_LIBKERN_OSATOMIC_H
+
+#define SIMPLEOPS_HAVE_ATOMIC_IMPL 1
+#define SIMPLEOPS_HAVE_ATOMIC_IMPL_MACOSX 1
+
+#include <libkern/OSAtomic.h>
+
+static simpleops_always_inline void
+_simpleops_atomic_barrier (void)
+{
+#if SIMPLEOPS_ATOMIC_IMPL_NEEDS_MEMORY_BARRIER
+ OSMemoryBarrier ();
+#endif
+}
+
+/* Atomic integer functions */
+typedef int32_t simpleops_atomic_int_t;
+
+static simpleops_always_inline simpleops_bool_t
+simpleops_atomic_int_compare_exchange (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t oldv,
+ simpleops_atomic_int_t newv)
+{
+ return OSAtomicCompareAndSwap32Barrier (oldv, newv, x);
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_exchange (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t newv)
+{
+ simpleops_atomic_int_t r;
+
+ _simpleops_atomic_barrier ();
+
+ do {
+ r = *x;
+ } while (! simpleops_atomic_int_compare_exchange (x, r, newv));
+
+ return r;
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_load (simpleops_atomic_int_t const volatile *x)
+{
+ _simpleops_atomic_barrier ();
+ return *x;
+}
+
+static simpleops_always_inline void
+simpleops_atomic_int_store (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t newv)
+{
+ _simpleops_atomic_barrier ();
+ *x = newv;
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_fetch_add (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t y)
+{
+ return OSAtomicAdd32Barrier (y, x) - y;
+}
+
+/* Atomic pointer functions */
+static simpleops_always_inline simpleops_bool_t
+simpleops_atomic_ptr_compare_exchange (void * volatile *x,
+ void * const oldv,
+ void * const newv)
+{
+ return OSAtomicCompareAndSwapPtrBarrier ((void *) oldv, (void *) newv, x);
+}
+
+static simpleops_always_inline void *
+simpleops_atomic_ptr_exchange (void * volatile *x,
+ void * const newv)
+{
+ void *r;
+
+ _simpleops_atomic_barrier ();
+
+ do {
+ r = *x;
+ } while (! simpleops_atomic_ptr_compare_exchange (x, r, newv));
+
+ return r;
+}
+
+static simpleops_always_inline void *
+simpleops_atomic_ptr_load (void * const volatile *x)
+{
+ _simpleops_atomic_barrier ();
+ return *x;
+}
+
+static simpleops_always_inline void
+simpleops_atomic_ptr_store (void * volatile *x,
+ void * const newv)
+{
+ _simpleops_atomic_barrier ();
+ *x = newv;
+}
+
+#endif
+
+#endif
diff --git a/atomic/impl/simpleops-atomic-impl-msvc.h b/atomic/impl/simpleops-atomic-impl-msvc.h
new file mode 100644
index 0000000..c584bbe
--- /dev/null
+++ b/atomic/impl/simpleops-atomic-impl-msvc.h
@@ -0,0 +1,144 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2007 Chris Wilson
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ * Chris Wilson <chris@chris-wilson.co.uk>
+ */
+
+#ifndef SIMPLEOPS_ATOMIC_IMPL_MSVC_H
+#define SIMPLEOPS_ATOMIC_IMPL_MSVC_H
+
+#ifndef SIMPLEOPS_ATOMIC_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_ATOMIC_IMPL && \
+ defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
+
+#define SIMPLEOPS_HAVE_ATOMIC_IMPL 1
+#define SIMPLEOPS_HAVE_ATOMIC_IMPL_WIN32 1
+
+#include <intrin.h>
+
+#pragma intrinsic (_InterlockedCompareExchange)
+#pragma intrinsic (_InterlockedExchange)
+#pragma intrinsic (_InterlockedExchangeAdd)
+#pragma intrinsic (_ReadWriteBarrier)
+
+#ifdef _M_X64
+#pragma intrinsic (_InterlockedCompareExchangePointer)
+#pragma intrinsic (_InterlockedExchangePointer)
+#endif
+
+static simpleops_always_inline void
+_simpleops_atomic_barrier (void)
+{
+#if SIMPLEOPS_ATOMIC_IMPL_NEEDS_MEMORY_BARRIER
+ _ReadWriteBarrier ();
+#endif
+}
+
+/* Atomic integer functions */
+typedef long simpleops_atomic_int_t;
+
+static simpleops_always_inline simpleops_bool_t
+simpleops_atomic_int_compare_exchange (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t oldv,
+ simpleops_atomic_int_t newv)
+{
+ return _InterlockedCompareExchange (x, newv, oldv) == oldv;
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_exchange (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t newv)
+{
+ return _InterlockedExchange (x, newv);
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_load (simpleops_atomic_int_t const volatile *x)
+{
+ _simpleops_atomic_barrier ();
+ return *x;
+}
+
+static simpleops_always_inline void
+simpleops_atomic_int_store (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t newv)
+{
+ _simpleops_atomic_barrier ();
+ *x = newv;
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_fetch_add (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t y)
+{
+ return _InterlockedExchangeAdd (x, y);
+}
+
+/* Atomic pointer functions */
+static simpleops_always_inline simpleops_bool_t
+simpleops_atomic_ptr_compare_exchange (void * volatile *x,
+ void * const oldv,
+ void * const newv)
+{
+#ifdef _M_X64
+ return _InterlockedCompareExchangePointer (x, newv, oldv) == oldv;
+#else
+ return _InterlockedCompareExchangePointer (x, (int) newv, (int) oldv) == (int) oldv;
+#endif
+}
+
+static simpleops_always_inline void *
+simpleops_atomic_ptr_exchange (void * volatile *x,
+ void * const newv)
+{
+#ifdef _M_X64
+ return _InterlockedExchangePointer (x, newv);
+#else
+ return (void *) _InterlockedExchangePointer (x, (int) newv);
+#endif
+}
+
+static simpleops_always_inline void *
+simpleops_atomic_ptr_load (void * const volatile *x)
+{
+ _simpleops_atomic_barrier ();
+ return *x;
+}
+
+static simpleops_always_inline void
+simpleops_atomic_ptr_store (void * volatile *x,
+ void * const newv)
+{
+ _simpleops_atomic_barrier ();
+ *x = newv;
+}
+
+#endif
+
+#endif
diff --git a/atomic/impl/simpleops-atomic-impl-mutex.h b/atomic/impl/simpleops-atomic-impl-mutex.h
new file mode 100644
index 0000000..9c76704
--- /dev/null
+++ b/atomic/impl/simpleops-atomic-impl-mutex.h
@@ -0,0 +1,171 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2007 Chris Wilson
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ * Chris Wilson <chris@chris-wilson.co.uk>
+ */
+
+#ifndef SIMPLEOPS_ATOMIC_IMPL_MUTEX_H
+#define SIMPLEOPS_ATOMIC_IMPL_MUTEX_H
+
+#ifndef SIMPLEOPS_ATOMIC_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_ATOMIC_IMPL && \
+ 1 /* TODO: Do we want to warn about slow "atomics"? */
+
+#define SIMPLEOPS_HAVE_ATOMIC_IMPL 1
+#define SIMPLEOPS_HAVE_ATOMIC_IMPL_MUTEX 1
+
+#include "simpleops/mutex/simpleops-mutex.h"
+
+#define _SIMPLEOPS_ATOMIC_MUTEX SIMPLEOPS_ADD_PREFIX (_simpleops_atomic_mutex)
+
+extern simpleops_mutex_t _SIMPLEOPS_ATOMIC_MUTEX;
+
+/* Atomic integer functions */
+typedef int simpleops_atomic_int_t;
+
+static simpleops_always_inline simpleops_bool_t
+simpleops_atomic_int_compare_exchange (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t oldv,
+ simpleops_atomic_int_t newv)
+{
+ simpleops_bool_t r;
+
+ simpleops_mutex_lock (&_SIMPLEOPS_ATOMIC_MUTEX);
+ r = *x == oldv;
+ if (r)
+ *x = newv;
+ simpleops_mutex_unlock (&_SIMPLEOPS_ATOMIC_MUTEX);
+
+ return r;
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_exchange (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t newv)
+{
+ simpleops_atomic_int_t r;
+
+ simpleops_mutex_lock (&_SIMPLEOPS_ATOMIC_MUTEX);
+ r = *x;
+ *x = newv;
+ simpleops_mutex_unlock (&_SIMPLEOPS_ATOMIC_MUTEX);
+
+ return r;
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_load (simpleops_atomic_int_t const volatile *x)
+{
+ simpleops_atomic_int_t r;
+
+ simpleops_mutex_lock (&_SIMPLEOPS_ATOMIC_MUTEX);
+ r = *x;
+ simpleops_mutex_unlock (&_SIMPLEOPS_ATOMIC_MUTEX);
+
+ return r;
+}
+
+static simpleops_always_inline void
+simpleops_atomic_int_store (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t newv)
+{
+ simpleops_mutex_lock (&_SIMPLEOPS_ATOMIC_MUTEX);
+ *x = newv;
+ simpleops_mutex_unlock (&_SIMPLEOPS_ATOMIC_MUTEX);
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_fetch_add (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t y)
+{
+ simpleops_atomic_int_t r;
+
+ simpleops_mutex_lock (&_SIMPLEOPS_ATOMIC_MUTEX);
+ r = *x;
+ *x += y;
+ simpleops_mutex_unlock (&_SIMPLEOPS_ATOMIC_MUTEX);
+
+ return r;
+}
+
+/* Atomic pointer functions */
+static simpleops_always_inline simpleops_bool_t
+simpleops_atomic_ptr_compare_exchange (void * volatile *x,
+ void * const oldv,
+ void * const newv)
+{
+ simpleops_bool_t r;
+
+ simpleops_mutex_lock (&_SIMPLEOPS_ATOMIC_MUTEX);
+ r = *x == oldv;
+ if (r)
+ *x = newv;
+ simpleops_mutex_unlock (&_SIMPLEOPS_ATOMIC_MUTEX);
+
+ return r;
+}
+
+static simpleops_always_inline void *
+simpleops_atomic_ptr_exchange (void * volatile *x,
+ void * const newv)
+{
+ void *r;
+
+ simpleops_mutex_lock (&_SIMPLEOPS_ATOMIC_MUTEX);
+ r = *x;
+ *x = newv;
+ simpleops_mutex_unlock (&_SIMPLEOPS_ATOMIC_MUTEX);
+
+ return r;
+}
+
+static simpleops_always_inline void *
+simpleops_atomic_ptr_load (void * const volatile *x)
+{
+ void *r;
+
+ simpleops_mutex_lock (&_SIMPLEOPS_ATOMIC_MUTEX);
+ r = *x;
+ simpleops_mutex_unlock (&_SIMPLEOPS_ATOMIC_MUTEX);
+
+ return r;
+}
+
+static simpleops_always_inline void
+simpleops_atomic_ptr_store (void * volatile *x,
+ void * const newv)
+{
+ simpleops_mutex_lock (&_SIMPLEOPS_ATOMIC_MUTEX);
+ *x = newv;
+ simpleops_mutex_unlock (&_SIMPLEOPS_ATOMIC_MUTEX);
+}
+
+#endif
+
+#endif
diff --git a/atomic/impl/simpleops-atomic-impl-native.h b/atomic/impl/simpleops-atomic-impl-native.h
new file mode 100644
index 0000000..4c58e72
--- /dev/null
+++ b/atomic/impl/simpleops-atomic-impl-native.h
@@ -0,0 +1,147 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2007 Chris Wilson
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ * Chris Wilson <chris@chris-wilson.co.uk>
+ */
+
+#ifndef SIMPLEOPS_ATOMIC_IMPL_NATIVE_H
+#define SIMPLEOPS_ATOMIC_IMPL_NATIVE_H
+
+#ifndef SIMPLEOPS_ATOMIC_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_ATOMIC_IMPL && \
+ SIMPLEOPS_HAVE_NATIVE_ATOMIC_PRIMITIVES
+
+#define SIMPLEOPS_HAVE_ATOMIC_IMPL 1
+#define SIMPLEOPS_HAVE_ATOMIC_IMPL_NATIVE 1
+
+static simpleops_always_inline void _simpleops_atomic_barrier (void)
+{
+#if SIMPLEOPS_ATOMIC_IMPL_NEEDS_MEMORY_BARRIER
+ __sync_synchronize ();
+#endif
+}
+
+/* Atomic integer functions */
+typedef int simpleops_atomic_int_t;
+
+static simpleops_always_inline simpleops_bool_t
+simpleops_atomic_int_compare_exchange (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t oldv,
+ simpleops_atomic_int_t newv)
+{
+ return __sync_bool_compare_and_swap (x, oldv, newv);
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_exchange (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t newv)
+{
+#if SIMPLEOPS_HAVE_NATIVE_ATOMIC_SWAP
+ return __sync_swap (x, newv);
+#else
+ simpleops_atomic_int_t r;
+
+ _simpleops_atomic_barrier ();
+
+ do {
+ r = *x;
+ } while (! simpleops_atomic_int_compare_exchange (x, r, newv));
+
+ return r;
+#endif
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_load (simpleops_atomic_int_t const volatile *x)
+{
+ _simpleops_atomic_barrier ();
+ return *x;
+}
+
+static simpleops_always_inline void
+simpleops_atomic_int_store (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t newv)
+{
+ _simpleops_atomic_barrier ();
+ *x = newv;
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_fetch_add (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t y)
+{
+ return __sync_fetch_and_add (x, y);
+}
+
+/* Atomic pointer functions */
+static simpleops_always_inline simpleops_bool_t
+simpleops_atomic_ptr_compare_exchange (void * volatile *x,
+ void * const oldv,
+ void * const newv)
+{
+ return __sync_bool_compare_and_swap (x, oldv, newv);
+}
+
+static simpleops_always_inline void *
+simpleops_atomic_ptr_exchange (void * volatile *x,
+ void * const newv)
+{
+#if SIMPLEOPS_HAVE_SYNC_SWAP
+ return __sync_swap (x, newv);
+#else
+ void *r;
+
+ _simpleops_atomic_barrier ();
+
+ do {
+ r = *x;
+ } while (! simpleops_atomic_ptr_compare_exchange (x, r, newv));
+
+ return r;
+#endif
+}
+
+static simpleops_always_inline void *
+simpleops_atomic_ptr_load (void * const volatile *x)
+{
+ _simpleops_atomic_barrier ();
+ return *x;
+}
+
+static simpleops_always_inline void
+simpleops_atomic_ptr_store (void * volatile *x,
+ void * const newv)
+{
+ _simpleops_atomic_barrier ();
+ *x = newv;
+}
+
+#endif
+
+#endif
diff --git a/atomic/impl/simpleops-atomic-impl-no.h b/atomic/impl/simpleops-atomic-impl-no.h
new file mode 100644
index 0000000..84e2ad9
--- /dev/null
+++ b/atomic/impl/simpleops-atomic-impl-no.h
@@ -0,0 +1,147 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2007 Chris Wilson
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ * Chris Wilson <chris@chris-wilson.co.uk>
+ */
+
+#ifndef SIMPLEOPS_ATOMIC_IMPL_NO_H
+#define SIMPLEOPS_ATOMIC_IMPL_NO_H
+
+#ifndef SIMPLEOPS_ATOMIC_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_ATOMIC_IMPL && \
+ defined(SIMPLEOPS_DISABLE_ATOMIC)
+
+#define SIMPLEOPS_HAVE_ATOMIC_IMPL 1
+#define SIMPLEOPS_HAVE_ATOMIC_IMPL_NO 1
+
+/* Atomic integer functions */
+typedef int simpleops_atomic_int_t;
+
+static simpleops_always_inline simpleops_bool_t
+simpleops_atomic_int_compare_exchange (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t oldv,
+ simpleops_atomic_int_t newv)
+{
+ simpleops_bool_t r;
+
+ r = *x == oldv;
+ if (r)
+ *x = newv;
+
+ return r;
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_exchange (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t newv)
+{
+ simpleops_atomic_int_t r;
+
+ r = *x;
+ *x = newv;
+
+ return r;
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_load (simpleops_atomic_int_t const volatile *x)
+{
+ simpleops_atomic_int_t r;
+
+ r = *x;
+
+ return r;
+}
+
+static simpleops_always_inline void
+simpleops_atomic_int_store (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t newv)
+{
+ *x = newv;
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_fetch_add (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t y)
+{
+ simpleops_atomic_int_t r;
+
+ r = *x;
+ *x += y;
+
+ return r;
+}
+
+/* Atomic pointer functions */
+static simpleops_always_inline simpleops_bool_t
+simpleops_atomic_ptr_compare_exchange (void * volatile *x,
+ void * const oldv,
+ void * const newv)
+{
+ simpleops_bool_t r;
+
+ r = *x == oldv;
+ if (r)
+ *x = newv;
+
+ return r;
+}
+
+static simpleops_always_inline void *
+simpleops_atomic_ptr_exchange (void * volatile *x,
+ void * const newv)
+{
+ void *r;
+
+ r = *x;
+ *x = newv;
+
+ return r;
+}
+
+static simpleops_always_inline void *
+simpleops_atomic_ptr_load (void * const volatile *x)
+{
+ void *r;
+
+ r = *x;
+
+ return r;
+}
+
+static simpleops_always_inline void
+simpleops_atomic_ptr_store (void * volatile *x,
+ void * const newv)
+{
+ *x = newv;
+}
+
+#endif
+
+#endif
diff --git a/atomic/impl/simpleops-atomic-impl-template.h b/atomic/impl/simpleops-atomic-impl-template.h
new file mode 100644
index 0000000..9cb9ce8
--- /dev/null
+++ b/atomic/impl/simpleops-atomic-impl-template.h
@@ -0,0 +1,103 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2007 Chris Wilson
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ * Chris Wilson <chris@chris-wilson.co.uk>
+ */
+
+#ifndef SIMPLEOPS_ATOMIC_IMPL_TEMPLATE_H
+#define SIMPLEOPS_ATOMIC_IMPL_TEMPLATE_H
+
+#ifndef SIMPLEOPS_ATOMIC_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_ATOMIC_IMPL && \
+ 0
+
+#define SIMPLEOPS_HAVE_ATOMIC_IMPL 1
+#define SIMPLEOPS_HAVE_ATOMIC_IMPL_TEMPLATE 1
+
+/* Atomic integer functions */
+typedef int simpleops_atomic_int_t;
+
+static simpleops_always_inline simpleops_bool_t
+simpleops_atomic_int_compare_exchange (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t oldv,
+ simpleops_atomic_int_t newv)
+{
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_exchange (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t newv)
+{
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_load (simpleops_atomic_int_t const volatile *x)
+{
+}
+
+static simpleops_always_inline void
+simpleops_atomic_int_store (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t newv)
+{
+}
+
+static simpleops_always_inline simpleops_atomic_int_t
+simpleops_atomic_int_fetch_add (simpleops_atomic_int_t volatile *x,
+ simpleops_atomic_int_t y)
+{
+}
+
+/* Atomic pointer functions */
+static simpleops_always_inline simpleops_bool_t
+simpleops_atomic_ptr_compare_exchange (void * volatile *x,
+ void * const oldv,
+ void * const newv)
+{
+}
+
+static simpleops_always_inline void *
+simpleops_atomic_ptr_exchange (void * volatile *x,
+ void * const newv)
+{
+}
+
+static simpleops_always_inline void *
+simpleops_atomic_ptr_load (void * const volatile *x)
+{
+}
+
+static simpleops_always_inline void
+simpleops_atomic_ptr_store (void * volatile *x,
+ void * const newv)
+{
+}
+
+#endif
+
+#endif
diff --git a/atomic/impl/simpleops-atomic-impl.h b/atomic/impl/simpleops-atomic-impl.h
new file mode 100644
index 0000000..01358ed
--- /dev/null
+++ b/atomic/impl/simpleops-atomic-impl.h
@@ -0,0 +1,50 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_ATOMIC_IMPL_H
+#define SIMPLEOPS_ATOMIC_IMPL_H
+
+#ifndef SIMPLEOPS_ATOMIC_H
+#error Private header used directly
+#endif
+
+/* DIFFTABLE */
+#include "simpleops/atomic/impl/simpleops-atomic-impl-template.h"
+#include "simpleops/atomic/impl/simpleops-atomic-impl-doc.h"
+#include "simpleops/atomic/impl/simpleops-atomic-impl-no.h"
+#include "simpleops/atomic/impl/simpleops-atomic-impl-native.h"
+#include "simpleops/atomic/impl/simpleops-atomic-impl-msvc.h"
+#include "simpleops/atomic/impl/simpleops-atomic-impl-macosx.h"
+#include "simpleops/atomic/impl/simpleops-atomic-impl-ao.h"
+#include "simpleops/atomic/impl/simpleops-atomic-impl-mutex.h"
+/* DIFFTABLE */
+
+#if ! SIMPLEOPS_HAVE_ATOMIC_IMPL
+#error No implementation available
+#endif
+
+#endif
diff --git a/atomic/internal/simpleops-atomic-internal-mutex.h b/atomic/internal/simpleops-atomic-internal-mutex.h
new file mode 100644
index 0000000..8f41b59
--- /dev/null
+++ b/atomic/internal/simpleops-atomic-internal-mutex.h
@@ -0,0 +1,56 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_ATOMIC_INTERNAL_MUTEX_H
+#define SIMPLEOPS_ATOMIC_INTERNAL_MUTEX_H
+
+#ifndef SIMPLEOPS_ATOMIC_INTERNAL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_ATOMIC_INTERNAL && \
+ SIMPLEOPS_HAVE_ATOMIC_IMPL_MUTEX
+
+#define SIMPLEOPS_HAVE_ATOMIC_INTERNAL 1
+
+simpleops_private simpleops_mutex_t _SIMPLEOPS_ATOMIC_MUTEX;
+
+static simpleops_always_inline void
+_simpleops_atomic_init (void)
+{
+ simpleops_mutex_init (&_SIMPLEOPS_ATOMIC_MUTEX);
+}
+
+static simpleops_always_inline void
+_simpleops_atomic_fini (void)
+{
+ simpleops_mutex_fini (&_SIMPLEOPS_ATOMIC_MUTEX);
+}
+
+#endif
+
+#endif
diff --git a/atomic/internal/simpleops-atomic-internal-template.h b/atomic/internal/simpleops-atomic-internal-template.h
new file mode 100644
index 0000000..1e5fadc
--- /dev/null
+++ b/atomic/internal/simpleops-atomic-internal-template.h
@@ -0,0 +1,52 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_ATOMIC_INTERNAL_TEMPLATE_H
+#define SIMPLEOPS_ATOMIC_INTERNAL_TEMPLATE_H
+
+#ifndef SIMPLEOPS_ATOMIC_INTERNAL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_ATOMIC_INTERNAL && \
+ SIMPLEOPS_HAVE_ATOMIC_IMPL_TEMPLATE
+
+#define SIMPLEOPS_HAVE_ATOMIC_INTERNAL 1
+
+static simpleops_always_inline void
+_simpleops_atomic_init (void)
+{
+}
+
+static simpleops_always_inline void
+_simpleops_atomic_fini (void)
+{
+}
+
+#endif
+
+#endif
diff --git a/atomic/internal/simpleops-atomic-internal.h b/atomic/internal/simpleops-atomic-internal.h
new file mode 100644
index 0000000..367c3b8
--- /dev/null
+++ b/atomic/internal/simpleops-atomic-internal.h
@@ -0,0 +1,56 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_ATOMIC_INTERNAL_H
+#define SIMPLEOPS_ATOMIC_INTERNAL_H
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_COMMON_H
+#error Private header used directly
+#endif
+
+#include "simpleops/atomic/simpleops-atomic.h"
+
+/* DIFFTABLE */
+#include "simpleops/atomic/internal/simpleops-atomic-internal-template.h"
+#include "simpleops/atomic/internal/simpleops-atomic-internal-mutex.h"
+/* DIFFTABLE */
+
+#if ! SIMPLEOPS_HAVE_ATOMIC_INTERNAL
+
+static simpleops_always_inline void
+_simpleops_atomic_init (void)
+{
+}
+
+static simpleops_always_inline void
+_simpleops_atomic_fini (void)
+{
+}
+
+#endif
+
+#endif
diff --git a/atomic/simpleops-atomic.h b/atomic/simpleops-atomic.h
new file mode 100644
index 0000000..c517a60
--- /dev/null
+++ b/atomic/simpleops-atomic.h
@@ -0,0 +1,35 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_ATOMIC_H
+#define SIMPLEOPS_ATOMIC_H
+
+#include "simpleops/compiler/simpleops-compiler.h"
+
+#include "simpleops/atomic/impl/simpleops-atomic-impl.h"
+
+#endif
diff --git a/compiler/simpleops-compiler-config.h b/compiler/simpleops-compiler-config.h
new file mode 100644
index 0000000..adb54c8
--- /dev/null
+++ b/compiler/simpleops-compiler-config.h
@@ -0,0 +1,41 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_COMPILER_CONFIG_H
+#define SIMPLEOPS_COMPILER_CONFIG_H
+
+#ifndef SIMPLEOPS_COMPILER_H
+#error Private header used directly
+#endif
+
+#ifdef _MSC_VER
+/* TODO */
+#else
+#include "simpleops/simpleops-config.h"
+#endif
+
+#endif
diff --git a/compiler/simpleops-compiler-types.h b/compiler/simpleops-compiler-types.h
new file mode 100644
index 0000000..15248da
--- /dev/null
+++ b/compiler/simpleops-compiler-types.h
@@ -0,0 +1,180 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_COMPILER_TYPES_H
+#define SIMPLEOPS_COMPILER_TYPES_H
+
+#ifndef SIMPLEOPS_COMPILER_H
+#error Private header used directly
+#endif
+
+/**
+ * The type of boolean values returned by simpleops functions.
+ */
+typedef int simpleops_bool_t;
+
+#ifndef FALSE
+/**
+ * The false boolean value.
+ */
+#define FALSE 0
+#endif
+
+#ifndef TRUE
+/**
+ * The true boolean value.
+ */
+#define TRUE (! FALSE)
+#endif
+
+#if defined(_MSC_VER)
+#define simpleops_inline __inline
+#else
+/**
+ * An attribute or type qualifier that hints to the compiler that the
+ * function might be appropriate for inlining.
+ *
+ * This is only a hint, the compiler can choose to ignore it.
+ */
+#define simpleops_inline inline
+#endif
+
+#if defined(_MSC_VER)
+#define simpleops_always_inline simpleops_inline __forceinline
+#elif SIMPLEOPS_HAVE_ATTRIBUTE_ALWAYS_INLINE
+#define simpleops_always_inline simpleops_inline __attribute__((always_inline))
+#else
+/**
+ * An attribute or type qualifier that requires to the compiler to
+ * inline the function.
+ *
+ * This is stronger than simpleops_inline, as it asks to the compiler
+ * to inline the function even if this worsen the performance of the
+ * code.
+ */
+#define simpleops_always_inline simpleops_inline
+#endif
+
+#if defined(_MSC_VER)
+#define simpleops_noinline __declspec(noinline)
+#elif SIMPLEOPS_HAVE_ATTRIBUTE_NOINLINE
+#define simpleops_noinline __attribute__((noinline))
+#else
+/**
+ * An attribute or type qualifier that requests to the compiler to
+ * svoid inlining the function.
+ *
+ * This is conflicting with simpleops_always_inline and
+ * simpleops_inline.
+ */
+#define simpleops_noinline
+#endif
+
+#if SIMPLEOPS_HAVE_ATTRIBUTE_CONST
+#define simpleops_const __attribute__((const))
+#else
+/**
+ * An attribute that informs the compiler that the function does not
+ * examine any value except those of its arguments.
+ *
+ * This is stronger than simpleops_pure, as const functions are not
+ * allowed to read global state (for example, const functions cannot
+ * dereference pointers).
+ */
+#define simpleops_const
+#endif
+
+#if SIMPLEOPS_HAVE_ATTRIBUTE_PURE
+#define simpleops_pure __attribute__((pure))
+#else
+/**
+ * An attribute that informs the compiler that the function has no
+ * side effects and that the return value only depends on its
+ * arguments and global state.
+ *
+ * Pure functions are not allowed to read global state, but their
+ * behavior should not change depending on system resources and they
+ * should not diverge. For example, memcmp() is a pure function,
+ * time() is not.
+ */
+#define simpleops_pure
+#endif
+
+#endif
+
+/* The following definitions are outside of the
+ * SIMPLEOPS_COMPILER_TYPES_H #if to allow libraries using simpleops
+ * to import symbols from other libraries using simpleops without
+ * conflicts.
+ */
+
+#undef _simpleops_import
+#undef _simpleops_export
+#undef simpleops_private
+#undef simpleops_public
+
+#if defined(_MSC_VER) && defined(SIMPLEOPS_DLL)
+#define _simpleops_import __declspec(dllimport)
+#define _simpleops_export __declspec(dllexport)
+#define simpleops_private
+#elif defined(__GNUC__) && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3))
+#define _simpleops_import extern
+#define _simpleops_export __attribute__((__visibility__("default")))
+#define simpleops_private __attribute__((__visibility__("hidden")))
+#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
+#define _simpleops_import extern
+#define _simpleops_export __global
+#define simpleops_private __hidden
+#else
+#define _simpleops_import extern
+#define _simpleops_export
+/**
+ * An attribute that informs the compiler that the function is
+ * private, i.e. it should not be visible outside the library.
+ */
+#define simpleops_private
+#endif
+
+#ifdef SIMPLEOPS_EXPORT_PUBLIC
+#define simpleops_public _simpleops_export
+#else
+/**
+ * An attribute that informs the compiler that the function is public.
+ *
+ * When declaring symbols in the library, the
+ * SIMPLEOPS_EXPORT_PUBLIC macro should be defined, so that the
+ * public symbols are exported.
+ *
+ * When declaring symbols of an external library (usually by
+ * including its headers), SIMPLEOPS_EXPORT_PUBLIC should NOT be
+ * defined, so that the functions are imported.
+ *
+ * If the symbols being declared belong to a DLL, the SIMPLEOPS_DLL
+ * macro should be defined, too.
+ */
+#define simpleops_public _simpleops_import
+#endif
diff --git a/compiler/simpleops-compiler-utils.h b/compiler/simpleops-compiler-utils.h
new file mode 100644
index 0000000..187386d
--- /dev/null
+++ b/compiler/simpleops-compiler-utils.h
@@ -0,0 +1,98 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_COMPILER_UTILS_H
+#define SIMPLEOPS_COMPILER_UTILS_H
+
+#ifndef SIMPLEOPS_COMPILER_H
+#error Private header used directly
+#endif
+
+/**
+ * Computes the number of elements of an array
+ */
+#define SIMPLEOPS_ARRAY_LENGTH(x) (sizeof (x) / sizeof (x[0]))
+
+#define _SIMPLEOPS_CONCAT(x,y) x ## y
+#define _SIMPLEOPS_RESOLVE_CONCAT(x,y) _SIMPLEOPS_CONCAT(x,y)
+
+/**
+ * Prepends the SIMPLEOPS_PREFIX to the argument.
+ *
+ * This macro is used to generate non-static identifiers that do not
+ * collide across multiple libraries. In order to use it,
+ * SIMPLEOPS_PREFIX should be defined to an appropriate identifier.
+ */
+#define SIMPLEOPS_ADD_PREFIX(x) _SIMPLEOPS_RESOLVE_CONCAT(SIMPLEOPS_PREFIX, x)
+
+#define _SIMPLEOPS_COMPILE_TIME_RAW_ASSERT(condition, line) \
+ typedef int compile_time_assertion_at_line_##line##_failed [(condition)?1:-1]
+#define _SIMPLEOPS_COMPILE_TIME_RESOLVE_ASSERT(condition, line) \
+ _SIMPLEOPS_COMPILE_TIME_RAW_ASSERT(condition, line)
+
+/**
+ * Asserts that the condition is TRUE at compile time.
+ *
+ * Conditions that cannot be evaluated at compile time cannot be used
+ * in these assertions.
+ */
+#define SIMPLEOPS_COMPILE_TIME_ASSERT(condition) \
+ _SIMPLEOPS_COMPILE_TIME_RESOLVE_ASSERT(condition, __LINE__)
+
+
+#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
+
+#define _SIMPLEOPS_BOOLEAN_EXPR(expr) ((expr) ? TRUE : FALSE)
+
+#define SIMPLEOPS_LIKELY(expr) \
+ (__builtin_expect (_SIMPLEOPS_BOOLEAN_EXPR (expr), TRUE))
+#define SIMPLEOPS_UNLIKELY(expr) \
+ (__builtin_expect (_SIMPLEOPS_BOOLEAN_EXPR (expr), FALSE))
+
+#else
+
+/**
+ * Provides an hint to the compiler that the expression is probably
+ * going to be TRUE and evaluates to the value of the expression.
+ */
+#define SIMPLEOPS_LIKELY(expr) (expr)
+
+/**
+ * Provides an hint to the compiler that the expression is probably
+ * going to be FALSE and evaluates to the value of the expression.
+ */
+#define SIMPLEOPS_UNLIKELY(expr) (expr)
+#endif
+
+/**
+ * Computes the address of a structure given its type and the address
+ * and name of one of its fields.
+ */
+#define SIMPLEOPS_CONTAINER_OF(ptr, type, member) \
+ ((type*)(((char *) ptr) - offsetof (type, member)))
+
+#endif
diff --git a/compiler/simpleops-compiler.h b/compiler/simpleops-compiler.h
new file mode 100644
index 0000000..d6fe97a
--- /dev/null
+++ b/compiler/simpleops-compiler.h
@@ -0,0 +1,35 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_COMPILER_H
+#define SIMPLEOPS_COMPILER_H
+
+#include "simpleops/compiler/simpleops-compiler-config.h"
+#include "simpleops/compiler/simpleops-compiler-types.h"
+#include "simpleops/compiler/simpleops-compiler-utils.h"
+
+#endif
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..91e43ae
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,19 @@
+AC_PREREQ([2.61])
+AC_INIT([simpleops], [0.1.1], [ranma42@gmail.com])
+AC_CONFIG_MACRO_DIR([m4])
+
+AM_INIT_AUTOMAKE([foreign dist-bzip2])
+AC_PROG_CC
+
+SIMPLEOPS_CHECK_ATOMIC
+SIMPLEOPS_CHECK_COMPILER
+SIMPLEOPS_CHECK_INITFINI
+SIMPLEOPS_CHECK_MUTEX
+SIMPLEOPS_CHECK_THREAD
+SIMPLEOPS_CHECK_TLS
+
+AC_CONFIG_HEADERS([config.h])
+AX_PREFIX_CONFIG_H
+AC_CONFIG_FILES([Makefile])
+
+AC_OUTPUT
diff --git a/initfini/impl/simpleops-initfini-impl-attr.h b/initfini/impl/simpleops-initfini-impl-attr.h
new file mode 100644
index 0000000..2a7eb80
--- /dev/null
+++ b/initfini/impl/simpleops-initfini-impl-attr.h
@@ -0,0 +1,56 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_ATTR_H
+#define SIMPLEOPS_INITFINI_IMPL_ATTR_H
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_INITFINI_IMPL && \
+ SIMPLEOPS_HAVE_ATTRIBUTE_CONSTRUCTOR && \
+ SIMPLEOPS_HAVE_ATTRIBUTE_DESTRUCTOR
+
+#define SIMPLEOPS_HAVE_INITFINI_IMPL 1
+#define SIMPLEOPS_HAVE_INITFINI_IMPL_ATTR 1
+
+static void __attribute__((constructor))
+_simpleops_constructor (void)
+{
+ simpleops_init ();
+}
+
+static void __attribute__((destructor))
+_simpleops_destructor (void)
+{
+ simpleops_fini ();
+}
+
+#endif
+
+#endif
diff --git a/initfini/impl/simpleops-initfini-impl-common-tail.h b/initfini/impl/simpleops-initfini-impl-common-tail.h
new file mode 100644
index 0000000..7c35fb1
--- /dev/null
+++ b/initfini/impl/simpleops-initfini-impl-common-tail.h
@@ -0,0 +1,37 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_COMMON_TAIL_H
+#define SIMPLEOPS_INITFINI_IMPL_COMMON_TAIL_H
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_H
+#error Private header used directly
+#endif
+
+#include "simpleops/tls/req/simpleops-tls-req.h"
+
+#endif
diff --git a/initfini/impl/simpleops-initfini-impl-common.h b/initfini/impl/simpleops-initfini-impl-common.h
new file mode 100644
index 0000000..fcc1c76
--- /dev/null
+++ b/initfini/impl/simpleops-initfini-impl-common.h
@@ -0,0 +1,116 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_COMMON_H
+#define SIMPLEOPS_INITFINI_IMPL_COMMON_H
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_H
+#error Private header used directly
+#endif
+
+#include "simpleops/atomic/internal/simpleops-atomic-internal.h"
+#include "simpleops/tls/internal/simpleops-tls-internal.h"
+
+static void
+_simpleops_init_internals (void)
+{
+ _simpleops_atomic_init ();
+ _simpleops_tls_init ();
+}
+
+static void
+_simpleops_fini_internals (void)
+{
+ simpleops_tls_reset ();
+
+ _simpleops_tls_fini ();
+ _simpleops_atomic_fini ();
+}
+
+
+static void _simpleops_init_externals (void);
+static void _simpleops_fini_externals (void);
+
+/**
+ * This macro is used to specify what function should be called upon
+ * initialization.
+ */
+#define SIMPLEOPS_INIT(f) static void _simpleops_init_externals (void) { f (); }
+
+/**
+ * This macro is used to specify what function should be called upon
+ * termination.
+ */
+#define SIMPLEOPS_FINI(f) static void _simpleops_fini_externals (void) { f (); }
+
+static int _simpleops_initfini_counter;
+
+/* Invoke internal/external init/fini in the right order. Init only if
+ * initialization has not yet been performed, fini only if every user
+ * has already detached. */
+
+/**
+ * Perform the initialization.
+ *
+ * After this function returns, the initialization is guaranteed to be
+ * complete. This is only needed in order to enforce a specific
+ * initialization sequence in dependent libraries.
+ *
+ * This function is not thread-safe. Multiple concurrent calls may
+ * lead to undefined behavior.
+ */
+static void
+simpleops_init (void)
+{
+ if (_simpleops_initfini_counter++)
+ return;
+
+ _simpleops_init_internals ();
+ _simpleops_init_externals ();
+}
+
+/**
+ * Perform the termination.
+ *
+ * After this function returns, the termination is guaranteed to be
+ * complete. This is only needed in order to enforce a specific
+ * termination sequence in dependent libraries.
+ *
+ * This function is not thread-safe. Multiple concurrent calls may
+ * lead to undefined behavior.
+ */
+static void
+simpleops_fini (void)
+{
+ if (--_simpleops_initfini_counter)
+ return;
+
+ _simpleops_fini_externals ();
+ _simpleops_fini_internals ();
+}
+
+#endif
diff --git a/initfini/impl/simpleops-initfini-impl-doc.h b/initfini/impl/simpleops-initfini-impl-doc.h
new file mode 100644
index 0000000..7833ec0
--- /dev/null
+++ b/initfini/impl/simpleops-initfini-impl-doc.h
@@ -0,0 +1,58 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_DOC_H
+#define SIMPLEOPS_INITFINI_IMPL_DOC_H
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_INITFINI_IMPL && \
+ SIMPLEOPS_DOC
+
+/**
+ * Defined whenever the simpleops library is providing an
+ * implementation of initialization and termination operations.
+ *
+ * Initialization is performed exaclty once, as soon as the
+ * application or library is loaded, before any other code is
+ * executed. In a similar way, finalization is performed exactly once,
+ * when the application or library is being unloaded.
+ */
+#define SIMPLEOPS_HAVE_INITFINI_IMPL 1
+
+/**
+ * SIMPLEOPS_HAVE_INITFINI_IMPL_* identifies which implementation is
+ * being used in the simpleops library to provide
+ * initialization/termination operations.
+ */
+#define SIMPLEOPS_HAVE_INITFINI_IMPL_DOC 1
+
+#endif
+
+#endif
diff --git a/initfini/impl/simpleops-initfini-impl-msvc.h b/initfini/impl/simpleops-initfini-impl-msvc.h
new file mode 100644
index 0000000..9ccf51a
--- /dev/null
+++ b/initfini/impl/simpleops-initfini-impl-msvc.h
@@ -0,0 +1,98 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_MSVC_H
+#define SIMPLEOPS_INITFINI_IMPL_MSVC_H
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_INITFINI_IMPL && \
+ defined(_MSC_VER) && ! defined(_DLL)
+
+#define SIMPLEOPS_HAVE_INITFINI_IMPL 1
+#define SIMPLEOPS_HAVE_INITFINI_IMPL_MSVC 1
+
+#define SIMPLEOPS_HAVE_TLS_DESTRUCTOR 1
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+typedef int (__cdecl *_PVFV)(void);
+
+static void NTAPI
+_simpleops_msvc_tls (HINSTANCE h,
+ DWORD dwReason,
+ PVOID pv)
+{
+ if (dwReason == DLL_THREAD_DETACH)
+ simpleops_tls_reset ();
+}
+
+static int
+_simpleops_init_msvc (void)
+{
+ simpleops_init ();
+ return 0;
+}
+
+static int
+_simpleops_fini_msvc (void)
+{
+ simpleops_fini ();
+ return 0;
+}
+
+#ifdef _M_IX86
+#pragma comment (linker, "/INCLUDE:__tls_used")
+#else
+#pragma comment (linker, "/INCLUDE:_tls_used")
+#endif
+
+#pragma data_seg(push, old_seg)
+
+#pragma section(".CRT$XIU", long, read)
+#pragma section(".CRT$XTU", long, read)
+#pragma section(".CRT$XLB", long, read)
+
+#pragma data_seg(".CRT$XIU")
+static _PVFV _simpleops_msvc_init_cb = _simpleops_init_msvc;
+
+#pragma data_seg(".CRT$XTU")
+static _PVFV _simpleops_msvc_fini_cb = _simpleops_fini_msvc;
+
+#pragma data_seg(".CRT$XLB")
+static PIMAGE_TLS_CALLBACK _simpleops_msvc_tls_cb = _simpleops_msvc_tls;
+
+#pragma data_seg()
+
+#pragma data_seg(pop, old_seg)
+
+#endif
+
+#endif
diff --git a/initfini/impl/simpleops-initfini-impl-no.h b/initfini/impl/simpleops-initfini-impl-no.h
new file mode 100644
index 0000000..37c7920
--- /dev/null
+++ b/initfini/impl/simpleops-initfini-impl-no.h
@@ -0,0 +1,43 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_NO_H
+#define SIMPLEOPS_INITFINI_IMPL_NO_H
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_INITFINI_IMPL && \
+ defined(SIMPLEOPS_DISABLE_INITFINI)
+
+#define SIMPLEOPS_HAVE_INITFINI_IMPL 1
+#define SIMPLEOPS_HAVE_INITFINI_IMPL_NO 1
+
+#endif
+
+#endif
diff --git a/initfini/impl/simpleops-initfini-impl-pragma.h b/initfini/impl/simpleops-initfini-impl-pragma.h
new file mode 100644
index 0000000..82f67d7
--- /dev/null
+++ b/initfini/impl/simpleops-initfini-impl-pragma.h
@@ -0,0 +1,58 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_PRAGMA_H
+#define SIMPLEOPS_INITFINI_IMPL_PRAGMA_H
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_INITFINI_IMPL && \
+ SIMPLEOPS_HAVE_PRAGMA_INIT && \
+ SIMPLEOPS_HAVE_PRAGMA_FINI
+
+#define SIMPLEOPS_HAVE_INITFINI_IMPL 1
+#define SIMPLEOPS_HAVE_INITFINI_IMPL_PRAGMA 1
+
+#pragma init
+static void
+simpleops_constructor (void)
+{
+ simpleops_init ();
+}
+
+#pragma fini
+static void
+simpleops_destructor (void)
+{
+ simpleops_fini ();
+}
+
+#endif
+
+#endif
diff --git a/initfini/impl/simpleops-initfini-impl-template.h b/initfini/impl/simpleops-initfini-impl-template.h
new file mode 100644
index 0000000..5520525
--- /dev/null
+++ b/initfini/impl/simpleops-initfini-impl-template.h
@@ -0,0 +1,43 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_TEMPLATE_H
+#define SIMPLEOPS_INITFINI_IMPL_TEMPLATE_H
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_INITFINI_IMPL && \
+ 0
+
+#define SIMPLEOPS_HAVE_INITFINI_IMPL 1
+#define SIMPLEOPS_HAVE_INITFINI_IMPL_TEMPLATE 1
+
+#endif
+
+#endif
diff --git a/initfini/impl/simpleops-initfini-impl-win32.h b/initfini/impl/simpleops-initfini-impl-win32.h
new file mode 100644
index 0000000..4ccb716
--- /dev/null
+++ b/initfini/impl/simpleops-initfini-impl-win32.h
@@ -0,0 +1,68 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_WIN32_H
+#define SIMPLEOPS_INITFINI_IMPL_WIN32_H
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_INITFINI_IMPL && \
+ defined(_WIN32) && defined(SIMPLEOPS_DLL)
+
+#define SIMPLEOPS_HAVE_INITFINI_IMPL 1
+#define SIMPLEOPS_HAVE_INITFINI_IMPL_WIN32 1
+
+#define SIMPLEOPS_HAVE_TLS_DESTRUCTOR 1
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
+{
+ switch (fdwReason) {
+ case DLL_PROCESS_ATTACH:
+ simpleops_init ();
+ return TRUE;
+
+ case DLL_PROCESS_DETACH:
+ simpleops_fini ();
+ return TRUE;
+
+ case DLL_THREAD_DETACH:
+ simpleops_tls_reset ();
+ return TRUE;
+
+ default:
+ return TRUE;
+ }
+}
+
+#endif
+
+#endif
diff --git a/initfini/impl/simpleops-initfini-impl.h b/initfini/impl/simpleops-initfini-impl.h
new file mode 100644
index 0000000..2b890f6
--- /dev/null
+++ b/initfini/impl/simpleops-initfini-impl.h
@@ -0,0 +1,53 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_H
+#define SIMPLEOPS_INITFINI_IMPL_H
+
+#ifndef SIMPLEOPS_INITFINI_H
+#error Private header used directly
+#endif
+
+#include "simpleops/initfini/impl/simpleops-initfini-impl-common.h"
+
+/* DIFFTABLE */
+#include "simpleops/initfini/impl/simpleops-initfini-impl-template.h"
+#include "simpleops/initfini/impl/simpleops-initfini-impl-doc.h"
+#include "simpleops/initfini/impl/simpleops-initfini-impl-no.h"
+#include "simpleops/initfini/impl/simpleops-initfini-impl-win32.h"
+#include "simpleops/initfini/impl/simpleops-initfini-impl-attr.h"
+#include "simpleops/initfini/impl/simpleops-initfini-impl-pragma.h"
+#include "simpleops/initfini/impl/simpleops-initfini-impl-msvc.h"
+/* DIFFTABLE */
+
+#include "simpleops/initfini/impl/simpleops-initfini-impl-common-tail.h"
+
+#if ! SIMPLEOPS_HAVE_INITFINI_IMPL
+#error No implementation available
+#endif
+
+#endif
diff --git a/initfini/simpleops-initfini.h b/initfini/simpleops-initfini.h
new file mode 100644
index 0000000..d08b8b8
--- /dev/null
+++ b/initfini/simpleops-initfini.h
@@ -0,0 +1,35 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_INITFINI_H
+#define SIMPLEOPS_INITFINI_H
+
+#include "simpleops/compiler/simpleops-compiler.h"
+
+#include "simpleops/initfini/impl/simpleops-initfini-impl.h"
+
+#endif
diff --git a/m4/ax_c___attribute__.m4 b/m4/ax_c___attribute__.m4
new file mode 100644
index 0000000..a8bcb73
--- /dev/null
+++ b/m4/ax_c___attribute__.m4
@@ -0,0 +1,70 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_c___attribute__.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_C___ATTRIBUTE__(ATTRIBUTE-ID)
+#
+# DESCRIPTION
+#
+# Provides a test for the compiler support of the
+# __attribute__((ATTRIBUTE-ID)) extension.
+# Defines HAVE_ATTRIBUTE_<ATTRIBUTE-ID> if it is found.
+#
+# LICENSE
+#
+# Copyright (c) 2008 Stepan Kasal <skasal@redhat.com>
+# Copyright (c) 2008 Christian Haggstrom
+# Copyright (c) 2008 Ryan McCabe <ryan@numb.org>
+# Copyright (c) 2011 Andrea Canciani <ranma42@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+#
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Archive. When you make and distribute a
+# modified version of the Autoconf Macro, you may extend this special
+# exception to the GPL to apply to your modified version as well.
+
+#serial 10
+
+AC_DEFUN([AX_C_ATTRIBUTE], [
+ AC_CACHE_CHECK([for __attribute__(($1))], [ax_cv_attribute_$1],
+ [AX_NODIFF_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[
+static void foo (void);
+static void foo (void) { return; }
+ ]], [[foo ()]])],
+ [AC_LANG_PROGRAM(
+ [[
+static void foo (void) __attribute__ (($1));
+static void foo (void) { return; }
+ ]], [[foo ()]])],
+ [ax_cv_attribute_$1=yes],
+ [ax_cv_attribute_$1=no]
+ )
+ ])
+ if test "$ax_cv_attribute_$1" = "yes"; then
+ AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_ATTRIBUTE_$1]), 1, [Define to 1 if your compiler has __attribute__(($1)).])
+ fi
+])
diff --git a/m4/ax_c_pragma.m4 b/m4/ax_c_pragma.m4
new file mode 100644
index 0000000..1848c5e
--- /dev/null
+++ b/m4/ax_c_pragma.m4
@@ -0,0 +1,66 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_c___attribute__.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_C_PRAGMA(PRAGMA-ID)
+#
+# DESCRIPTION
+#
+# Provides a test for the compiler support of the
+# #pragma <PRAGMA-ID> extension.
+# Defines HAVE_PRAGMA_<PRAGMA-ID> if it is found.
+#
+# LICENSE
+#
+# Copyright (c) 2011 Andrea Canciani <ranma42@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+#
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Archive. When you make and distribute a
+# modified version of the Autoconf Macro, you may extend this special
+# exception to the GPL to apply to your modified version as well.
+
+#serial 1
+
+AC_DEFUN([AX_C_PRAGMA], [
+ AC_CACHE_CHECK([for @%:@pragma $1], [ax_cv_pragma_$1],
+ [AX_NODIFF_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[
+static void foo (void) { return; }
+ ]], [[foo ()]])],
+ [AC_LANG_PROGRAM(
+ [[
+@%:@pragma $1
+static void foo (void) { return; }
+ ]], [[foo ()]])],
+ [ax_cv_pragma_$1=yes],
+ [ax_cv_pragma_$1=no]
+ )
+ ])
+ if test "x$ax_cv_pragma_$1" = "xyes"; then
+ AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_PRAGMA_$1]), 1, [Define to 1 if your compiler has @%:@pragma $1.])
+ fi
+])
diff --git a/m4/ax_nodiff_compile_ifelse.m4 b/m4/ax_nodiff_compile_ifelse.m4
new file mode 100644
index 0000000..99473fd
--- /dev/null
+++ b/m4/ax_nodiff_compile_ifelse.m4
@@ -0,0 +1,57 @@
+# SYNOPSIS
+#
+# AX_NODIFF_COMPILE_IFELSE(REFERENCE-PROGRAM, TEST-PROGRAM,
+# [ACTION-IF-TRUE], [ACTION-IF-FALSE])
+#
+# DESCRIPTION
+#
+# Provides a test for the compiler support of __attribute__ extensions.
+# Defines HAVE___ATTRIBUTE__ if it is found.
+#
+# Check that the compilation of both REFERENCE-PROGRAM and
+# TEST-PROGRAM succeeds and produces the same warnings. Requires
+# that the compiler for the current language was checked for, hence
+# do not use this macro in macros looking for a compiler.
+#
+# LICENSE
+#
+# Copyright (c) 2011 Andrea Canciani <ranma42@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+#
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Archive. When you make and distribute a
+# modified version of the Autoconf Macro, you may extend this special
+# exception to the GPL to apply to your modified version as well.
+
+#serial 1
+
+AC_DEFUN([AX_NODIFF_COMPILE_IFELSE], [dnl
+ AC_COMPILE_IFELSE([$1], [dnl
+ cp conftest.err conftest.err.ref
+ AC_COMPILE_IFELSE([$2], [dnl
+ AS_IF([diff conftest.err.ref conftest.err],
+ [$3], [$4])
+ ])
+ rm -f conftest.err.ref
+ ])
+])
diff --git a/m4/ax_prefix_config_h.m4 b/m4/ax_prefix_config_h.m4
new file mode 100644
index 0000000..b37f08b
--- /dev/null
+++ b/m4/ax_prefix_config_h.m4
@@ -0,0 +1,217 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_prefix_config_h.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_PREFIX_CONFIG_H [(OUTPUT-HEADER [,PREFIX [,ORIG-HEADER]])]
+#
+# DESCRIPTION
+#
+# This is a new variant from ac_prefix_config_ this one will use a
+# lowercase-prefix if the config-define was starting with a
+# lowercase-char, e.g. "#define const", "#define restrict", or "#define
+# off_t", (and this one can live in another directory, e.g.
+# testpkg/config.h therefore I decided to move the output-header to be the
+# first arg)
+#
+# takes the usual config.h generated header file; looks for each of the
+# generated "#define SOMEDEF" lines, and prefixes the defined name (ie.
+# makes it "#define PREFIX_SOMEDEF". The result is written to the output
+# config.header file. The PREFIX is converted to uppercase for the
+# conversions.
+#
+# Defaults:
+#
+# OUTPUT-HEADER = $PACKAGE-config.h
+# PREFIX = $PACKAGE
+# ORIG-HEADER, from AM_CONFIG_HEADER(config.h)
+#
+# Your configure.ac script should contain both macros in this order, and
+# unlike the earlier variations of this prefix-macro it is okay to place
+# the AX_PREFIX_CONFIG_H call before the AC_OUTPUT invokation.
+#
+# Example:
+#
+# AC_INIT(config.h.in) # config.h.in as created by "autoheader"
+# AM_INIT_AUTOMAKE(testpkg, 0.1.1) # makes #undef VERSION and PACKAGE
+# AM_CONFIG_HEADER(config.h) # prep config.h from config.h.in
+# AX_PREFIX_CONFIG_H(mylib/_config.h) # prep mylib/_config.h from it..
+# AC_MEMORY_H # makes "#undef NEED_MEMORY_H"
+# AC_C_CONST_H # makes "#undef const"
+# AC_OUTPUT(Makefile) # creates the "config.h" now
+# # and also mylib/_config.h
+#
+# if the argument to AX_PREFIX_CONFIG_H would have been omitted then the
+# default outputfile would have been called simply "testpkg-config.h", but
+# even under the name "mylib/_config.h" it contains prefix-defines like
+#
+# #ifndef TESTPKG_VERSION
+# #define TESTPKG_VERSION "0.1.1"
+# #endif
+# #ifndef TESTPKG_NEED_MEMORY_H
+# #define TESTPKG_NEED_MEMORY_H 1
+# #endif
+# #ifndef _testpkg_const
+# #define _testpkg_const _const
+# #endif
+#
+# and this "mylib/_config.h" can be installed along with other
+# header-files, which is most convenient when creating a shared library
+# (that has some headers) where some functionality is dependent on the
+# OS-features detected at compile-time. No need to invent some
+# "mylib-confdefs.h.in" manually. :-)
+#
+# Note that some AC_DEFINEs that end up in the config.h file are actually
+# self-referential - e.g. AC_C_INLINE, AC_C_CONST, and the AC_TYPE_OFF_T
+# say that they "will define inline|const|off_t if the system does not do
+# it by itself". You might want to clean up about these - consider an
+# extra mylib/conf.h that reads something like:
+#
+# #include <mylib/_config.h>
+# #ifndef _testpkg_const
+# #define _testpkg_const const
+# #endif
+#
+# and then start using _testpkg_const in the header files. That is also a
+# good thing to differentiate whether some library-user has starting to
+# take up with a different compiler, so perhaps it could read something
+# like this:
+#
+# #ifdef _MSC_VER
+# #include <mylib/_msvc.h>
+# #else
+# #include <mylib/_config.h>
+# #endif
+# #ifndef _testpkg_const
+# #define _testpkg_const const
+# #endif
+#
+# LICENSE
+#
+# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
+# Copyright (c) 2008 Marten Svantesson
+# Copyright (c) 2008 Gerald Point <Gerald.Point@labri.fr>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+#
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Archive. When you make and distribute a
+# modified version of the Autoconf Macro, you may extend this special
+# exception to the GPL to apply to your modified version as well.
+
+#serial 9
+
+AC_DEFUN([AX_PREFIX_CONFIG_H],[dnl
+AC_BEFORE([AC_CONFIG_HEADERS],[$0])dnl
+AC_CONFIG_COMMANDS([ifelse($1,,$PACKAGE-config.h,$1)],[dnl
+AS_VAR_PUSHDEF([_OUT],[ac_prefix_conf_OUT])dnl
+AS_VAR_PUSHDEF([_DEF],[ac_prefix_conf_DEF])dnl
+AS_VAR_PUSHDEF([_PKG],[ac_prefix_conf_PKG])dnl
+AS_VAR_PUSHDEF([_LOW],[ac_prefix_conf_LOW])dnl
+AS_VAR_PUSHDEF([_UPP],[ac_prefix_conf_UPP])dnl
+AS_VAR_PUSHDEF([_INP],[ac_prefix_conf_INP])dnl
+m4_pushdef([_script],[conftest.prefix])dnl
+m4_pushdef([_symbol],[m4_cr_Letters[]m4_cr_digits[]_])dnl
+_OUT=`echo ifelse($1, , $PACKAGE-config.h, $1)`
+_DEF=`echo _$_OUT | sed -e "y:m4_cr_letters:m4_cr_LETTERS[]:" -e "s/@<:@^m4_cr_Letters@:>@/_/g"`
+_PKG=`echo ifelse($2, , $PACKAGE, $2)`
+_LOW=`echo _$_PKG | sed -e "y:m4_cr_LETTERS-:m4_cr_letters[]_:"`
+_UPP=`echo $_PKG | sed -e "y:m4_cr_letters-:m4_cr_LETTERS[]_:" -e "/^@<:@m4_cr_digits@:>@/s/^/_/"`
+_INP=`echo "ifelse($3,,,$3)" | sed -e 's/ *//'`
+if test ".$_INP" = "."; then
+ for ac_file in : $CONFIG_HEADERS; do test "_$ac_file" = _: && continue
+ case "$ac_file" in
+ *.h) _INP=$ac_file ;;
+ *)
+ esac
+ test ".$_INP" != "." && break
+ done
+fi
+if test ".$_INP" = "."; then
+ case "$_OUT" in
+ */*) _INP=`basename "$_OUT"`
+ ;;
+ *-*) _INP=`echo "$_OUT" | sed -e "s/@<:@_symbol@:>@*-//"`
+ ;;
+ *) _INP=config.h
+ ;;
+ esac
+fi
+if test -z "$_PKG" ; then
+ AC_MSG_ERROR([no prefix for _PREFIX_PKG_CONFIG_H])
+else
+ if test ! -f "$_INP" ; then if test -f "$srcdir/$_INP" ; then
+ _INP="$srcdir/$_INP"
+ fi fi
+ AC_MSG_NOTICE(creating $_OUT - prefix $_UPP for $_INP defines)
+ if test -f $_INP ; then
+ echo "s/^@%:@undef *\\(@<:@m4_cr_LETTERS[]_@:>@\\)/@%:@undef $_UPP""_\\1/" > _script
+ echo "s/^@%:@undef *\\(@<:@m4_cr_letters@:>@\\)/@%:@undef $_LOW""_\\1/" >> _script
+ echo "s/^@%:@def[]ine *\\(@<:@m4_cr_LETTERS[]_@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_UPP""_\\1\\" >> _script
+ echo "@%:@def[]ine $_UPP""_\\1\\2\\" >> _script
+ echo "@%:@endif/" >>_script
+ echo "s/^@%:@def[]ine *\\(@<:@m4_cr_letters@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_LOW""_\\1\\" >> _script
+ echo "@%:@define $_LOW""_\\1\\2\\" >> _script
+ echo "@%:@endif/" >> _script
+ # now executing _script on _DEF input to create _OUT output file
+ echo "@%:@ifndef $_DEF" >$tmp/pconfig.h
+ echo "@%:@def[]ine $_DEF 1" >>$tmp/pconfig.h
+ echo ' ' >>$tmp/pconfig.h
+ echo /'*' $_OUT. Generated automatically at end of configure. '*'/ >>$tmp/pconfig.h
+
+ sed -f _script $_INP >>$tmp/pconfig.h
+ echo ' ' >>$tmp/pconfig.h
+ echo '/* once:' $_DEF '*/' >>$tmp/pconfig.h
+ echo "@%:@endif" >>$tmp/pconfig.h
+ if cmp -s $_OUT $tmp/pconfig.h 2>/dev/null; then
+ AC_MSG_NOTICE([$_OUT is unchanged])
+ else
+ ac_dir=`AS_DIRNAME(["$_OUT"])`
+ AS_MKDIR_P(["$ac_dir"])
+ rm -f "$_OUT"
+ mv $tmp/pconfig.h "$_OUT"
+ fi
+ cp _script _configs.sed
+ else
+ AC_MSG_ERROR([input file $_INP does not exist - skip generating $_OUT])
+ fi
+ rm -f conftest.*
+fi
+m4_popdef([_symbol])dnl
+m4_popdef([_script])dnl
+AS_VAR_POPDEF([_INP])dnl
+AS_VAR_POPDEF([_UPP])dnl
+AS_VAR_POPDEF([_LOW])dnl
+AS_VAR_POPDEF([_PKG])dnl
+AS_VAR_POPDEF([_DEF])dnl
+AS_VAR_POPDEF([_OUT])dnl
+],[PACKAGE="$PACKAGE"])])
+
+dnl implementation note: a bug report (31.5.2005) from Marten Svantesson points
+dnl out a problem where `echo "\1"` results in a Control-A. The unix standard
+dnl http://www.opengroup.org/onlinepubs/000095399/utilities/echo.html
+dnl defines all backslash-sequences to be inherently non-portable asking
+dnl for replacement mit printf. Some old systems had problems with that
+dnl one either. However, the latest libtool (!) release does export an $ECHO
+dnl (and $echo) that does the right thing - just one question is left: what
+dnl was the first version to have it? Is it greater 2.58 ?
diff --git a/m4/ax_pthread.m4 b/m4/ax_pthread.m4
new file mode 100644
index 0000000..9350d8b
--- /dev/null
+++ b/m4/ax_pthread.m4
@@ -0,0 +1,288 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_pthread.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
+#
+# DESCRIPTION
+#
+# This macro figures out how to build C programs using POSIX threads. It
+# sets the PTHREAD_LIBS output variable to the threads library and linker
+# flags, and the PTHREAD_CFLAGS output variable to any special C compiler
+# flags that are needed. (The user can also force certain compiler
+# flags/libs to be tested by setting these environment variables.)
+#
+# Also sets PTHREAD_CC to any special C compiler that is needed for
+# multi-threaded programs (defaults to the value of CC otherwise). (This
+# is necessary on AIX to use the special cc_r compiler alias.)
+#
+# NOTE: You are assumed to not only compile your program with these flags,
+# but also link it with them as well. e.g. you should link with
+# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
+#
+# If you are only building threads programs, you may wish to use these
+# variables in your default LIBS, CFLAGS, and CC:
+#
+# LIBS="$PTHREAD_LIBS $LIBS"
+# CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+# CC="$PTHREAD_CC"
+#
+# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant
+# has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name
+# (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
+#
+# ACTION-IF-FOUND is a list of shell commands to run if a threads library
+# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it
+# is not found. If ACTION-IF-FOUND is not specified, the default action
+# will define HAVE_PTHREAD.
+#
+# Please let the authors know if this macro fails on any platform, or if
+# you have any other suggestions or comments. This macro was based on work
+# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help
+# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by
+# Alejandro Forero Cuervo to the autoconf macro repository. We are also
+# grateful for the helpful feedback of numerous users.
+#
+# Updated for Autoconf 2.68 by Daniel Richard G.
+#
+# LICENSE
+#
+# Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
+# Copyright (c) 2011 Daniel Richard G. <skunk@iSKUNK.ORG>
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+#
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Archive. When you make and distribute a
+# modified version of the Autoconf Macro, you may extend this special
+# exception to the GPL to apply to your modified version as well.
+
+#serial 12
+
+AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD])
+AC_DEFUN([AX_PTHREAD], [
+AC_REQUIRE([AC_CANONICAL_HOST])
+AC_LANG_PUSH([C])
+ax_pthread_ok=no
+
+# We used to check for pthread.h first, but this fails if pthread.h
+# requires special compiler flags (e.g. on True64 or Sequent).
+# It gets checked for in the link test anyway.
+
+# First of all, check if the user has set any of the PTHREAD_LIBS,
+# etcetera environment variables, and if threads linking works using
+# them:
+if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+ save_LIBS="$LIBS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+ AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
+ AC_TRY_LINK_FUNC(pthread_join, ax_pthread_ok=yes)
+ AC_MSG_RESULT($ax_pthread_ok)
+ if test x"$ax_pthread_ok" = xno; then
+ PTHREAD_LIBS=""
+ PTHREAD_CFLAGS=""
+ fi
+ LIBS="$save_LIBS"
+ CFLAGS="$save_CFLAGS"
+fi
+
+# We must check for the threads library under a number of different
+# names; the ordering is very important because some systems
+# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
+# libraries is broken (non-POSIX).
+
+# Create a list of thread flags to try. Items starting with a "-" are
+# C compiler flags, and other items are library names, except for "none"
+# which indicates that we try without any flags at all, and "pthread-config"
+# which is a program returning the flags for the Pth emulation library.
+
+ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
+
+# The ordering *is* (sometimes) important. Some notes on the
+# individual items follow:
+
+# pthreads: AIX (must check this before -lpthread)
+# none: in case threads are in libc; should be tried before -Kthread and
+# other compiler flags to prevent continual compiler warnings
+# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
+# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
+# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
+# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
+# -pthreads: Solaris/gcc
+# -mthreads: Mingw32/gcc, Lynx/gcc
+# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
+# doesn't hurt to check since this sometimes defines pthreads too;
+# also defines -D_REENTRANT)
+# ... -mt is also the pthreads flag for HP/aCC
+# pthread: Linux, etcetera
+# --thread-safe: KAI C++
+# pthread-config: use pthread-config program (for GNU Pth library)
+
+case "${host_cpu}-${host_os}" in
+ *solaris*)
+
+ # On Solaris (at least, for some versions), libc contains stubbed
+ # (non-functional) versions of the pthreads routines, so link-based
+ # tests will erroneously succeed. (We need to link with -pthreads/-mt/
+ # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
+ # a function called by this macro, so we could check for that, but
+ # who knows whether they'll stub that too in a future libc.) So,
+ # we'll just look for -pthreads and -lpthread first:
+
+ ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags"
+ ;;
+
+ *-darwin*)
+ ax_pthread_flags="-pthread $ax_pthread_flags"
+ ;;
+esac
+
+if test x"$ax_pthread_ok" = xno; then
+for flag in $ax_pthread_flags; do
+
+ case $flag in
+ none)
+ AC_MSG_CHECKING([whether pthreads work without any flags])
+ ;;
+
+ -*)
+ AC_MSG_CHECKING([whether pthreads work with $flag])
+ PTHREAD_CFLAGS="$flag"
+ ;;
+
+ pthread-config)
+ AC_CHECK_PROG(ax_pthread_config, pthread-config, yes, no)
+ if test x"$ax_pthread_config" = xno; then continue; fi
+ PTHREAD_CFLAGS="`pthread-config --cflags`"
+ PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
+ ;;
+
+ *)
+ AC_MSG_CHECKING([for the pthreads library -l$flag])
+ PTHREAD_LIBS="-l$flag"
+ ;;
+ esac
+
+ save_LIBS="$LIBS"
+ save_CFLAGS="$CFLAGS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+
+ # Check for various functions. We must include pthread.h,
+ # since some functions may be macros. (On the Sequent, we
+ # need a special flag -Kthread to make this header compile.)
+ # We check for pthread_join because it is in -lpthread on IRIX
+ # while pthread_create is in libc. We check for pthread_attr_init
+ # due to DEC craziness with -lpthreads. We check for
+ # pthread_cleanup_push because it is one of the few pthread
+ # functions on Solaris that doesn't have a non-functional libc stub.
+ # We try pthread_create on general principles.
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>
+ static void routine(void *a) { a = 0; }
+ static void *start_routine(void *a) { return a; }],
+ [pthread_t th; pthread_attr_t attr;
+ pthread_create(&th, 0, start_routine, 0);
+ pthread_join(th, 0);
+ pthread_attr_init(&attr);
+ pthread_cleanup_push(routine, 0);
+ pthread_cleanup_pop(0) /* ; */])],
+ [ax_pthread_ok=yes],
+ [])
+
+ LIBS="$save_LIBS"
+ CFLAGS="$save_CFLAGS"
+
+ AC_MSG_RESULT($ax_pthread_ok)
+ if test "x$ax_pthread_ok" = xyes; then
+ break;
+ fi
+
+ PTHREAD_LIBS=""
+ PTHREAD_CFLAGS=""
+done
+fi
+
+# Various other checks:
+if test "x$ax_pthread_ok" = xyes; then
+ save_LIBS="$LIBS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+
+ # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
+ AC_MSG_CHECKING([for joinable pthread attribute])
+ attr_name=unknown
+ for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],
+ [int attr = $attr; return attr /* ; */])],
+ [attr_name=$attr; break],
+ [])
+ done
+ AC_MSG_RESULT($attr_name)
+ if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
+ AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
+ [Define to necessary symbol if this constant
+ uses a non-standard name on your system.])
+ fi
+
+ AC_MSG_CHECKING([if more special flags are required for pthreads])
+ flag=no
+ case "${host_cpu}-${host_os}" in
+ *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
+ *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
+ esac
+ AC_MSG_RESULT(${flag})
+ if test "x$flag" != xno; then
+ PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
+ fi
+
+ LIBS="$save_LIBS"
+ CFLAGS="$save_CFLAGS"
+
+ # More AIX lossage: must compile with xlc_r or cc_r
+ if test x"$GCC" != xyes; then
+ AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
+ else
+ PTHREAD_CC=$CC
+ fi
+else
+ PTHREAD_CC="$CC"
+fi
+
+AC_SUBST(PTHREAD_LIBS)
+AC_SUBST(PTHREAD_CFLAGS)
+AC_SUBST(PTHREAD_CC)
+
+# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
+if test x"$ax_pthread_ok" = xyes; then
+ ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define to 1 if you have POSIX threads libraries and header files.]),[$1])
+ :
+else
+ ax_pthread_ok=no
+ $2
+fi
+AC_LANG_POP
+])dnl AX_PTHREAD
diff --git a/m4/simpleops_atomic.m4 b/m4/simpleops_atomic.m4
new file mode 100644
index 0000000..8278f5e
--- /dev/null
+++ b/m4/simpleops_atomic.m4
@@ -0,0 +1,81 @@
+AC_DEFUN([SIMPLEOPS_CHECK_ATOMIC_OP_NEEDS_MEMORY_BARRIER],
+[dnl
+ AC_CANONICAL_HOST
+ AC_CACHE_CHECK([whether atomic ops require a memory barrier],
+ [simpleops_cv_atomic_op_needs_memory_barrier],
+ [dnl
+ case $host_cpu in
+ i?86) simpleops_cv_atomic_op_needs_memory_barrier="no" ;;
+ x86_64) simpleops_cv_atomic_op_needs_memory_barrier="no" ;;
+ arm*) simpleops_cv_atomic_op_needs_memory_barrier="no" ;;
+ *) simpleops_cv_atomic_op_needs_memory_barrier="yes" ;;
+ esac
+ ])
+ if test "x$simpleops_cv_atomic_op_needs_memory_barrier" = "xyes"; then
+ AC_DEFINE(ATOMIC_OP_NEEDS_MEMORY_BARRIER, 1,
+ [Define to 1 if memory barriers are needed around atomic operations.])
+ fi
+])
+
+AC_DEFUN([SIMPLEOPS_CHECK_NATIVE_ATOMIC_PRIMITIVES],
+[dnl
+ SIMPLEOPS_CHECK_ATOMIC_OP_NEEDS_MEMORY_BARRIER
+ AC_CACHE_CHECK([for native atomic primitives], simpleops_cv_native_atomic_primitives,
+ [dnl
+ AC_TRY_LINK([
+static int test_atomic (void)
+{
+ int r, x;
+#if SIMPLEOPS_ATOMIC_NEEDS_MEMORY_BARRIER
+ __sync_synchronize ();
+#endif
+ x = 0;
+ r = __sync_fetch_and_add (&x, 1);
+ r |= __sync_bool_compare_and_swap (&x, 0, 1);
+}
+],
+ [test_atomic ()],
+ [simpleops_cv_native_atomic_primitives="yes"],
+ [simpleops_cv_native_atomic_primitives="no"]
+ )
+ ])
+ if test "x$simpleops_cv_native_atomic_primitives" = "xyes"; then
+ AC_DEFINE(HAVE_NATIVE_ATOMIC_PRIMITIVES, 1,
+ [Define to 1 if your compiler supports the __sync_* atomic primitives])
+ fi
+])
+
+AC_DEFUN([SIMPLEOPS_CHECK_NATIVE_ATOMIC_SWAP],
+[dnl
+ AC_CACHE_CHECK([for native atomic swap], simpleops_cv_native_atomic_swap,
+ [dnl
+ AC_TRY_LINK([
+static int test_atomic_swap (void)
+{
+ int r, x;
+ x = 0;
+ r = __sync_swap (&x, 1);
+}
+],
+ [test_atomic_swap ()],
+ [simpleops_cv_native_atomic_swap="yes"],
+ [simpleops_cv_native_atomic_swap="no"]
+ )
+ ])
+ if test "x$simpleops_cv_native_atomic_swap" = "xyes"; then
+ AC_DEFINE(HAVE_NATIVE_ATOMIC_SWAP, 1,
+ [Define to 1 if your compiler supports __sync_swap()])
+ fi
+])
+
+AC_DEFUN([SIMPLEOPS_CHECK_ATOMIC],
+[dnl
+ AC_ARG_ENABLE([atomic],
+ [AS_HELP_STRING([--disable-atomic], [disable atomic operations])],
+ [AC_DEFINE(DISABLE_ATOMIC, 1, [Define to 1 to disable atomic operations.])]
+ )
+
+ SIMPLEOPS_CHECK_NATIVE_ATOMIC_PRIMITIVES
+ SIMPLEOPS_CHECK_NATIVE_ATOMIC_SWAP
+ AC_CHECK_HEADERS([libkern/OSAtomic.h atomic_ops.h])
+])
diff --git a/m4/simpleops_compiler.m4 b/m4/simpleops_compiler.m4
new file mode 100644
index 0000000..8ae12a5
--- /dev/null
+++ b/m4/simpleops_compiler.m4
@@ -0,0 +1,8 @@
+AC_DEFUN([SIMPLEOPS_CHECK_COMPILER],
+[dnl
+ AC_C_INLINE
+ AX_C_ATTRIBUTE([always_inline])
+ AX_C_ATTRIBUTE([const])
+ AX_C_ATTRIBUTE([noinline])
+ AX_C_ATTRIBUTE([pure])
+])
diff --git a/m4/simpleops_initfini.m4 b/m4/simpleops_initfini.m4
new file mode 100644
index 0000000..86cf0e9
--- /dev/null
+++ b/m4/simpleops_initfini.m4
@@ -0,0 +1,13 @@
+AC_DEFUN([SIMPLEOPS_CHECK_INITFINI],
+[dnl
+ AC_ARG_ENABLE([initfini],
+ [AS_HELP_STRING([--disable-initfini], [disable init/fini operations])],
+ [AC_DEFINE(DISABLE_INITFINI, 1, [Define to 1 to disable init/fini operations.])]
+ )
+
+ AX_C_ATTRIBUTE([constructor])
+ AX_C_ATTRIBUTE([destructor])
+
+ AX_C_PRAGMA([init])
+ AX_C_PRAGMA([fini])
+])
diff --git a/m4/simpleops_mutex.m4 b/m4/simpleops_mutex.m4
new file mode 100644
index 0000000..2236ab5
--- /dev/null
+++ b/m4/simpleops_mutex.m4
@@ -0,0 +1,10 @@
+AC_DEFUN([SIMPLEOPS_CHECK_MUTEX],
+[dnl
+ AC_ARG_ENABLE([mutex],
+ [AS_HELP_STRING([--disable-mutex], [disable mutex operations])],
+ [AC_DEFINE(DISABLE_MUTEX, 1, [Define to 1 to disable mutex operations.])]
+ )
+
+ AX_PTHREAD()
+ AC_CHECK_HEADERS([Locker.h])
+])
diff --git a/m4/simpleops_public.m4 b/m4/simpleops_public.m4
new file mode 100644
index 0000000..6e76b64
--- /dev/null
+++ b/m4/simpleops_public.m4
@@ -0,0 +1,12 @@
+AC_DEFUN([SIMPLEOPS_CONFIG],
+[dnl
+ AX_PTHREAD
+
+ SIMPLEOPS_CFLAGS="$PTHREAD_CFLAGS"
+ SIMPLEOPS_LIBS="$PTHREAD_LIBS"
+ SIMPLEOPS_CC="$PTHREAD_CC"
+
+ AC_SUBST(SIMPLEOPS_LIBS)
+ AC_SUBST(SIMPLEOPS_CFLAGS)
+ AC_SUBST(SIMPLEOPS_CC)
+])
diff --git a/m4/simpleops_thread.m4 b/m4/simpleops_thread.m4
new file mode 100644
index 0000000..820cc0e
--- /dev/null
+++ b/m4/simpleops_thread.m4
@@ -0,0 +1,9 @@
+AC_DEFUN([SIMPLEOPS_CHECK_THREAD],
+[dnl
+ AC_ARG_ENABLE([thread],
+ [AS_HELP_STRING([--disable-thread], [disable thread operations])],
+ [AC_DEFINE(DISABLE_THREAD, 1, [Define to 1 to disable thread operations.])]
+ )
+
+ AX_PTHREAD()
+])
diff --git a/m4/simpleops_tls.m4 b/m4/simpleops_tls.m4
new file mode 100644
index 0000000..8251a22
--- /dev/null
+++ b/m4/simpleops_tls.m4
@@ -0,0 +1,9 @@
+AC_DEFUN([SIMPLEOPS_CHECK_TLS],
+[dnl
+ AC_ARG_ENABLE([tls],
+ [AS_HELP_STRING([--disable-tls], [disable TLS operations])],
+ [AC_DEFINE(DISABLE_TLS, 1, [Define to 1 to disable TLS operations.])]
+ )
+
+ AX_PTHREAD()
+])
diff --git a/mutex/impl/simpleops-mutex-impl-beos.h b/mutex/impl/simpleops-mutex-impl-beos.h
new file mode 100644
index 0000000..a481053
--- /dev/null
+++ b/mutex/impl/simpleops-mutex-impl-beos.h
@@ -0,0 +1,77 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_MUTEX_IMPL_BEOS_H
+#define SIMPLEOPS_MUTEX_IMPL_BEOS_H
+
+#ifndef SIMPLEOPS_MUTEX_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_MUTEX_IMPL && \
+ SIMPLEOPS_HAVE_LOCKER_H
+
+#define SIMPLEOPS_HAVE_MUTEX_IMPL 1
+#define SIMPLEOPS_HAVE_MUTEX_IMPL_BEOS 1
+
+#include <Locker.h>
+
+typedef BLocker simpleops_mutex_t;
+
+static simpleops_always_inline void
+simpleops_mutex_init (simpleops_mutex_t *mutex)
+{
+ *mutex = new BLocker ();
+}
+
+static simpleops_always_inline void
+simpleops_mutex_init_recursive (simpleops_mutex_t *mutex)
+{
+ *mutex = new BLocker ();
+}
+
+static simpleops_always_inline void
+simpleops_mutex_fini (simpleops_mutex_t *mutex)
+{
+ delete mutex;
+}
+
+static simpleops_always_inline void
+simpleops_mutex_lock (simpleops_mutex_t *mutex)
+{
+ mutex->Lock ();
+}
+
+static simpleops_always_inline void
+simpleops_mutex_unlock (simpleops_mutex_t *mutex)
+{
+ mutex->Unlock ();
+}
+
+#endif
+
+#endif
diff --git a/mutex/impl/simpleops-mutex-impl-doc.h b/mutex/impl/simpleops-mutex-impl-doc.h
new file mode 100644
index 0000000..8942cb6
--- /dev/null
+++ b/mutex/impl/simpleops-mutex-impl-doc.h
@@ -0,0 +1,110 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_MUTEX_IMPL_DOC_H
+#define SIMPLEOPS_MUTEX_IMPL_DOC_H
+
+#ifndef SIMPLEOPS_MUTEX_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_MUTEX_IMPL && \
+ SIMPLEOPS_DOC
+
+/**
+ * Defined whenever the simpleops library is providing an
+ * implementation of mutex operations.
+ *
+ * Mutexes are used to avoid to avoid race conditions when performing
+ * concurrent access to shared data.
+ */
+#define SIMPLEOPS_HAVE_MUTEX_IMPL 1
+
+/**
+ * SIMPLEOPS_HAVE_MUTEX_IMPL_* identifies which implementation is
+ * being used in the simpleops library to provide mutex operations.
+ */
+#define SIMPLEOPS_HAVE_MUTEX_IMPL_DOC 1
+
+/**
+ * This is the type used to identify mutexes in the thread functions.
+ */
+typedef int simpleops_mutex_t;
+
+/**
+ * Initialize a mutex.
+ *
+ * \param[in,out] mutex the mutex to be initialized.
+ */
+static simpleops_always_inline void
+simpleops_mutex_init (simpleops_mutex_t *mutex)
+{
+}
+
+/**
+ * Initialize a recursive mutex.
+ *
+ * \param[in,out] mutex the mutex to be initialized.
+ */
+static simpleops_always_inline void
+simpleops_mutex_init_recursive (simpleops_mutex_t *mutex)
+{
+}
+
+/**
+ * Destroy the internal status of a mutex.
+ *
+ * \param[in,out] mutex the mutex to be destroyed.
+ */
+static simpleops_always_inline void
+simpleops_mutex_fini (simpleops_mutex_t *mutex)
+{
+}
+
+/**
+ * Lock a mutex.
+ *
+ * \param[in,out] mutex the mutex to be locked.
+ */
+static simpleops_always_inline void
+simpleops_mutex_lock (simpleops_mutex_t *mutex)
+{
+}
+
+/**
+ * Unlock a mutex.
+ *
+ * \param[in,out] mutex the mutex to be unlocked.
+ */
+static simpleops_always_inline void
+simpleops_mutex_unlock (simpleops_mutex_t *mutex)
+{
+}
+
+#endif
+
+#endif
diff --git a/mutex/impl/simpleops-mutex-impl-no.h b/mutex/impl/simpleops-mutex-impl-no.h
new file mode 100644
index 0000000..1262161
--- /dev/null
+++ b/mutex/impl/simpleops-mutex-impl-no.h
@@ -0,0 +1,70 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_MUTEX_IMPL_NO_H
+#define SIMPLEOPS_MUTEX_IMPL_NO_H
+
+#ifndef SIMPLEOPS_MUTEX_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_MUTEX_IMPL && \
+ defined(SIMPLEOPS_DISABLE_MUTEX)
+
+#define SIMPLEOPS_HAVE_MUTEX_IMPL 1
+#define SIMPLEOPS_HAVE_MUTEX_IMPL_NO 1
+
+typedef int simpleops_mutex_t;
+
+static simpleops_always_inline void
+simpleops_mutex_init (simpleops_mutex_t *mutex)
+{
+}
+
+static simpleops_always_inline void
+simpleops_mutex_init_recursive (simpleops_mutex_t *mutex)
+{
+}
+
+static simpleops_always_inline void
+simpleops_mutex_fini (simpleops_mutex_t *mutex)
+{
+}
+
+static simpleops_always_inline void
+simpleops_mutex_lock (simpleops_mutex_t *mutex)
+{
+}
+
+static simpleops_always_inline void
+simpleops_mutex_unlock (simpleops_mutex_t *mutex)
+{
+}
+
+#endif
+
+#endif
diff --git a/mutex/impl/simpleops-mutex-impl-os2.h b/mutex/impl/simpleops-mutex-impl-os2.h
new file mode 100644
index 0000000..826195e
--- /dev/null
+++ b/mutex/impl/simpleops-mutex-impl-os2.h
@@ -0,0 +1,79 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_MUTEX_IMPL_OS2_H
+#define SIMPLEOPS_MUTEX_IMPL_OS2_H
+
+#ifndef SIMPLEOPS_MUTEX_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_MUTEX_IMPL && \
+ __OS2__
+
+#define SIMPLEOPS_HAVE_MUTEX_IMPL 1
+#define SIMPLEOPS_HAVE_MUTEX_IMPL_OS2 1
+
+#define INCL_BASE
+#define INCL_PM
+#include <os2.h>
+
+typedef HMTX simpleops_mutex_t;
+
+static simpleops_always_inline void
+simpleops_mutex_init (simpleops_mutex_t *mutex)
+{
+ DosCreateMutexSem (NULL, mutex, 0L, FALSE);
+}
+
+static simpleops_always_inline void
+simpleops_mutex_init_recursive (simpleops_mutex_t *mutex)
+{
+ DosCreateMutexSem (NULL, mutex, 0L, FALSE);
+}
+
+static simpleops_always_inline void
+simpleops_mutex_fini (simpleops_mutex_t *mutex)
+{
+ DosCloseMutexSem (*mutex);
+}
+
+static simpleops_always_inline void
+simpleops_mutex_lock (simpleops_mutex_t *mutex)
+{
+ DosRequestMutexSem (*mutex, SEM_INDEFINITE_WAIT);
+}
+
+static simpleops_always_inline void
+simpleops_mutex_unlock (simpleops_mutex_t *mutex)
+{
+ DosReleaseMutexSem (*mutex);
+}
+
+#endif
+
+#endif
diff --git a/mutex/impl/simpleops-mutex-impl-pthread.h b/mutex/impl/simpleops-mutex-impl-pthread.h
new file mode 100644
index 0000000..91e3200
--- /dev/null
+++ b/mutex/impl/simpleops-mutex-impl-pthread.h
@@ -0,0 +1,82 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_MUTEX_IMPL_PTHREAD_H
+#define SIMPLEOPS_MUTEX_IMPL_PTHREAD_H
+
+#ifndef SIMPLEOPS_MUTEX_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_MUTEX_IMPL && \
+ SIMPLEOPS_HAVE_PTHREAD
+
+#define SIMPLEOPS_HAVE_MUTEX_IMPL 1
+#define SIMPLEOPS_HAVE_MUTEX_IMPL_PTHREAD 1
+
+#include <pthread.h>
+
+typedef pthread_mutex_t simpleops_mutex_t;
+
+static simpleops_always_inline void
+simpleops_mutex_init (simpleops_mutex_t *mutex)
+{
+ pthread_mutex_init (mutex, NULL);
+}
+
+static simpleops_always_inline void
+simpleops_mutex_init_recursive (simpleops_mutex_t *mutex)
+{
+ pthread_mutexattr_t attr;
+
+ pthread_mutexattr_init (&attr);
+ pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
+ pthread_mutex_init (mutex, &attr);
+ pthread_mutexattr_destroy (&attr);
+}
+
+static simpleops_always_inline void
+simpleops_mutex_fini (simpleops_mutex_t *mutex)
+{
+ pthread_mutex_destroy (mutex);
+}
+
+static simpleops_always_inline void
+simpleops_mutex_lock (simpleops_mutex_t *mutex)
+{
+ pthread_mutex_lock (mutex);
+}
+
+static simpleops_always_inline void
+simpleops_mutex_unlock (simpleops_mutex_t *mutex)
+{
+ pthread_mutex_unlock (mutex);
+}
+
+#endif
+
+#endif
diff --git a/mutex/impl/simpleops-mutex-impl-template.h b/mutex/impl/simpleops-mutex-impl-template.h
new file mode 100644
index 0000000..9632d4f
--- /dev/null
+++ b/mutex/impl/simpleops-mutex-impl-template.h
@@ -0,0 +1,70 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_MUTEX_IMPL_TEMPLATE_H
+#define SIMPLEOPS_MUTEX_IMPL_TEMPLATE_H
+
+#ifndef SIMPLEOPS_MUTEX_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_MUTEX_IMPL && \
+ 0
+
+#define SIMPLEOPS_HAVE_MUTEX_IMPL 1
+#define SIMPLEOPS_HAVE_MUTEX_IMPL_TEMPLATE 1
+
+typedef int simpleops_mutex_t;
+
+static simpleops_always_inline void
+simpleops_mutex_init (simpleops_mutex_t *mutex)
+{
+}
+
+static simpleops_always_inline void
+simpleops_mutex_init_recursive (simpleops_mutex_t *mutex)
+{
+}
+
+static simpleops_always_inline void
+simpleops_mutex_fini (simpleops_mutex_t *mutex)
+{
+}
+
+static simpleops_always_inline void
+simpleops_mutex_lock (simpleops_mutex_t *mutex)
+{
+}
+
+static simpleops_always_inline void
+simpleops_mutex_unlock (simpleops_mutex_t *mutex)
+{
+}
+
+#endif
+
+#endif
diff --git a/mutex/impl/simpleops-mutex-impl-win32.h b/mutex/impl/simpleops-mutex-impl-win32.h
new file mode 100644
index 0000000..1a0f2f8
--- /dev/null
+++ b/mutex/impl/simpleops-mutex-impl-win32.h
@@ -0,0 +1,78 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_MUTEX_IMPL_WIN32_H
+#define SIMPLEOPS_MUTEX_IMPL_WIN32_H
+
+#ifndef SIMPLEOPS_MUTEX_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_MUTEX_IMPL && \
+ defined(_WIN32)
+
+#define SIMPLEOPS_HAVE_MUTEX_IMPL 1
+#define SIMPLEOPS_HAVE_MUTEX_IMPL_WIN32 1
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+typedef CRITICAL_SECTION simpleops_mutex_t;
+
+static simpleops_always_inline void
+simpleops_mutex_init (simpleops_mutex_t *mutex)
+{
+ InitializeCriticalSection (mutex);
+}
+
+static simpleops_always_inline void
+simpleops_mutex_init_recursive (simpleops_mutex_t *mutex)
+{
+ InitializeCriticalSection (mutex);
+}
+
+static simpleops_always_inline void
+simpleops_mutex_fini (simpleops_mutex_t *mutex)
+{
+ DeleteCriticalSection (mutex);
+}
+
+static simpleops_always_inline void
+simpleops_mutex_lock (simpleops_mutex_t *mutex)
+{
+ EnterCriticalSection (mutex);
+}
+
+static simpleops_always_inline void
+simpleops_mutex_unlock (simpleops_mutex_t *mutex)
+{
+ LeaveCriticalSection (mutex);
+}
+
+#endif
+
+#endif
diff --git a/mutex/impl/simpleops-mutex-impl.h b/mutex/impl/simpleops-mutex-impl.h
new file mode 100644
index 0000000..9cff3b0
--- /dev/null
+++ b/mutex/impl/simpleops-mutex-impl.h
@@ -0,0 +1,49 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_MUTEX_IMPL_H
+#define SIMPLEOPS_MUTEX_IMPL_H
+
+#ifndef SIMPLEOPS_MUTEX_H
+#error Private header used directly
+#endif
+
+/* DIFFTABLE */
+#include "simpleops/mutex/impl/simpleops-mutex-impl-template.h"
+#include "simpleops/mutex/impl/simpleops-mutex-impl-doc.h"
+#include "simpleops/mutex/impl/simpleops-mutex-impl-no.h"
+#include "simpleops/mutex/impl/simpleops-mutex-impl-win32.h"
+#include "simpleops/mutex/impl/simpleops-mutex-impl-beos.h"
+#include "simpleops/mutex/impl/simpleops-mutex-impl-os2.h"
+#include "simpleops/mutex/impl/simpleops-mutex-impl-pthread.h"
+/* DIFFTABLE */
+
+#if ! SIMPLEOPS_HAVE_MUTEX_IMPL
+#error No implementation available
+#endif
+
+#endif
diff --git a/mutex/simpleops-mutex.h b/mutex/simpleops-mutex.h
new file mode 100644
index 0000000..1781190
--- /dev/null
+++ b/mutex/simpleops-mutex.h
@@ -0,0 +1,35 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_MUTEX_H
+#define SIMPLEOPS_MUTEX_H
+
+#include "simpleops/compiler/simpleops-compiler.h"
+
+#include "simpleops/mutex/impl/simpleops-mutex-impl.h"
+
+#endif
diff --git a/template/impl/simpleops-template-impl-template.h b/template/impl/simpleops-template-impl-template.h
new file mode 100644
index 0000000..8ab220a
--- /dev/null
+++ b/template/impl/simpleops-template-impl-template.h
@@ -0,0 +1,43 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TEMPLATE_IMPL_TEMPLATE_H
+#define SIMPLEOPS_TEMPLATE_IMPL_TEMPLATE_H
+
+#ifndef SIMPLEOPS_TEMPLATE_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_TEMPLATE_IMPL && \
+ 0
+
+#define SIMPLEOPS_HAVE_TEMPLATE_IMPL 1
+#define SIMPLEOPS_HAVE_TEMPLATE_IMPL_TEMPLATE 1
+
+#endif
+
+#endif
diff --git a/template/impl/simpleops-template-impl.h b/template/impl/simpleops-template-impl.h
new file mode 100644
index 0000000..0d9a7e7
--- /dev/null
+++ b/template/impl/simpleops-template-impl.h
@@ -0,0 +1,48 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TEMPLATE_IMPL_H
+#define SIMPLEOPS_TEMPLATE_IMPL_H
+
+#ifndef SIMPLEOPS_TEMPLATE_H
+#error Private header used directly
+#endif
+
+/* DIFFTABLE */
+#include "simpleops/template/impl/simpleops-template-impl-template.h"
+#include "simpleops/atomic/impl/simpleops-atomic-impl-template.h"
+#include "simpleops/initfini/impl/simpleops-initfini-impl-template.h"
+#include "simpleops/mutex/impl/simpleops-mutex-impl-template.h"
+#include "simpleops/thread/impl/simpleops-thread-impl-template.h"
+#include "simpleops/tls/impl/simpleops-tls-impl-template.h"
+/* DIFFTABLE */
+
+#if ! SIMPLEOPS_HAVE_TEMPLATE_IMPL
+#error No implementation available
+#endif
+
+#endif
diff --git a/template/internal/simpleops-template-internal-template.h b/template/internal/simpleops-template-internal-template.h
new file mode 100644
index 0000000..dde74d1
--- /dev/null
+++ b/template/internal/simpleops-template-internal-template.h
@@ -0,0 +1,52 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TEMPLATE_INTERNAL_TEMPLATE_H
+#define SIMPLEOPS_TEMPLATE_INTERNAL_TEMPLATE_H
+
+#ifndef SIMPLEOPS_TEMPLATE_INTERNAL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_TEMPLATE_INTERNAL && \
+ SIMPLEOPS_HAVE_TEMPLATE_IMPL_TEMPLATE
+
+#define SIMPLEOPS_HAVE_TEMPLATE_INTERNAL 1
+
+static simpleops_always_inline void
+_simpleops_template_init (void)
+{
+}
+
+static simpleops_always_inline void
+_simpleops_template_fini (void)
+{
+}
+
+#endif
+
+#endif
diff --git a/template/internal/simpleops-template-internal.h b/template/internal/simpleops-template-internal.h
new file mode 100644
index 0000000..3b16357
--- /dev/null
+++ b/template/internal/simpleops-template-internal.h
@@ -0,0 +1,59 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TEMPLATE_INTERNAL_H
+#define SIMPLEOPS_TEMPLATE_INTERNAL_H
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_COMMON_H
+#error Private header used directly
+#endif
+
+#include "simpleops/template/simpleops-template.h"
+
+/* DIFFTABLE */
+#include "simpleops/template/internal/simpleops-template-internal-template.h"
+#include "simpleops/atomic/internal/simpleops-atomic-internal-template.h"
+#include "simpleops/mutex/internal/simpleops-mutex-internal-template.h"
+#include "simpleops/thread/internal/simpleops-thread-internal-template.h"
+#include "simpleops/tls/internal/simpleops-tls-internal-template.h"
+/* DIFFTABLE */
+
+#if ! SIMPLEOPS_HAVE_TEMPLATE_INTERNAL
+
+static simpleops_always_inline void
+_simpleops_template_init (void)
+{
+}
+
+static simpleops_always_inline void
+_simpleops_template_fini (void)
+{
+}
+
+#endif
+
+#endif
diff --git a/template/simpleops-impl.h b/template/simpleops-impl.h
new file mode 100644
index 0000000..48f543e
--- /dev/null
+++ b/template/simpleops-impl.h
@@ -0,0 +1,40 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_IMPL_H
+#define SIMPLEOPS_IMPL_H
+
+/* DIFFTABLE */
+#include "simpleops/template/impl/simpleops-template-impl.h"
+#include "simpleops/atomic/impl/simpleops-atomic-impl.h"
+#include "simpleops/initfini/impl/simpleops-initfini-impl.h"
+#include "simpleops/mutex/impl/simpleops-mutex-impl.h"
+#include "simpleops/thread/impl/simpleops-thread-impl.h"
+#include "simpleops/tls/impl/simpleops-tls-impl.h"
+/* DIFFTABLE */
+
+#endif
diff --git a/template/simpleops-internal.h b/template/simpleops-internal.h
new file mode 100644
index 0000000..ab8c3c8
--- /dev/null
+++ b/template/simpleops-internal.h
@@ -0,0 +1,39 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_INTERNAL_H
+#define SIMPLEOPS_INTERNAL_H
+
+/* DIFFTABLE */
+#include "simpleops/template/internal/simpleops-template-internal.h"
+#include "simpleops/atomic/internal/simpleops-atomic-internal.h"
+#include "simpleops/mutex/internal/simpleops-mutex-internal.h"
+#include "simpleops/thread/internal/simpleops-thread-internal.h"
+#include "simpleops/tls/internal/simpleops-tls-internal.h"
+/* DIFFTABLE */
+
+#endif
diff --git a/template/simpleops-template.h b/template/simpleops-template.h
new file mode 100644
index 0000000..2c4ac28
--- /dev/null
+++ b/template/simpleops-template.h
@@ -0,0 +1,35 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TEMPLATE_H
+#define SIMPLEOPS_TEMPLATE_H
+
+#include "simpleops/compiler/simpleops-compiler.h"
+
+#include "simpleops/template/impl/simpleops-template-impl.h"
+
+#endif
diff --git a/template/simpleops.h b/template/simpleops.h
new file mode 100644
index 0000000..fa7ef5f
--- /dev/null
+++ b/template/simpleops.h
@@ -0,0 +1,40 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_H
+#define SIMPLEOPS_H
+
+/* DIFFTABLE */
+#include "simpleops/template/simpleops-template.h"
+#include "simpleops/atomic/simpleops-atomic.h"
+#include "simpleops/initfini/simpleops-initfini.h"
+#include "simpleops/mutex/simpleops-mutex.h"
+#include "simpleops/thread/simpleops-thread.h"
+#include "simpleops/tls/simpleops-tls.h"
+/* DIFFTABLE */
+
+#endif
diff --git a/thread/impl/simpleops-thread-impl-doc.h b/thread/impl/simpleops-thread-impl-doc.h
new file mode 100644
index 0000000..df549c4
--- /dev/null
+++ b/thread/impl/simpleops-thread-impl-doc.h
@@ -0,0 +1,90 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_THREAD_IMPL_DOC_H
+#define SIMPLEOPS_THREAD_IMPL_DOC_H
+
+#ifndef SIMPLEOPS_THREAD_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_THREAD_IMPL && \
+ SIMPLEOPS_DOC
+
+/**
+ * Defined whenever the simpleops library is providing an
+ * implementation of thread operations.
+ *
+ * Threads can be used to perform concurrent execution.
+ */
+#define SIMPLEOPS_HAVE_THREAD_IMPL 1
+
+/**
+ * SIMPLEOPS_HAVE_THREAD_IMPL_* identifies which implementation is
+ * being used in the simpleops library to provide thread operations.
+ */
+#define SIMPLEOPS_HAVE_THREAD_IMPL_DOC 1
+
+/**
+ * This is the type used to identify threads in the thread functions.
+ */
+typedef int simpleops_thread_t;
+
+/**
+ * Start a new thread.
+ *
+ * If the value pointed by x is oldv, replace it with newv.
+ *
+ * \param[out] thread the thread identifier.
+ * \param[in] f the function to be executed by the new thread.
+ * \param[in] arg the argument for the function f.
+ *
+ * \return whether the thread was started successfully.
+ */
+static simpleops_always_inline simpleops_bool_t
+simpleops_thread_create (simpleops_thread_t *thread,
+ void * (*f) (void *),
+ void *arg)
+{
+}
+
+/**
+ * Wait for the termination of a thread.
+ *
+ * \param[in] thread the thread identifier.
+ * \param[out] value_ptr the return value of the function running on the thread.
+ *
+ * \return whether the operation was successful.
+ */
+static simpleops_always_inline simpleops_bool_t
+simpleops_thread_join (simpleops_thread_t thread, void **value_ptr)
+{
+}
+
+#endif
+
+#endif
diff --git a/thread/impl/simpleops-thread-impl-no.h b/thread/impl/simpleops-thread-impl-no.h
new file mode 100644
index 0000000..d5bfee8
--- /dev/null
+++ b/thread/impl/simpleops-thread-impl-no.h
@@ -0,0 +1,59 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_THREAD_IMPL_NO_H
+#define SIMPLEOPS_THREAD_IMPL_NO_H
+
+#ifndef SIMPLEOPS_THREAD_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_THREAD_IMPL && \
+ defined(SIMPLEOPS_DISABLE_THREAD)
+
+#define SIMPLEOPS_HAVE_THREAD_IMPL 1
+#define SIMPLEOPS_HAVE_THREAD_IMPL_NO 1
+
+typedef int simpleops_thread_t;
+
+static simpleops_always_inline simpleops_bool_t
+simpleops_thread_create (simpleops_thread_t *thread,
+ void * (*f) (void *),
+ void *arg)
+{
+ return FALSE;
+}
+
+static simpleops_always_inline simpleops_bool_t
+simpleops_thread_join (simpleops_thread_t thread, void **value_ptr)
+{
+ return FALSE;
+}
+
+#endif
+
+#endif
diff --git a/thread/impl/simpleops-thread-impl-pthread.h b/thread/impl/simpleops-thread-impl-pthread.h
new file mode 100644
index 0000000..9182ff5
--- /dev/null
+++ b/thread/impl/simpleops-thread-impl-pthread.h
@@ -0,0 +1,61 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_THREAD_IMPL_PTHREAD_H
+#define SIMPLEOPS_THREAD_IMPL_PTHREAD_H
+
+#ifndef SIMPLEOPS_THREAD_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_THREAD_IMPL && \
+ SIMPLEOPS_HAVE_PTHREAD
+
+#define SIMPLEOPS_HAVE_THREAD_IMPL 1
+#define SIMPLEOPS_HAVE_THREAD_IMPL_PTHREAD 1
+
+#include <pthread.h>
+
+typedef pthread_t simpleops_thread_t;
+
+static simpleops_always_inline simpleops_bool_t
+simpleops_thread_create (simpleops_thread_t *thread,
+ void * (*f) (void *),
+ void *arg)
+{
+ return ! pthread_create (thread, NULL, f, arg);
+}
+
+static simpleops_always_inline simpleops_bool_t
+simpleops_thread_join (simpleops_thread_t thread, void **value_ptr)
+{
+ return ! pthread_join (thread, value_ptr);
+}
+
+#endif
+
+#endif
diff --git a/thread/impl/simpleops-thread-impl-template.h b/thread/impl/simpleops-thread-impl-template.h
new file mode 100644
index 0000000..82a8dc2
--- /dev/null
+++ b/thread/impl/simpleops-thread-impl-template.h
@@ -0,0 +1,57 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_THREAD_IMPL_TEMPLATE_H
+#define SIMPLEOPS_THREAD_IMPL_TEMPLATE_H
+
+#ifndef SIMPLEOPS_THREAD_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_THREAD_IMPL && \
+ 0
+
+#define SIMPLEOPS_HAVE_THREAD_IMPL 1
+#define SIMPLEOPS_HAVE_THREAD_IMPL_TEMPLATE 1
+
+typedef int simpleops_thread_t;
+
+static simpleops_always_inline simpleops_bool_t
+simpleops_thread_create (simpleops_thread_t *thread,
+ void * (*f) (void *),
+ void *arg)
+{
+}
+
+static simpleops_always_inline simpleops_bool_t
+simpleops_thread_join (simpleops_thread_t thread, void **value_ptr)
+{
+}
+
+#endif
+
+#endif
diff --git a/thread/impl/simpleops-thread-impl-win32.h b/thread/impl/simpleops-thread-impl-win32.h
new file mode 100644
index 0000000..ba8f126
--- /dev/null
+++ b/thread/impl/simpleops-thread-impl-win32.h
@@ -0,0 +1,123 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_THREAD_IMPL_WIN32_H
+#define SIMPLEOPS_THREAD_IMPL_WIN32_H
+
+#ifndef SIMPLEOPS_THREAD_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_THREAD_IMPL && \
+ defined(_WIN32)
+
+#define SIMPLEOPS_HAVE_THREAD_IMPL 1
+#define SIMPLEOPS_HAVE_THREAD_IMPL_WIN32 1
+
+#include "simpleops/atomic/simpleops-atomic.h"
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <process.h>
+#include <errno.h>
+
+typedef struct _simpleops_thread_win32 {
+ void *(*f) (void *);
+ void *arg, *value;
+ HANDLE handle;
+} *simpleops_thread_t;
+
+static unsigned __stdcall
+_simpleops_thread_win32_wrapper (void *arg)
+{
+ simpleops_thread_t thread;
+
+ thread = arg;
+ thread->value = thread->f (thread->arg);
+
+ _endthreadex (0);
+ return 0;
+}
+
+static simpleops_always_inline simpleops_bool_t
+simpleops_thread_create (simpleops_thread_t *thread,
+ void * (*f) (void *),
+ void *arg)
+{
+ simpleops_thread_t t;
+ uintptr_t r;
+
+ if (SIMPLEOPS_UNLIKELY (thread == NULL))
+ return FALSE;
+
+ *thread = NULL;
+
+ t = malloc (sizeof (struct _simpleops_thread_win32));
+ if (SIMPLEOPS_UNLIKELY (t == NULL))
+ return FALSE;
+
+ t->f = f;
+ t->arg = arg;
+ t->value = NULL;
+
+ r = _beginthreadex (NULL, 0, _simpleops_thread_win32_wrapper, t, 0, NULL);
+ if (SIMPLEOPS_UNLIKELY (r == 0)) {
+ free (t);
+ return FALSE;
+ }
+
+ t->handle = (HANDLE) r;
+
+ *thread = t;
+
+ return TRUE;
+}
+
+static simpleops_always_inline simpleops_bool_t
+simpleops_thread_join (simpleops_thread_t thread, void **value_ptr)
+{
+ DWORD ret;
+
+ if (SIMPLEOPS_UNLIKELY (thread == NULL))
+ return FALSE;
+
+ ret = WaitForSingleObject (thread->handle, INFINITE);
+ if (SIMPLEOPS_UNLIKELY (ret != WAIT_OBJECT_0))
+ return FALSE;
+
+ if (value_ptr != NULL)
+ *value_ptr = thread->value;
+
+ CloseHandle (thread->handle);
+ free (thread);
+
+ return TRUE;
+}
+
+#endif
+
+#endif
diff --git a/thread/impl/simpleops-thread-impl.h b/thread/impl/simpleops-thread-impl.h
new file mode 100644
index 0000000..b1f67d6
--- /dev/null
+++ b/thread/impl/simpleops-thread-impl.h
@@ -0,0 +1,47 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_THREAD_IMPL_H
+#define SIMPLEOPS_THREAD_IMPL_H
+
+#ifndef SIMPLEOPS_THREAD_H
+#error Private header used directly
+#endif
+
+/* DIFFTABLE */
+#include "simpleops/thread/impl/simpleops-thread-impl-template.h"
+#include "simpleops/thread/impl/simpleops-thread-impl-doc.h"
+#include "simpleops/thread/impl/simpleops-thread-impl-no.h"
+#include "simpleops/thread/impl/simpleops-thread-impl-win32.h"
+#include "simpleops/thread/impl/simpleops-thread-impl-pthread.h"
+/* DIFFTABLE */
+
+#if ! SIMPLEOPS_HAVE_THREAD_IMPL
+#error No implementation available
+#endif
+
+#endif
diff --git a/thread/simpleops-thread.h b/thread/simpleops-thread.h
new file mode 100644
index 0000000..4e165a6
--- /dev/null
+++ b/thread/simpleops-thread.h
@@ -0,0 +1,35 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_THREAD_H
+#define SIMPLEOPS_THREAD_H
+
+#include "simpleops/compiler/simpleops-compiler.h"
+
+#include "simpleops/thread/impl/simpleops-thread-impl.h"
+
+#endif
diff --git a/tls/impl/simpleops-tls-impl-common-tail.h b/tls/impl/simpleops-tls-impl-common-tail.h
new file mode 100644
index 0000000..829a48c
--- /dev/null
+++ b/tls/impl/simpleops-tls-impl-common-tail.h
@@ -0,0 +1,154 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TLS_IMPL_COMMON_TAIL_H
+#define SIMPLEOPS_TLS_IMPL_COMMON_TAIL_H
+
+#ifndef SIMPLEOPS_TLS_IMPL_H
+#error Private header used directly
+#endif
+
+#include <stdlib.h>
+
+static simpleops_tls_t *_simpleops_tls_create (void);
+static void _simpleops_tls_destroy (void *tls);
+
+#define _SIMPLEOPS_TLS_INITIALIZED SIMPLEOPS_ADD_PREFIX (_simpleops_tls_initialized)
+extern simpleops_bool_t _SIMPLEOPS_TLS_INITIALIZED;
+
+/**
+ * Get the pointer to the thread-local storage.
+ *
+ * \return the pointer to the TLS. If the TLS cannot be initialized,
+ * NULL is returned instead.
+ */
+static simpleops_tls_t *
+simpleops_tls_get (void)
+{
+ simpleops_tls_t *tls;
+
+ if (SIMPLEOPS_UNLIKELY (! _SIMPLEOPS_TLS_INITIALIZED))
+ return NULL;
+
+ tls = _simpleops_tls_get ();
+ if (SIMPLEOPS_UNLIKELY (tls == NULL)) {
+ tls = _simpleops_tls_create ();
+
+ if (SIMPLEOPS_UNLIKELY (tls == NULL))
+ return NULL;
+
+ if (SIMPLEOPS_UNLIKELY (_simpleops_tls_set (tls))) {
+ _simpleops_tls_destroy (tls);
+ return NULL;
+ }
+ }
+
+ return tls;
+}
+
+/**
+ * Reset the thread-local storage.
+ *
+ * Destroy the current content of the TLS and reset it to the state
+ * preceding the first simpleops_tls_get() call.
+ */
+static void
+simpleops_tls_reset (void)
+{
+ simpleops_tls_t *tls;
+
+ if (SIMPLEOPS_UNLIKELY (! _SIMPLEOPS_TLS_INITIALIZED))
+ return;
+
+ tls = _simpleops_tls_get ();
+ if (SIMPLEOPS_UNLIKELY (tls == NULL))
+ return;
+
+ if (SIMPLEOPS_UNLIKELY (_simpleops_tls_set (NULL)))
+ return;
+
+ _simpleops_tls_destroy (tls);
+}
+
+static simpleops_always_inline void
+_simpleops_tls_silence_unused_warnings (void)
+{
+ if (simpleops_tls_get () != NULL)
+ simpleops_tls_reset ();
+}
+
+/**
+ * This macro is used to specify what function should be used to
+ * instantiate and initialize the thread-local storage, when needed.
+ *
+ * This macro should be invoked as a declaration of a function. The
+ * invocation must be visible to all the places where the TLS
+ * functions are called.
+ */
+#define SIMPLEOPS_TLS_CREATE(f) \
+ static simpleops_tls_t *_simpleops_tls_create (void) \
+ { \
+ return f (); \
+ }
+
+/**
+ * This macro is used to specify what function should be used to
+ * destroy the content of the thread-local storage, when needed.
+ *
+ * This macro should be invoked as a declaration of a function. The
+ * invocation must be visible to all the places where the TLS
+ * functions are called.
+ */
+#define SIMPLEOPS_TLS_DESTROY(f) \
+ static void _simpleops_tls_destroy (void *tls) \
+ { \
+ f ((simpleops_tls_t *) tls); \
+ }
+
+/**
+ * This macro provides a default implementation for TLS allocation.
+ *
+ * The create function performs dynamic allocation and initializes
+ * the content of the simpleops_tls_t structure to 0 (i.e. it is a
+ * calloc()).
+ *
+ * The destroy function free()s the data.
+ */
+#define SIMPLEOPS_TLS_DEFAULT_ALLOCATOR \
+ static simpleops_tls_t * \
+ _simpleops_tls_create (void) \
+ { \
+ return calloc (1, sizeof (simpleops_tls_t)); \
+ } \
+ \
+ static void \
+ _simpleops_tls_destroy (void *tls) \
+ { \
+ free (tls); \
+ }
+
+#endif
diff --git a/tls/impl/simpleops-tls-impl-common.h b/tls/impl/simpleops-tls-impl-common.h
new file mode 100644
index 0000000..4460a81
--- /dev/null
+++ b/tls/impl/simpleops-tls-impl-common.h
@@ -0,0 +1,47 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TLS_IMPL_COMMON_H
+#define SIMPLEOPS_TLS_IMPL_COMMON_H
+
+#ifndef SIMPLEOPS_TLS_IMPL_H
+#error Private header used directly
+#endif
+
+struct _simpleops_tls_t;
+
+/**
+ * This is the type used to access thread-local storage using the TLS
+ * operations.
+ *
+ * It is defined through a forward-declaration of the struct
+ * _simpleops_tls_t type, which is to be provided by the caller of the
+ * TLS operations.
+ */
+typedef struct _simpleops_tls_t simpleops_tls_t;
+
+#endif
diff --git a/tls/impl/simpleops-tls-impl-doc.h b/tls/impl/simpleops-tls-impl-doc.h
new file mode 100644
index 0000000..97b12de
--- /dev/null
+++ b/tls/impl/simpleops-tls-impl-doc.h
@@ -0,0 +1,61 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TLS_IMPL_DOC_H
+#define SIMPLEOPS_TLS_IMPL_DOC_H
+
+#ifndef SIMPLEOPS_TLS_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_TLS_IMPL && \
+ SIMPLEOPS_DOC
+
+/**
+ * Defined whenever the simpleops library is providing an
+ * implementation of TLS (thread-local storage) operations.
+ *
+ * Thread-local storage can be used to have internal data structure
+ * which are not shared between threads. This can be useful to avoid
+ * race conditions and cache contention and to make adaptive data
+ * structures which reflect the behavior of each thread more
+ * accurately.
+ *
+ * In order to use the TLS operations, the application must define
+ * SIMPLEOPS_PREFIX.
+ */
+#define SIMPLEOPS_HAVE_TLS_IMPL 1
+
+/**
+ * SIMPLEOPS_HAVE_TLS_IMPL_* identifies which implementation is being
+ * used in the simpleops library to provide TLS operations.
+ */
+#define SIMPLEOPS_HAVE_TLS_IMPL_DOC 1
+
+#endif
+
+#endif
diff --git a/tls/impl/simpleops-tls-impl-no.h b/tls/impl/simpleops-tls-impl-no.h
new file mode 100644
index 0000000..220e7f4
--- /dev/null
+++ b/tls/impl/simpleops-tls-impl-no.h
@@ -0,0 +1,55 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TLS_IMPL_NO_H
+#define SIMPLEOPS_TLS_IMPL_NO_H
+
+#ifndef SIMPLEOPS_TLS_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_TLS_IMPL && \
+ defined(SIMPLEOPS_DISABLE_TLS)
+
+#define SIMPLEOPS_HAVE_TLS_IMPL 1
+#define SIMPLEOPS_HAVE_TLS_IMPL_NO 1
+
+static simpleops_always_inline simpleops_tls_t *
+_simpleops_tls_get (void)
+{
+ return NULL;
+}
+
+static simpleops_always_inline int
+_simpleops_tls_set (simpleops_tls_t *tls)
+{
+ return -1;
+}
+
+#endif
+
+#endif
diff --git a/tls/impl/simpleops-tls-impl-pthread.h b/tls/impl/simpleops-tls-impl-pthread.h
new file mode 100644
index 0000000..e76a60e
--- /dev/null
+++ b/tls/impl/simpleops-tls-impl-pthread.h
@@ -0,0 +1,60 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TLS_IMPL_PTHREAD_H
+#define SIMPLEOPS_TLS_IMPL_PTHREAD_H
+
+#ifndef SIMPLEOPS_TLS_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_TLS_IMPL && \
+ SIMPLEOPS_HAVE_PTHREAD
+
+#define SIMPLEOPS_HAVE_TLS_IMPL 1
+#define SIMPLEOPS_HAVE_TLS_IMPL_PTHREAD 1
+
+#include <pthread.h>
+
+#define _SIMPLEOPS_TLS_PTHREAD_KEY SIMPLEOPS_ADD_PREFIX (_simpleops_tls_pthread_key)
+extern pthread_key_t _SIMPLEOPS_TLS_PTHREAD_KEY;
+
+static simpleops_always_inline simpleops_tls_t *
+_simpleops_tls_get (void)
+{
+ return pthread_getspecific (_SIMPLEOPS_TLS_PTHREAD_KEY);
+}
+
+static simpleops_always_inline int
+_simpleops_tls_set (simpleops_tls_t *tls)
+{
+ return pthread_setspecific (_SIMPLEOPS_TLS_PTHREAD_KEY, tls);
+}
+
+#endif
+
+#endif
diff --git a/tls/impl/simpleops-tls-impl-template.h b/tls/impl/simpleops-tls-impl-template.h
new file mode 100644
index 0000000..c08925d
--- /dev/null
+++ b/tls/impl/simpleops-tls-impl-template.h
@@ -0,0 +1,53 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TLS_IMPL_TEMPLATE_H
+#define SIMPLEOPS_TLS_IMPL_TEMPLATE_H
+
+#ifndef SIMPLEOPS_TLS_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_TLS_IMPL && \
+ 0
+
+#define SIMPLEOPS_HAVE_TLS_IMPL 1
+#define SIMPLEOPS_HAVE_TLS_IMPL_TEMPLATE 1
+
+static simpleops_always_inline simpleops_tls_t *
+_simpleops_tls_get (void)
+{
+}
+
+static simpleops_always_inline int
+_simpleops_tls_set (simpleops_tls_t *tls)
+{
+}
+
+#endif
+
+#endif
diff --git a/tls/impl/simpleops-tls-impl-win32.h b/tls/impl/simpleops-tls-impl-win32.h
new file mode 100644
index 0000000..38dfbd0
--- /dev/null
+++ b/tls/impl/simpleops-tls-impl-win32.h
@@ -0,0 +1,62 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TLS_IMPL_WIN32_H
+#define SIMPLEOPS_TLS_IMPL_WIN32_H
+
+#ifndef SIMPLEOPS_TLS_IMPL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_TLS_IMPL && \
+ defined(_WIN32)
+
+#define SIMPLEOPS_HAVE_TLS_IMPL 1
+#define SIMPLEOPS_HAVE_TLS_IMPL_WIN32 1
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#define _SIMPLEOPS_TLS_WIN32_INDEX SIMPLEOPS_ADD_PREFIX (_simpleops_tls_win32_index)
+
+extern DWORD _SIMPLEOPS_TLS_WIN32_INDEX;
+
+static simpleops_always_inline simpleops_tls_t *
+_simpleops_tls_get (void)
+{
+ return TlsGetValue (_SIMPLEOPS_TLS_WIN32_INDEX);
+}
+
+static simpleops_always_inline int
+_simpleops_tls_set (simpleops_tls_t *tls)
+{
+ return ! TlsSetValue (_SIMPLEOPS_TLS_WIN32_INDEX, tls);
+}
+
+#endif
+
+#endif
diff --git a/tls/impl/simpleops-tls-impl.h b/tls/impl/simpleops-tls-impl.h
new file mode 100644
index 0000000..7aa51d3
--- /dev/null
+++ b/tls/impl/simpleops-tls-impl.h
@@ -0,0 +1,50 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TLS_IMPL_H
+#define SIMPLEOPS_TLS_IMPL_H
+
+#ifndef SIMPLEOPS_TLS_H
+#error Private header used directly
+#endif
+
+#include "simpleops/tls/impl/simpleops-tls-impl-common.h"
+
+/* DIFFTABLE */
+#include "simpleops/tls/impl/simpleops-tls-impl-template.h"
+#include "simpleops/tls/impl/simpleops-tls-impl-no.h"
+#include "simpleops/tls/impl/simpleops-tls-impl-win32.h"
+#include "simpleops/tls/impl/simpleops-tls-impl-pthread.h"
+/* DIFFTABLE */
+
+#include "simpleops/tls/impl/simpleops-tls-impl-common-tail.h"
+
+#if ! SIMPLEOPS_HAVE_TLS_IMPL
+#error No implementation available
+#endif
+
+#endif
diff --git a/tls/internal/simpleops-tls-internal-common.h b/tls/internal/simpleops-tls-internal-common.h
new file mode 100644
index 0000000..5d2e538
--- /dev/null
+++ b/tls/internal/simpleops-tls-internal-common.h
@@ -0,0 +1,37 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TLS_INTERNAL_COMMON_H
+#define SIMPLEOPS_TLS_INTERNAL_COMMON_H
+
+#ifndef SIMPLEOPS_TLS_INTERNAL_H
+#error Private header used directly
+#endif
+
+simpleops_private simpleops_bool_t _SIMPLEOPS_TLS_INITIALIZED;
+
+#endif
diff --git a/tls/internal/simpleops-tls-internal-pthread.h b/tls/internal/simpleops-tls-internal-pthread.h
new file mode 100644
index 0000000..35935d2
--- /dev/null
+++ b/tls/internal/simpleops-tls-internal-pthread.h
@@ -0,0 +1,58 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TLS_INTERNAL_PTHREAD_H
+#define SIMPLEOPS_TLS_INTERNAL_PTHREAD_H
+
+#ifndef SIMPLEOPS_TLS_INTERNAL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_TLS_INTERNAL && \
+ SIMPLEOPS_HAVE_TLS_IMPL_PTHREAD
+
+#define SIMPLEOPS_HAVE_TLS_INTERNAL 1
+
+simpleops_private pthread_key_t _SIMPLEOPS_TLS_PTHREAD_KEY;
+
+static simpleops_always_inline void
+_simpleops_tls_init (void)
+{
+ _SIMPLEOPS_TLS_INITIALIZED = ! pthread_key_create (&_SIMPLEOPS_TLS_PTHREAD_KEY,
+ _simpleops_tls_destroy);
+}
+
+static simpleops_always_inline void
+_simpleops_tls_fini (void)
+{
+ if (SIMPLEOPS_LIKELY (_SIMPLEOPS_TLS_INITIALIZED))
+ pthread_key_delete (_SIMPLEOPS_TLS_PTHREAD_KEY);
+}
+
+#endif
+
+#endif
diff --git a/tls/internal/simpleops-tls-internal-template.h b/tls/internal/simpleops-tls-internal-template.h
new file mode 100644
index 0000000..9ac7014
--- /dev/null
+++ b/tls/internal/simpleops-tls-internal-template.h
@@ -0,0 +1,52 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TLS_INTERNAL_TEMPLATE_H
+#define SIMPLEOPS_TLS_INTERNAL_TEMPLATE_H
+
+#ifndef SIMPLEOPS_TLS_INTERNAL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_TLS_INTERNAL && \
+ SIMPLEOPS_HAVE_TLS_IMPL_TEMPLATE
+
+#define SIMPLEOPS_HAVE_TLS_INTERNAL 1
+
+static simpleops_always_inline void
+_simpleops_tls_init (void)
+{
+}
+
+static simpleops_always_inline void
+_simpleops_tls_fini (void)
+{
+}
+
+#endif
+
+#endif
diff --git a/tls/internal/simpleops-tls-internal-win32.h b/tls/internal/simpleops-tls-internal-win32.h
new file mode 100644
index 0000000..eb087f2
--- /dev/null
+++ b/tls/internal/simpleops-tls-internal-win32.h
@@ -0,0 +1,58 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TLS_INTERNAL_WIN32_H
+#define SIMPLEOPS_TLS_INTERNAL_WIN32_H
+
+#ifndef SIMPLEOPS_TLS_INTERNAL_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_TLS_INTERNAL && \
+ SIMPLEOPS_HAVE_TLS_IMPL_WIN32
+
+#define SIMPLEOPS_HAVE_TLS_INTERNAL 1
+
+simpleops_private DWORD _SIMPLEOPS_TLS_WIN32_INDEX;
+
+static simpleops_always_inline void
+_simpleops_tls_init (void)
+{
+ _SIMPLEOPS_TLS_WIN32_INDEX = TlsAlloc ();
+ _SIMPLEOPS_TLS_INITIALIZED = _SIMPLEOPS_TLS_WIN32_INDEX != TLS_OUT_OF_INDEXES;
+}
+
+static simpleops_always_inline void
+_simpleops_tls_fini (void)
+{
+ if (SIMPLEOPS_LIKELY (_SIMPLEOPS_TLS_INITIALIZED))
+ TlsFree (_SIMPLEOPS_TLS_WIN32_INDEX);
+}
+
+#endif
+
+#endif
diff --git a/tls/internal/simpleops-tls-internal.h b/tls/internal/simpleops-tls-internal.h
new file mode 100644
index 0000000..e6ade35
--- /dev/null
+++ b/tls/internal/simpleops-tls-internal.h
@@ -0,0 +1,60 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TLS_INTERNAL_H
+#define SIMPLEOPS_TLS_INTERNAL_H
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_COMMON_H
+#error Private header used directly
+#endif
+
+#include "simpleops/tls/simpleops-tls.h"
+
+#include "simpleops/tls/internal/simpleops-tls-internal-common.h"
+
+/* DIFFTABLE */
+#include "simpleops/tls/internal/simpleops-tls-internal-template.h"
+#include "simpleops/tls/internal/simpleops-tls-internal-win32.h"
+#include "simpleops/tls/internal/simpleops-tls-internal-pthread.h"
+/* DIFFTABLE */
+
+#if ! SIMPLEOPS_HAVE_TLS_INTERNAL
+
+static simpleops_always_inline void
+_simpleops_tls_init (void)
+{
+ _SIMPLEOPS_TLS_INITIALIZED = FALSE;
+}
+
+static simpleops_always_inline void
+_simpleops_tls_fini (void)
+{
+}
+
+#endif
+
+#endif
diff --git a/tls/req/simpleops-tls-req-template.h b/tls/req/simpleops-tls-req-template.h
new file mode 100644
index 0000000..628ee58
--- /dev/null
+++ b/tls/req/simpleops-tls-req-template.h
@@ -0,0 +1,42 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TLS_REQ_TEMPLATE_H
+#define SIMPLEOPS_TLS_REQ_TEMPLATE_H
+
+#ifndef SIMPLEOPS_TLS_REQ_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_TLS_REQ && \
+ SIMPLEOPS_HAVE_TLS_IMPL_TEMPLATE
+
+#define SIMPLEOPS_HAVE_TLS_REQ 1
+
+#endif
+
+#endif
diff --git a/tls/req/simpleops-tls-req-win32.h b/tls/req/simpleops-tls-req-win32.h
new file mode 100644
index 0000000..7476385
--- /dev/null
+++ b/tls/req/simpleops-tls-req-win32.h
@@ -0,0 +1,46 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TLS_REQ_WIN32_H
+#define SIMPLEOPS_TLS_REQ_WIN32_H
+
+#ifndef SIMPLEOPS_TLS_REQ_H
+#error Private header used directly
+#endif
+
+#if ! SIMPLEOPS_HAVE_TLS_REQ && \
+ SIMPLEOPS_HAVE_TLS_IMPL_WIN32
+
+#define SIMPLEOPS_HAVE_TLS_REQ 1
+
+#if ! SIMPLEOPS_HAVE_TLS_DESTRUCTOR
+#error "Win32 TLS requires a TLS destruction callback"
+#endif
+
+#endif
+
+#endif
diff --git a/tls/req/simpleops-tls-req.h b/tls/req/simpleops-tls-req.h
new file mode 100644
index 0000000..3c3a9b7
--- /dev/null
+++ b/tls/req/simpleops-tls-req.h
@@ -0,0 +1,42 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TLS_REQ_H
+#define SIMPLEOPS_TLS_REQ_H
+
+#ifndef SIMPLEOPS_INITFINI_IMPL_COMMON_H
+#error Private header used directly
+#endif
+
+#include "simpleops/tls/simpleops-tls.h"
+
+/* DIFFTABLE */
+#include "simpleops/tls/req/simpleops-tls-req-template.h"
+#include "simpleops/tls/req/simpleops-tls-req-win32.h"
+/* DIFFTABLE */
+
+#endif
diff --git a/tls/simpleops-tls.h b/tls/simpleops-tls.h
new file mode 100644
index 0000000..1250981
--- /dev/null
+++ b/tls/simpleops-tls.h
@@ -0,0 +1,35 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010-2011 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author(s): Andrea Canciani <ranma42@gmail.com>
+ */
+
+#ifndef SIMPLEOPS_TLS_H
+#define SIMPLEOPS_TLS_H
+
+#include "simpleops/compiler/simpleops-compiler.h"
+
+#include "simpleops/tls/impl/simpleops-tls-impl.h"
+
+#endif