diff options
Diffstat (limited to 'src/dbus/qdbus_symbols_p.h')
-rw-r--r-- | src/dbus/qdbus_symbols_p.h | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/src/dbus/qdbus_symbols_p.h b/src/dbus/qdbus_symbols_p.h index e3008be761..78b7e049ef 100644 --- a/src/dbus/qdbus_symbols_p.h +++ b/src/dbus/qdbus_symbols_p.h @@ -27,6 +27,8 @@ # include "dbus_minimal_p.h" #endif +#include <atomic> + #ifdef interface # undef interface #endif @@ -35,8 +37,8 @@ QT_BEGIN_NAMESPACE #if !defined QT_LINKED_LIBDBUS -void (*qdbus_resolve_conditionally(const char *name))(); // doesn't print a warning -void (*qdbus_resolve_me(const char *name))(); // prints a warning +QFunctionPointer qdbus_resolve_conditionally(const char *name); // doesn't print a warning +QFunctionPointer qdbus_resolve_me(const char *name); // prints a warning bool qdbus_loadLibDBus(); //# define TRACE_DBUS_CALLS @@ -114,28 +116,34 @@ template <> struct TraceReturn<void> { typedef void Type; }; # define DEBUGRET(ret) # endif -# define DEFINEFUNC(ret, func, args, argcall, funcret) \ - typedef ret (* _q_PTR_##func) args; \ - static inline ret q_##func args \ - { \ - static _q_PTR_##func ptr; \ - DEBUGCALL(#func, argcall); \ - if (!ptr) \ - ptr = (_q_PTR_##func) qdbus_resolve_me(#func); \ - funcret DEBUGRET(ret) ptr argcall; \ +# define DEFINEFUNC(ret, func, args, argcall, funcret) \ + static inline ret q_##func args \ + { \ + using func_ptr = ret (*) args; \ + static std::atomic<func_ptr> atomic_ptr; \ + func_ptr ptr = atomic_ptr.load(std::memory_order_relaxed); \ + DEBUGCALL(#func, argcall); \ + if (!ptr) { \ + ptr = reinterpret_cast<func_ptr>(qdbus_resolve_me(#func)); \ + atomic_ptr.store(ptr, std::memory_order_relaxed); \ + } \ + funcret DEBUGRET(ret) ptr argcall; \ } -# define DEFINEFUNC_CONDITIONALLY(ret, func, args, argcall, funcret, failret) \ - typedef ret (* _q_PTR_##func) args; \ - static inline ret q_##func args \ - { \ - static _q_PTR_##func ptr; \ - DEBUGCALL(#func, argcall); \ - if (!ptr) \ - ptr = (_q_PTR_##func) qdbus_resolve_conditionally(#func); \ - if (!ptr) \ - failret; \ - funcret DEBUGRET(ret) ptr argcall; \ +# define DEFINEFUNC_CONDITIONALLY(ret, func, args, argcall, funcret, failret) \ + static inline ret q_##func args \ + { \ + using func_ptr = ret (*) args; \ + static std::atomic<func_ptr> atomic_ptr; \ + func_ptr ptr = atomic_ptr.load(std::memory_order_relaxed); \ + DEBUGCALL(#func, argcall); \ + if (!ptr) { \ + ptr = reinterpret_cast<func_ptr>(qdbus_resolve_conditionally(#func)); \ + atomic_ptr.store(ptr, std::memory_order_relaxed); \ + } \ + if (!ptr) \ + failret; \ + funcret DEBUGRET(ret) ptr argcall; \ } #else // defined QT_LINKED_LIBDBUS |