1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #ifndef _LOG4CXX_HELPERS_APRINITIALIZER_H 19 #define _LOG4CXX_HELPERS_APRINITIALIZER_H 20 21 #ifndef LOG4CXX 22 #error "aprinitializer.h should only be included by log4cxx implementation" 23 #endif 24 25 #include <list> 26 27 extern "C" { 28 typedef struct apr_thread_mutex_t apr_thread_mutex_t; 29 typedef struct apr_threadkey_t apr_threadkey_t; 30 } 31 32 #include <apr_time.h> 33 34 namespace log4cxx 35 { 36 namespace helpers 37 { 38 class FileWatchdog; 39 40 class APRInitializer 41 { 42 public: 43 static log4cxx_time_t initialize(); 44 static apr_pool_t* getRootPool(); 45 static apr_threadkey_t* getTlsKey(); 46 static bool isDestructed; 47 48 /** 49 * Register a FileWatchdog for deletion prior to 50 * APR termination. FileWatchdog must be 51 * allocated on heap and not deleted elsewhere. 52 */ 53 static void registerCleanup(FileWatchdog* watchdog); 54 static void unregisterCleanup(FileWatchdog* watchdog); 55 56 private: 57 APRInitializer(); 58 APRInitializer(const APRInitializer&); 59 APRInitializer& operator=(const APRInitializer&); 60 apr_pool_t* p; 61 apr_thread_mutex_t* mutex; 62 std::list<FileWatchdog*> watchdogs; 63 apr_time_t startTime; 64 apr_threadkey_t* tlsKey; 65 static APRInitializer& getInstance(); 66 67 public: 68 ~APRInitializer(); 69 }; 70 } // namespace helpers 71 } // namespace log4cxx 72 73 #endif //_LOG4CXX_HELPERS_APRINITIALIZER_H 74