diff options
author | Sam Bingner <sam@bingner.com> | 2020-04-09 15:04:38 -1000 |
---|---|---|
committer | Sam Bingner <sam@bingner.com> | 2020-04-09 15:04:38 -1000 |
commit | e4718f05d049c1a09fb9662cc3db2d4c5122defe (patch) | |
tree | 287912d2fcd30c8c549607641b1dea28cbd17763 /apt-pkg | |
parent | 129877e1be3d88d6f761d619085ca39ef01b1b09 (diff) |
Revert "Use C++11 threading support instead of pthread"cydia
C++ threading support is on available on iOS7
This reverts commit b28636e54f682dc65aef169f201a34a8e2893369.
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/contrib/error.cc | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/apt-pkg/contrib/error.cc b/apt-pkg/contrib/error.cc index 143b99557..2de13b4ae 100644 --- a/apt-pkg/contrib/error.cc +++ b/apt-pkg/contrib/error.cc @@ -32,11 +32,33 @@ /*}}}*/ // Global Error Object /*{{{*/ +/* If the implementation supports posix threads then the accessor function + is compiled to be thread safe otherwise a non-safe version is used. A + Per-Thread error object is maintained in much the same manner as libc + manages errno */ +#if defined(_POSIX_THREADS) && defined(HAVE_PTHREAD) +#include <pthread.h> + +static pthread_key_t ErrorKey; +static void ErrorDestroy(void *Obj) { delete (GlobalError *)Obj; }; +static void KeyAlloc() { pthread_key_create(&ErrorKey, ErrorDestroy); }; + GlobalError *_GetErrorObj() { - static thread_local GlobalError Obj; - return &Obj; + static pthread_once_t Once = PTHREAD_ONCE_INIT; + pthread_once(&Once, KeyAlloc); + + void *Res = pthread_getspecific(ErrorKey); + if (Res == 0) + pthread_setspecific(ErrorKey, Res = new GlobalError); + return (GlobalError *)Res; +} +#else +GlobalError *_GetErrorObj() { + static GlobalError *Obj = new GlobalError; + return Obj; } +#endif /*}}}*/ // GlobalError::GlobalError - Constructor /*{{{*/ GlobalError::GlobalError() : PendingFlag(false) {} |