#ifndef CYLOCAL_HPP
#define CYLOCAL_HPP
+#include <pthread.h>
+
template <typename Type_>
-struct CYLocal {
- Type_ last_;
+class CYLocal {
+ private:
+ static ::pthread_key_t key_;
+
+ Type_ *last_;
+
+ protected:
+ static _finline void Set(Type_ *value) {
+ _assert(::pthread_setspecific(key_, value) == 0);
+ }
- CYLocal(Type_ next) {
- Type_ &top(Top());
- last_ = top;
- top = next;
+ static ::pthread_key_t Key_() {
+ ::pthread_key_t key;
+ ::pthread_key_create(&key, NULL);
+ return key;
}
- ~CYLocal() {
- Top() = last_;
+ public:
+ CYLocal(Type_ *next) {
+ last_ = Get();
+ Set(next);
}
- static Type_ &Top() {
- static __thread Type_ top;
- return top;
+ _finline ~CYLocal() {
+ Set(last_);
+ }
+
+ static _finline Type_ *Get() {
+ return reinterpret_cast<Type_ *>(::pthread_getspecific(key_));
}
};
+template <typename Type_>
+::pthread_key_t CYLocal<Type_>::key_ = Key_();
+
#endif/*CYLOCAL_HPP*/
public CYPool
{
private:
- CYLocal<apr_pool_t *> local_;
+ CYLocal<apr_pool_t> local_;
public:
CYLocalPool() :
};
#define $pool \
- CYLocal<apr_pool_t *>::Top()
+ CYLocal<apr_pool_t>::Get()
#endif/*CYPOOLING_HPP*/