aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/llapr.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llcommon/llapr.h
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r--linden/indra/llcommon/llapr.h148
1 files changed, 148 insertions, 0 deletions
diff --git a/linden/indra/llcommon/llapr.h b/linden/indra/llcommon/llapr.h
new file mode 100644
index 0000000..a5c217c
--- /dev/null
+++ b/linden/indra/llcommon/llapr.h
@@ -0,0 +1,148 @@
1/**
2 * @file llapr.h
3 * @author Phoenix
4 * @date 2004-11-28
5 * @brief Helper functions for using the apache portable runtime library.
6 *
7 * Copyright (c) 2004-2007, Linden Research, Inc.
8 *
9 * The source code in this file ("Source Code") is provided by Linden Lab
10 * to you under the terms of the GNU General Public License, version 2.0
11 * ("GPL"), unless you have obtained a separate licensing agreement
12 * ("Other License"), formally executed by you and Linden Lab. Terms of
13 * the GPL can be found in doc/GPL-license.txt in this distribution, or
14 * online at http://secondlife.com/developers/opensource/gplv2
15 *
16 * There are special exceptions to the terms and conditions of the GPL as
17 * it is applied to this Source Code. View the full text of the exception
18 * in the file doc/FLOSS-exception.txt in this software distribution, or
19 * online at http://secondlife.com/developers/opensource/flossexception
20 *
21 * By copying, modifying or distributing this software, you acknowledge
22 * that you have read and understood your obligations described above,
23 * and agree to abide by those obligations.
24 *
25 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
26 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
27 * COMPLETENESS OR PERFORMANCE.
28 */
29
30#ifndef LL_LLAPR_H
31#define LL_LLAPR_H
32
33#if LL_LINUX
34#include <sys/param.h> // Need PATH_MAX in APR headers...
35#endif
36
37#include "boost/noncopyable.hpp"
38
39#include "apr-1/apr_thread_proc.h"
40#include "apr-1/apr_thread_mutex.h"
41#include "apr-1/apr_getopt.h"
42#include "apr-1/apr_signal.h"
43#include "apr-1/apr_atomic.h"
44#include "llstring.h"
45
46
47/**
48 * @brief initialize the common apr constructs -- apr itself, the
49 * global pool, and a mutex.
50 */
51void ll_init_apr();
52
53/**
54 * @brief Cleanup those common apr constructs.
55 */
56void ll_cleanup_apr();
57
58/**
59 * @class LLScopedLock
60 * @brief Small class to help lock and unlock mutexes.
61 *
62 * This class is used to have a stack level lock once you already have
63 * an apr mutex handy. The constructor handles the lock, and the
64 * destructor handles the unlock. Instances of this class are
65 * <b>not</b> thread safe.
66 */
67class LLScopedLock : private boost::noncopyable
68{
69public:
70 /**
71 * @brief Constructor which accepts a mutex, and locks it.
72 *
73 * @param mutex An allocated APR mutex. If you pass in NULL,
74 * this wrapper will not lock.
75 */
76 LLScopedLock(apr_thread_mutex_t* mutex);
77
78 /**
79 * @brief Destructor which unlocks the mutex if still locked.
80 */
81 ~LLScopedLock();
82
83 /**
84 * @brief Check lock.
85 */
86 bool isLocked() const { return mLocked; }
87
88 /**
89 * @brief This method unlocks the mutex.
90 */
91 void unlock();
92
93protected:
94 bool mLocked;
95 apr_thread_mutex_t* mMutex;
96};
97
98template <typename Type> class LLAtomic32
99{
100public:
101 LLAtomic32<Type>() {};
102 LLAtomic32<Type>(Type x) {apr_atomic_set32(&mData, apr_uint32_t(x)); };
103 ~LLAtomic32<Type>() {};
104
105 operator const Type() { apr_uint32_t data = apr_atomic_read32(&mData); return Type(data); }
106 Type operator =(const Type& x) { apr_atomic_set32(&mData, apr_uint32_t(x)); return Type(mData); }
107 void operator -=(Type x) { apr_atomic_sub32(&mData, apr_uint32_t(x)); }
108 void operator +=(Type x) { apr_atomic_add32(&mData, apr_uint32_t(x)); }
109 Type operator ++(int) { return apr_atomic_inc32(&mData); } // Type++
110 Type operator --(int) { return apr_atomic_dec32(&mData); } // Type--
111
112private:
113 apr_uint32_t mData;
114};
115
116typedef LLAtomic32<U32> LLAtomicU32;
117typedef LLAtomic32<S32> LLAtomicS32;
118
119// File IO convenience functions.
120// Returns NULL if the file fails to openm sets *sizep to file size of not NULL
121// abbreviated flags
122#define LL_APR_R (APR_READ) // "r"
123#define LL_APR_W (APR_CREATE|APR_TRUNCATE|APR_WRITE) // "w"
124#define LL_APR_RB (APR_READ|APR_BINARY) // "rb"
125#define LL_APR_WB (APR_CREATE|APR_TRUNCATE|APR_WRITE|APR_BINARY) // "wb"
126#define LL_APR_RPB (APR_READ|APR_WRITE|APR_BINARY) // "r+b"
127#define LL_APR_WPB (APR_CREATE|APR_TRUNCATE|APR_READ|APR_WRITE|APR_BINARY) // "w+b"
128apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags, S32* sizep = NULL);
129// Returns actual offset, -1 if seek fails
130S32 ll_apr_file_seek(apr_file_t* apr_file, apr_seek_where_t where, S32 offset);
131// Returns bytes read/written, 0 if read/write fails
132S32 ll_apr_file_read(apr_file_t* apr_file, void* buf, S32 nbytes);
133S32 ll_apr_file_write(apr_file_t* apr_file, const void* buf, S32 nbytes);
134bool ll_apr_file_remove(const LLString& filename);
135bool ll_apr_file_rename(const LLString& filename, const LLString& newname);
136
137/**
138 * @brief Function which approprately logs error or remains quiet on
139 * APR_SUCCESS.
140 * @return Returns <code>true</code> if status is an error condition.
141 */
142bool ll_apr_warn_status(apr_status_t status);
143
144void ll_apr_assert_status(apr_status_t status);
145
146extern "C" apr_pool_t* gAPRPoolp; // Global APR memory pool
147
148#endif // LL_LLAPR_H