aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/llapr.h
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llcommon/llapr.h')
-rw-r--r--linden/indra/llcommon/llapr.h128
1 files changed, 105 insertions, 23 deletions
diff --git a/linden/indra/llcommon/llapr.h b/linden/indra/llcommon/llapr.h
index a80c1d6..63130a8 100644
--- a/linden/indra/llcommon/llapr.h
+++ b/linden/indra/llcommon/llapr.h
@@ -19,7 +19,8 @@
19 * There are special exceptions to the terms and conditions of the GPL as 19 * There are special exceptions to the terms and conditions of the GPL as
20 * it is applied to this Source Code. View the full text of the exception 20 * it is applied to this Source Code. View the full text of the exception
21 * in the file doc/FLOSS-exception.txt in this software distribution, or 21 * in the file doc/FLOSS-exception.txt in this software distribution, or
22 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception 22 * online at
23 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
23 * 24 *
24 * By copying, modifying or distributing this software, you acknowledge 25 * By copying, modifying or distributing this software, you acknowledge
25 * that you have read and understood your obligations described above, 26 * that you have read and understood your obligations described above,
@@ -48,6 +49,7 @@
48#include "llstring.h" 49#include "llstring.h"
49 50
50extern apr_thread_mutex_t* gLogMutexp; 51extern apr_thread_mutex_t* gLogMutexp;
52extern apr_thread_mutex_t* gCallStacksLogMutexp;
51 53
52/** 54/**
53 * @brief initialize the common apr constructs -- apr itself, the 55 * @brief initialize the common apr constructs -- apr itself, the
@@ -60,18 +62,51 @@ void ll_init_apr();
60 */ 62 */
61void ll_cleanup_apr(); 63void ll_cleanup_apr();
62 64
65//
66//LL apr_pool
67//manage apr_pool_t, destroy allocated apr_pool in the destruction function.
68//
63class LLAPRPool 69class LLAPRPool
64{ 70{
65public: 71public:
66 LLAPRPool(apr_pool_t *parent = NULL, apr_size_t size = 0) ; 72 LLAPRPool(apr_pool_t *parent = NULL, apr_size_t size = 0, BOOL releasePoolFlag = TRUE) ;
67 ~LLAPRPool() ; 73 ~LLAPRPool() ;
68 74
69 apr_pool_t* getAPRPool() {return mPool ; } 75 apr_pool_t* getAPRPool() ;
70 apr_status_t getStatus() {return mStatus ; } 76 apr_status_t getStatus() {return mStatus ; }
71 77
78protected:
79 void releaseAPRPool() ;
80 void createAPRPool() ;
81
82protected:
83 apr_pool_t* mPool ; //pointing to an apr_pool
84 apr_pool_t* mParent ; //parent pool
85 apr_size_t mMaxSize ; //max size of mPool, mPool should return memory to system if allocated memory beyond this limit. However it seems not to work.
86 apr_status_t mStatus ; //status when creating the pool
87 BOOL mReleasePoolFlag ; //if set, mPool is destroyed when LLAPRPool is deleted. default value is true.
88};
89
90//
91//volatile LL apr_pool
92//which clears memory automatically.
93//so it can not hold static data or data after memory is cleared
94//
95class LLVolatileAPRPool : public LLAPRPool
96{
97public:
98 LLVolatileAPRPool(apr_pool_t *parent = NULL, apr_size_t size = 0, BOOL releasePoolFlag = TRUE);
99 ~LLVolatileAPRPool(){}
100
101 apr_pool_t* getVolatileAPRPool() ;
102
103 void clearVolatileAPRPool() ;
104
105 BOOL isFull() ;
106 BOOL isEmpty() {return !mNumActiveRef ;}
72private: 107private:
73 apr_pool_t* mPool ; 108 S32 mNumActiveRef ; //number of active pointers pointing to the apr_pool.
74 apr_status_t mStatus ; 109 S32 mNumTotalRef ; //number of total pointers pointing to the apr_pool since last creating.
75} ; 110} ;
76 111
77/** 112/**
@@ -144,24 +179,71 @@ typedef LLAtomic32<S32> LLAtomicS32;
144#define LL_APR_WB (APR_CREATE|APR_TRUNCATE|APR_WRITE|APR_BINARY) // "wb" 179#define LL_APR_WB (APR_CREATE|APR_TRUNCATE|APR_WRITE|APR_BINARY) // "wb"
145#define LL_APR_RPB (APR_READ|APR_WRITE|APR_BINARY) // "r+b" 180#define LL_APR_RPB (APR_READ|APR_WRITE|APR_BINARY) // "r+b"
146#define LL_APR_WPB (APR_CREATE|APR_TRUNCATE|APR_READ|APR_WRITE|APR_BINARY) // "w+b" 181#define LL_APR_WPB (APR_CREATE|APR_TRUNCATE|APR_READ|APR_WRITE|APR_BINARY) // "w+b"
147apr_file_t* ll_apr_file_open(const std::string& filename, apr_int32_t flags, S32* sizep, apr_pool_t* pool); 182
148apr_file_t* ll_apr_file_open(const std::string& filename, apr_int32_t flags, S32* sizep); 183//
149apr_file_t* ll_apr_file_open(const std::string& filename, apr_int32_t flags, apr_pool_t* pool); 184//apr_file manager
150apr_file_t* ll_apr_file_open(const std::string& filename, apr_int32_t flags); 185//which: 1)only keeps one file open;
151// Returns actual offset, -1 if seek fails 186// 2)closes the open file in the destruction function
152S32 ll_apr_file_seek(apr_file_t* apr_file, apr_seek_where_t where, S32 offset); 187// 3)informs the apr_pool to clean the memory when the file is closed.
153// Returns bytes read/written, 0 if read/write fails: 188//Note: please close an open file at the earliest convenience.
154S32 ll_apr_file_read(apr_file_t* apr_file, void* buf, S32 nbytes); 189// especially do not put some time-costly operations between open() and close().
155S32 ll_apr_file_read_ex(const std::string& filename, apr_pool_t* pool, void *buf, S32 offset, S32 nbytes); 190// otherwise it might lock the APRFilePool.
156S32 ll_apr_file_write(apr_file_t* apr_file, const void* buf, S32 nbytes); 191//there are two different apr_pools the APRFile can use:
157S32 ll_apr_file_write_ex(const std::string& filename, apr_pool_t* pool, void *buf, S32 offset, S32 nbytes); 192// 1, a temperary pool passed to an APRFile function, which is used within this function and only once.
158// returns false if failure: 193// 2, a global pool.
159bool ll_apr_file_remove(const std::string& filename, apr_pool_t* pool = NULL); 194//
160bool ll_apr_file_rename(const std::string& filename, const std::string& newname, apr_pool_t* pool = NULL); 195class LLAPRFile
161bool ll_apr_file_exists(const std::string& filename, apr_pool_t* pool = NULL); 196{
162S32 ll_apr_file_size(const std::string& filename, apr_pool_t* pool = NULL); 197private:
163bool ll_apr_dir_make(const std::string& dirname, apr_pool_t* pool = NULL); 198 apr_file_t* mFile ;
164bool ll_apr_dir_remove(const std::string& dirname, apr_pool_t* pool = NULL); 199 LLVolatileAPRPool *mCurrentFilePoolp ; //currently in use apr_pool, could be one of them: sAPRFilePoolp, or a temp pool.
200
201public:
202 LLAPRFile() ;
203 ~LLAPRFile() ;
204
205 apr_status_t open(LLVolatileAPRPool* pool, const std::string& filename, apr_int32_t flags, S32* sizep = NULL);
206 apr_status_t open(const std::string& filename, apr_int32_t flags, apr_pool_t* pool = NULL, S32* sizep = NULL);
207 apr_status_t close() ;
208
209 // Returns actual offset, -1 if seek fails
210 S32 seek(apr_seek_where_t where, S32 offset);
211 apr_status_t eof() { return apr_file_eof(mFile);}
212
213 // Returns bytes read/written, 0 if read/write fails:
214 S32 read(void* buf, S32 nbytes);
215 S32 write(const void* buf, S32 nbytes);
216
217 apr_file_t* getFileHandle() {return mFile;}
218
219private:
220 apr_pool_t* getAPRFilePool(apr_pool_t* pool) ;
221
222//
223//*******************************************************************************************************************************
224//static components
225//
226public:
227 static LLVolatileAPRPool *sAPRFilePoolp ; //a global apr_pool for APRFile, which is used only when local pool does not exist.
228
229private:
230 static apr_file_t* open(const std::string& filename, LLVolatileAPRPool* pool, apr_int32_t flags);
231 static apr_status_t close(apr_file_t* file, LLVolatileAPRPool* pool) ;
232 static S32 seek(apr_file_t* file, apr_seek_where_t where, S32 offset);
233public:
234 // returns false if failure:
235 static bool remove(const std::string& filename, LLVolatileAPRPool* pool = NULL);
236 static bool rename(const std::string& filename, const std::string& newname, LLVolatileAPRPool* pool = NULL);
237 static bool isExist(const std::string& filename, LLVolatileAPRPool* pool = NULL, apr_int32_t flags = APR_READ);
238 static S32 size(const std::string& filename, LLVolatileAPRPool* pool = NULL);
239 static bool makeDir(const std::string& dirname, LLVolatileAPRPool* pool = NULL);
240 static bool removeDir(const std::string& dirname, LLVolatileAPRPool* pool = NULL);
241
242 // Returns bytes read/written, 0 if read/write fails:
243 static S32 readEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool = NULL);
244 static S32 writeEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool = NULL);
245//*******************************************************************************************************************************
246};
165 247
166/** 248/**
167 * @brief Function which approprately logs error or remains quiet on 249 * @brief Function which approprately logs error or remains quiet on