~suaweb/nginx/nginx-recipe

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/third_party/mod_spdy/src/mod_spdy/apache/pool_util.h

  • Committer: Frans Elliott
  • Date: 2015-06-12 21:15:13 UTC
  • Revision ID: mastergeek.elliott@gmail.com-20150612211513-un4vguj32deibvb0
Added the actual pagespeed library to the ngx_pagespeed module dir.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2010 Google Inc.
 
2
//
 
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
 
6
//
 
7
//      http://www.apache.org/licenses/LICENSE-2.0
 
8
//
 
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.
 
14
 
 
15
#ifndef MOD_SPDY_APACHE_POOL_UTIL_H_
 
16
#define MOD_SPDY_APACHE_POOL_UTIL_H_
 
17
 
 
18
#include <string>
 
19
 
 
20
#include "apr_pools.h"
 
21
#include "base/logging.h"
 
22
 
 
23
namespace mod_spdy {
 
24
 
 
25
/**
 
26
 * Wrapper object that creates a new apr_pool_t and then destroys it when
 
27
 * deleted (handy for creating a local apr_pool_t on the stack).
 
28
 *
 
29
 * Example usage:
 
30
 *
 
31
 *   apr_status_t SomeFunction() {
 
32
 *     LocalPool local;
 
33
 *     char* buffer = apr_palloc(local.pool(), 1024);
 
34
 *     // Do stuff with buffer; it will dealloc when we leave this scope.
 
35
 *     return APR_SUCCESS;
 
36
 *   }
 
37
 */
 
38
class LocalPool {
 
39
 public:
 
40
  LocalPool() : pool_(NULL) {
 
41
    // apr_pool_create() only fails if we run out of memory.  However, we make
 
42
    // no effort elsewhere in this codebase to deal with running out of memory,
 
43
    // so there's no sense in dealing with it here.  Instead, just assert that
 
44
    // pool creation succeeds.
 
45
    const apr_status_t status = apr_pool_create(&pool_, NULL);
 
46
    CHECK(status == APR_SUCCESS);
 
47
    CHECK(pool_ != NULL);
 
48
  }
 
49
 
 
50
  ~LocalPool() {
 
51
    apr_pool_destroy(pool_);
 
52
  }
 
53
 
 
54
  apr_pool_t* pool() const { return pool_; }
 
55
 
 
56
 private:
 
57
  apr_pool_t* pool_;
 
58
 
 
59
  DISALLOW_COPY_AND_ASSIGN(LocalPool);
 
60
};
 
61
 
 
62
// Helper function for PoolRegisterDelete.
 
63
template <class T>
 
64
apr_status_t DeletionFunction(void* object) {
 
65
  delete static_cast<T*>(object);
 
66
  return APR_SUCCESS;
 
67
}
 
68
 
 
69
// Register a C++ object to be deleted with a pool.
 
70
template <class T>
 
71
void PoolRegisterDelete(apr_pool_t* pool, T* object) {
 
72
  // Note that the "child cleanup" argument below doesn't apply to us, so we
 
73
  // use apr_pool_cleanup_null, which is a no-op cleanup function.
 
74
  apr_pool_cleanup_register(pool, object,
 
75
                            DeletionFunction<T>,  // cleanup function
 
76
                            apr_pool_cleanup_null);  // child cleanup
 
77
}
 
78
 
 
79
// Un-register a C++ object from deletion with a pool.  Essentially, this
 
80
// undoes a previous call to PoolRegisterDelete with the same pool and object.
 
81
template <class T>
 
82
void PoolUnregisterDelete(apr_pool_t* pool, T* object) {
 
83
  apr_pool_cleanup_kill(pool, object, DeletionFunction<T>);
 
84
}
 
85
 
 
86
// Return a string describing the given APR status code.
 
87
std::string AprStatusString(apr_status_t status);
 
88
 
 
89
}  // namespace mod_spdy
 
90
 
 
91
#endif  // MOD_SPDY_APACHE_POOL_UTIL_H_