From 6f27a7fc6c8471534c5cee39cffdc2def1388bdc Mon Sep 17 00:00:00 2001 From: Arch Librarian Date: Mon, 20 Sep 2004 16:50:57 +0000 Subject: Sync Author: jgg Date: 1998-09-12 02:46:25 GMT Sync --- apt-pkg/contrib/error.cc | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'apt-pkg/contrib/error.cc') diff --git a/apt-pkg/contrib/error.cc b/apt-pkg/contrib/error.cc index d31aaf1b1..42e01e9fe 100644 --- a/apt-pkg/contrib/error.cc +++ b/apt-pkg/contrib/error.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: error.cc,v 1.3 1998/07/12 23:58:46 jgg Exp $ +// $Id: error.cc,v 1.4 1998/09/12 02:46:26 jgg Exp $ /* ###################################################################### Global Erorr Class - Global error mechanism @@ -18,15 +18,46 @@ #pragma implementation "apt-pkg/error.h" #endif +#include + #include #include #include #include +#include -#include /*}}}*/ -GlobalError *_error = new GlobalError; +// 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 _POSIX_THREADS == 1 + #include + + static pthread_key_t ErrorKey; + static void ErrorDestroy(void *Obj) {delete (GlobalError *)Obj;}; + static void KeyAlloc() {pthread_key_create(&ErrorKey,ErrorDestroy);}; + + GlobalError *_GetErrorObj() + { + 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 /*{{{*/ // --------------------------------------------------------------------- -- cgit v1.2.3