Remove apr from LLAtomic32 and rather use std::atomic and thus rename the class to a more generic name of LLAtomic The apr atomics had been problematic as no one ever did bother to call apr_atomic_init. This:
either did lead to crashes if apr was compiled to use a mutex for thread safe variable intialisation
or initialisation was okay, but apr did not synchronize setting the *pointer to a value.
Replace ARP Mutex and Condition with std::mutx and std::conditional_variable
Replace apr threads with std::thread.
Remove now unused APR pool.
Remove apr queue and replace it with a deque and LLMutex.
Because GCC 4.8 has a libstc++ that is a special snowflake and does not define std::atomic_(u)int32_t
More changed for gcc.
Need to include lltimer.h for ms_sleep
Fix typo in LLThreadSafeQueue<ElementT>::popBack. visual Studio did not care as method never is instantiated.
After input from Nat:
Rename LLAtomic to LLAtomicBase
LLAtomicBase has now only one required argument, the type to wrap. The other will be deduced as std::atomic< Type > if not supplied.
I did notice the forward declaration in llapp.h was not used, so away with it.
Change pointer to member where possible and do a bit of cleanup in lerror (move the mutexex in there and us the LLMutextTryLock rather than a custom class).
Use LLCondition rather than LLMutex. Then we can conveniently .wait() in popBack rather then having to use a poll loop./
This breaks compatibility with C++98. I suggest using boost mutexes instead.
I ported this code to my viewer, using boost/atomic.hpp, boost/thread/mutex.hpp, boost/thread/locks.hpp and boost/thread/condition_variable.hpp instead of their C++11 equivalents.
It works fine (tested under Linux with gcc v4.6.4, v4.8.5, v4.9.4, v5.5.0, v7.3.0 and clang v6.0.1, and under Windows/VS2013) and preserves the compatibility with pre-v4.9 gcc (v4.7 and v4.8 got partial/exotic C++11 support that requires hacks to properly work, and gcc v4.6 or older versions do not have the C++11 headers).
See however my comment about the missing mLocked = false; in LLScopedLock::unlock().
I also moved the LLAtomic stuff to its own header file (llatomic.h) since it does not have any relation any more with APR.