1
// Copyright 2012 Google Inc.
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
15
// Author: morlovich@google.com (Maksim Orlovich)
16
// jmarantz@google.com (Joshua Marantz) (refactoring only)
18
#ifndef NET_INSTAWEB_SYSTEM_PUBLIC_APR_THREAD_COMPATIBLE_POOL_H_
19
#define NET_INSTAWEB_SYSTEM_PUBLIC_APR_THREAD_COMPATIBLE_POOL_H_
21
#include "apr_pools.h"
23
namespace net_instaweb {
25
// Creates a pool that can be used in any thread, even when run in
28
// 1) This method must be called from startup phase only
29
// 2) Each pool must be accessed only from a single thread (or otherwise
30
// have its access serialized)
31
// 3) Different pools returned by this function may be safely used concurrently.
32
// 4) It's OK to just use ap_pool_create to create child pools of this one from
33
// multiple threads; those will be re-entrant too (but pools created merely
34
// as children of Apache's pools will not be reentrant in prefork)
36
// In short, pools returned by this method are not fully threadsafe, but
37
// at least they are not thread-hostile, which is what you get with
38
// apr_pool_create in Prefork.
40
// Note: the above is all about the release version of the pool code, the
41
// checking one has some additional locking!
43
// WARNING: you must not call apr_pool_clear on the returned pool. The
44
// returned pool can be used to create sub-pools that can be accessed
45
// in distinct threads, due to a mutex injected into the allocator.
46
// However, if you call apr_pool_clear on the returned pool, the allocator's
47
// mutex will be freed and the pointer to it will be dangling. Subsequent
48
// allocations are likely to crash.
49
apr_pool_t* AprCreateThreadCompatiblePool(apr_pool_t* parent_pool);
51
} // namespace net_instaweb
53
#endif // NET_INSTAWEB_SYSTEM_PUBLIC_APR_THREAD_COMPATIBLE_POOL_H_