~tsarev/percona-server/5.5-processlist_rows_stats-sporadic_fails-fix

« back to all changes in this revision

Viewing changes to HandlerSocket-Plugin-for-MySQL/libhsclient/allocator.hpp

Merge release branch, update version

Create release-5.5.12-20.3 with 5.5.12 changes and release branch from
5.5.11. Update versions to 5.5.12 and 20.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
// vim:sw=2:ai
 
3
 
 
4
/*
 
5
 * Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved.
 
6
 * See COPYRIGHT.txt for details.
 
7
 */
 
8
 
 
9
#ifndef DENA_ALLOCATOR_HPP
 
10
#define DENA_ALLOCATOR_HPP
 
11
 
 
12
#include <stdlib.h>
 
13
#include <string.h>
 
14
 
 
15
#if 0
 
16
extern "C" {
 
17
#include <tlsf.h>
 
18
};
 
19
#define DENA_MALLOC(x) tlsf_malloc(x)
 
20
#define DENA_REALLOC(x, y) tlsf_realloc(x, y)
 
21
#define DENA_FREE(x) tlsf_free(x)
 
22
#define DENA_NEWCHAR(x) static_cast<char *>(tlsf_malloc(x))
 
23
#define DENA_DELETE(x) tlsf_free(x)
 
24
typedef std::allocator<int> allocator_type;
 
25
#endif
 
26
 
 
27
#if 1
 
28
#define DENA_MALLOC(x) malloc(x)
 
29
#define DENA_REALLOC(x, y) realloc(x, y)
 
30
#define DENA_FREE(x) free(x)
 
31
#define DENA_NEWCHAR(x) (new char[x])
 
32
#define DENA_DELETE(x) (delete [] x)
 
33
typedef std::allocator<int> allocator_type;
 
34
#endif
 
35
 
 
36
#if 1
 
37
#define DENA_ALLOCA_ALLOCATE(typ, len) \
 
38
        static_cast<typ *>(alloca((len) * sizeof(typ)))
 
39
#define DENA_ALLOCA_FREE(x)
 
40
#else
 
41
#define DENA_ALLOCA_ALLOCATE(typ, len) \
 
42
        static_cast<typ *>(malloc((len) * sizeof(typ)))
 
43
#define DENA_ALLOCA_FREE(x) free(x)
 
44
#endif
 
45
 
 
46
namespace dena {
 
47
 
 
48
template <typename T> struct auto_alloca_free {
 
49
  auto_alloca_free(T *value) : value(value) { }
 
50
  ~auto_alloca_free() {
 
51
    /* no-op if alloca() is used */
 
52
    DENA_ALLOCA_FREE(value);
 
53
  }
 
54
 private:
 
55
  auto_alloca_free(const auto_alloca_free&);
 
56
  auto_alloca_free& operator =(const auto_alloca_free&);
 
57
 private:
 
58
  T *value;
 
59
};
 
60
 
 
61
};
 
62
 
 
63
#endif
 
64