diff options
-rw-r--r-- | apt-pkg/contrib/error.cc | 37 | ||||
-rw-r--r-- | apt-pkg/contrib/error.h | 8 | ||||
-rw-r--r-- | apt-pkg/makefile | 1 | ||||
-rw-r--r-- | buildlib/defaults.mak | 2 | ||||
-rw-r--r-- | buildlib/environment.mak.in | 2 |
5 files changed, 41 insertions, 9 deletions
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 <apt-pkg/error.h> + #include <errno.h> #include <stdio.h> #include <string.h> #include <stdarg.h> +#include <unistd.h> -#include <apt-pkg/error.h> /*}}}*/ -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 <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 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 /*{{{*/ // --------------------------------------------------------------------- diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h index 5d015c417..7250bb1c0 100644 --- a/apt-pkg/contrib/error.h +++ b/apt-pkg/contrib/error.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: error.h,v 1.3 1998/07/12 23:58:47 jgg Exp $ +// $Id: error.h,v 1.4 1998/09/12 02:46:27 jgg Exp $ /* ###################################################################### Global Erorr Class - Global error mechanism @@ -82,8 +82,8 @@ class GlobalError GlobalError(); }; -/* The 'extra-ansi' syntax is used to help with collisions. This is the - single global instance of this class. */ -extern GlobalError *_error; +// The 'extra-ansi' syntax is used to help with collisions. +GlobalError *_GetErrorObj(); +#define _error _GetErrorObj() #endif diff --git a/apt-pkg/makefile b/apt-pkg/makefile index 1c28711fe..d0d9cb63a 100644 --- a/apt-pkg/makefile +++ b/apt-pkg/makefile @@ -13,6 +13,7 @@ include ../buildlib/defaults.mak LIBRARY=apt-pkg MAJOR=2 MINOR=0.0 +SLIBS=$(PTHREADLIB) # Source code for the contributed non-core things SOURCE = contrib/mmap.cc contrib/error.cc contrib/strutl.cc \ diff --git a/buildlib/defaults.mak b/buildlib/defaults.mak index e9e7546fe..a70d4acd8 100644 --- a/buildlib/defaults.mak +++ b/buildlib/defaults.mak @@ -95,7 +95,7 @@ $(INCLUDE)/%.h $(addprefix $(INCLUDE)/,$(addsuffix /%.h,$(HEADER_TARGETDIRS))) : # makedep program that can be called after compiling, that's illistrated # by the DEPFLAG case. # Compile rules are expected to call this macro after calling the compiler - ifdef INLINEDEPFLAG +ifdef INLINEDEPFLAG define DoDep sed -e "1s/.*:/$(subst /,\\/,$@):/" $(basename $(@F)).d > $(DEP)/$(basename $(@F)).d -rm -f $(basename $(@F)).d diff --git a/buildlib/environment.mak.in b/buildlib/environment.mak.in index 3166c2e7f..4f001cc97 100644 --- a/buildlib/environment.mak.in +++ b/buildlib/environment.mak.in @@ -3,7 +3,7 @@ # C++ compiler options CC = @CC@ -CPPFLAGS+= @CPPFLAGS@ @DEFS@ +CPPFLAGS+= @CPPFLAGS@ @DEFS@ -D_REENTRANT CXX = @CXX@ CXXFLAGS+= @CXXFLAGS@ @X_CFLAGS@ |