Permalink
Browse files

Bring basho_metrics up to date with forks

* realized tick_interval meter parameter

* fixed wrong application name presumption

* priv dir discovery fixed

* hopefully priv dir detection finally fixed

* crash when different vm threads try to update same metric fixed

* fix var name

* dialyzer's warning fix

* export types and '{erl_opts, []}'

* new rebar

* Boost subset refreshed

* Sliding time window sample

* Oops, legacy stdint instead
  • Loading branch information...
1 parent 4ed4c0e commit 0b7474694c1bab3debc6742f0e64d12970d5fccf @petrkozorezov petrkozorezov committed with bsparrow435 Oct 5, 2016
Showing with 21,839 additions and 25,608 deletions.
  1. +86 −9 c_src/basho_metrics_nifs.cpp
  2. +24 −0 c_src/boost/boost/call_traits.hpp
  3. +69 −0 c_src/boost/boost/checked_delete.hpp
  4. +74 −0 c_src/boost/boost/circular_buffer.hpp
  5. +2,821 −0 c_src/boost/boost/circular_buffer/base.hpp
  6. +227 −0 c_src/boost/boost/circular_buffer/debug.hpp
  7. +470 −0 c_src/boost/boost/circular_buffer/details.hpp
  8. +1,425 −0 c_src/boost/boost/circular_buffer/space_optimized.hpp
  9. +43 −0 c_src/boost/boost/circular_buffer_fwd.hpp
  10. +46 −0 c_src/boost/boost/concept/assert.hpp
  11. +16 −0 c_src/boost/boost/concept/detail/backward_compatibility.hpp
  12. +51 −0 c_src/boost/boost/concept/detail/concept_def.hpp
  13. +5 −0 c_src/boost/boost/concept/detail/concept_undef.hpp
  14. +75 −0 c_src/boost/boost/concept/detail/general.hpp
  15. +50 −0 c_src/boost/boost/concept/detail/has_constraints.hpp
  16. +44 −0 c_src/boost/boost/concept/usage.hpp
  17. +1,083 −0 c_src/boost/boost/concept_check.hpp
  18. +0 −27 c_src/boost/boost/config/abi/borland_prefix.hpp
  19. +0 −12 c_src/boost/boost/config/abi/borland_suffix.hpp
  20. +0 −22 c_src/boost/boost/config/abi/msvc_prefix.hpp
  21. +0 −8 c_src/boost/boost/config/abi/msvc_suffix.hpp
  22. +0 −284 c_src/boost/boost/config/compiler/borland.hpp
  23. +0 −178 c_src/boost/boost/config/compiler/codegear.hpp
  24. +0 −100 c_src/boost/boost/config/compiler/common_edg.hpp
  25. +0 −19 c_src/boost/boost/config/compiler/compaq_cxx.hpp
  26. +0 −100 c_src/boost/boost/config/compiler/digitalmars.hpp
  27. +0 −28 c_src/boost/boost/config/compiler/greenhills.hpp
  28. +0 −83 c_src/boost/boost/config/compiler/mpw.hpp
  29. +0 −28 c_src/boost/boost/config/compiler/nvcc.hpp
  30. +0 −79 c_src/boost/boost/config/compiler/pathscale.hpp
  31. +0 −79 c_src/boost/boost/config/compiler/pgi.hpp
  32. +0 −146 c_src/boost/boost/config/compiler/sunpro_cc.hpp
  33. +0 −119 c_src/boost/boost/config/compiler/vacpp.hpp
  34. +0 −15 c_src/boost/boost/config/platform/amigaos.hpp
  35. +0 −26 c_src/boost/boost/config/platform/beos.hpp
  36. +0 −31 c_src/boost/boost/config/platform/irix.hpp
  37. +0 −31 c_src/boost/boost/config/platform/qnxnto.hpp
  38. +0 −28 c_src/boost/boost/config/platform/solaris.hpp
  39. +0 −97 c_src/boost/boost/config/platform/symbian.hpp
  40. +0 −25 c_src/boost/boost/config/platform/vms.hpp
  41. +0 −145 c_src/boost/boost/config/stdlib/dinkumware.hpp
  42. +0 −69 c_src/boost/boost/config/stdlib/libcomo.hpp
  43. +0 −53 c_src/boost/boost/config/stdlib/modena.hpp
  44. +0 −183 c_src/boost/boost/config/stdlib/roguewave.hpp
  45. +0 −51 c_src/boost/boost/config/stdlib/vacpp.hpp
  46. +0 −47 c_src/boost/boost/config/warning_disable.hpp
  47. +164 −0 c_src/boost/boost/detail/call_traits.hpp
  48. +0 −78 c_src/boost/boost/detail/endian.hpp
  49. +487 −0 c_src/boost/boost/detail/indirect_traits.hpp
  50. +494 −0 c_src/boost/boost/detail/iterator.hpp
  51. +0 −449 c_src/boost/boost/detail/limits.hpp
  52. +87 −0 c_src/boost/boost/detail/no_exceptions_support.hpp
  53. +17 −0 c_src/boost/boost/exception/detail/attribute_noreturn.hpp
  54. +456 −0 c_src/boost/boost/exception/exception.hpp
  55. +29 −0 c_src/boost/boost/implicit_cast.hpp
  56. +59 −0 c_src/boost/boost/iterator.hpp
  57. +137 −0 c_src/boost/boost/iterator/detail/config_def.hpp
  58. +25 −0 c_src/boost/boost/iterator/detail/config_undef.hpp
  59. +86 −0 c_src/boost/boost/iterator/detail/enable_if.hpp
  60. +200 −0 c_src/boost/boost/iterator/detail/facade_iterator_category.hpp
  61. +50 −0 c_src/boost/boost/iterator/interoperable.hpp
  62. +365 −0 c_src/boost/boost/iterator/iterator_adaptor.hpp
  63. +188 −0 c_src/boost/boost/iterator/iterator_categories.hpp
  64. +878 −0 c_src/boost/boost/iterator/iterator_facade.hpp
  65. +92 −0 c_src/boost/boost/iterator/iterator_traits.hpp
  66. +69 −0 c_src/boost/boost/iterator/reverse_iterator.hpp
  67. +39 −0 c_src/boost/boost/mpl/always.hpp
  68. +60 −0 c_src/boost/boost/mpl/and.hpp
  69. +229 −0 c_src/boost/boost/mpl/apply.hpp
  70. +107 −0 c_src/boost/boost/mpl/apply_fwd.hpp
  71. +234 −0 c_src/boost/boost/mpl/apply_wrap.hpp
  72. +131 −0 c_src/boost/boost/mpl/arg.hpp
  73. +28 −0 c_src/boost/boost/mpl/arg_fwd.hpp
  74. +370 −0 c_src/boost/boost/mpl/assert.hpp
  75. +31 −0 c_src/boost/boost/mpl/aux_/arg_typedef.hpp
  76. +67 −0 c_src/boost/boost/mpl/aux_/arity_spec.hpp
  77. +34 −0 c_src/boost/boost/mpl/aux_/common_name_wknd.hpp
  78. +28 −0 c_src/boost/boost/mpl/aux_/config/bcc.hpp
  79. +33 −0 c_src/boost/boost/mpl/aux_/config/bind.hpp
  80. +66 −0 c_src/boost/boost/mpl/aux_/config/compiler.hpp
  81. +32 −0 c_src/boost/boost/mpl/aux_/config/has_apply.hpp
  82. +34 −0 c_src/boost/boost/mpl/aux_/config/has_xxx.hpp
  83. +26 −0 c_src/boost/boost/mpl/aux_/config/msvc_typename.hpp
  84. +26 −0 c_src/boost/boost/mpl/aux_/config/pp_counter.hpp
  85. +19 −0 c_src/boost/boost/mpl/aux_/config/use_preprocessed.hpp
  86. +354 −0 c_src/boost/boost/mpl/aux_/full_lambda.hpp
  87. +32 −0 c_src/boost/boost/mpl/aux_/has_apply.hpp
  88. +23 −0 c_src/boost/boost/mpl/aux_/has_type.hpp
  89. +42 −0 c_src/boost/boost/mpl/aux_/include_preprocessed.hpp
  90. +34 −0 c_src/boost/boost/mpl/aux_/msvc_never_true.hpp
  91. +34 −0 c_src/boost/boost/mpl/aux_/na_assert.hpp
  92. +48 −0 c_src/boost/boost/mpl/aux_/nested_type_wknd.hpp
  93. +69 −0 c_src/boost/boost/mpl/aux_/preprocessed/gcc/and.hpp
  94. +169 −0 c_src/boost/boost/mpl/aux_/preprocessed/gcc/apply.hpp
  95. +52 −0 c_src/boost/boost/mpl/aux_/preprocessed/gcc/apply_fwd.hpp
  96. +84 −0 c_src/boost/boost/mpl/aux_/preprocessed/gcc/apply_wrap.hpp
  97. +123 −0 c_src/boost/boost/mpl/aux_/preprocessed/gcc/arg.hpp
  98. +561 −0 c_src/boost/boost/mpl/aux_/preprocessed/gcc/bind.hpp
  99. +52 −0 c_src/boost/boost/mpl/aux_/preprocessed/gcc/bind_fwd.hpp
  100. +558 −0 c_src/boost/boost/mpl/aux_/preprocessed/gcc/full_lambda.hpp
  101. +69 −0 c_src/boost/boost/mpl/aux_/preprocessed/gcc/or.hpp
  102. +105 −0 c_src/boost/boost/mpl/aux_/preprocessed/gcc/placeholders.hpp
  103. +123 −0 c_src/boost/boost/mpl/aux_/preprocessed/gcc/quote.hpp
  104. +97 −0 c_src/boost/boost/mpl/aux_/preprocessed/gcc/template_arity.hpp
  105. +0 −28 c_src/boost/boost/mpl/aux_/preprocessor/filter_params.hpp
  106. +0 −65 c_src/boost/boost/mpl/aux_/preprocessor/sub.hpp
  107. +0 −29 c_src/boost/boost/mpl/aux_/preprocessor/tuple.hpp
  108. +189 −0 c_src/boost/boost/mpl/aux_/template_arity.hpp
  109. +47 −0 c_src/boost/boost/mpl/aux_/type_wrapper.hpp
  110. +551 −0 c_src/boost/boost/mpl/bind.hpp
  111. +99 −0 c_src/boost/boost/mpl/bind_fwd.hpp
  112. +71 −0 c_src/boost/boost/mpl/eval_if.hpp
  113. +640 −0 c_src/boost/boost/mpl/has_xxx.hpp
  114. +45 −0 c_src/boost/boost/mpl/identity.hpp
  115. +29 −0 c_src/boost/boost/mpl/lambda.hpp
  116. +19 −0 c_src/boost/boost/mpl/next.hpp
  117. +49 −0 c_src/boost/boost/mpl/next_prior.hpp
  118. +51 −0 c_src/boost/boost/mpl/not.hpp
  119. +61 −0 c_src/boost/boost/mpl/or.hpp
  120. +100 −0 c_src/boost/boost/mpl/placeholders.hpp
  121. +55 −0 c_src/boost/boost/mpl/protect.hpp
  122. +151 −0 c_src/boost/boost/mpl/quote.hpp
  123. +76 −0 c_src/boost/boost/mpl/void.hpp
  124. +51 −0 c_src/boost/boost/next_prior.hpp
  125. +0 −27 c_src/boost/boost/non_type.hpp
  126. +36 −0 c_src/boost/boost/noncopyable.hpp
  127. +61 −0 c_src/boost/boost/preprocessor/arithmetic/detail/div_base.hpp
  128. +39 −0 c_src/boost/boost/preprocessor/arithmetic/mod.hpp
  129. +39 −0 c_src/boost/boost/preprocessor/comparison/less_equal.hpp
  130. +8 −7 c_src/boost/boost/preprocessor/{iteration/detail/self.hpp → control/deduce_d.hpp}
  131. +0 −536 c_src/boost/boost/preprocessor/control/detail/dmc/while.hpp
  132. +0 −534 c_src/boost/boost/preprocessor/control/detail/edg/while.hpp
  133. +0 −277 c_src/boost/boost/preprocessor/control/detail/msvc/while.hpp
  134. +0 −286 c_src/boost/boost/preprocessor/detail/dmc/auto_rec.hpp
  135. +0 −17 c_src/boost/boost/preprocessor/enum_params.hpp
  136. +0 −17 c_src/boost/boost/preprocessor/iterate.hpp
  137. +0 −99 c_src/boost/boost/preprocessor/iteration/detail/bounds/lower1.hpp
  138. +0 −99 c_src/boost/boost/preprocessor/iteration/detail/bounds/lower2.hpp
  139. +0 −99 c_src/boost/boost/preprocessor/iteration/detail/bounds/lower3.hpp
  140. +0 −99 c_src/boost/boost/preprocessor/iteration/detail/bounds/lower4.hpp
  141. +0 −99 c_src/boost/boost/preprocessor/iteration/detail/bounds/lower5.hpp
  142. +0 −99 c_src/boost/boost/preprocessor/iteration/detail/bounds/upper1.hpp
  143. +0 −99 c_src/boost/boost/preprocessor/iteration/detail/bounds/upper2.hpp
  144. +0 −99 c_src/boost/boost/preprocessor/iteration/detail/bounds/upper3.hpp
  145. +0 −99 c_src/boost/boost/preprocessor/iteration/detail/bounds/upper4.hpp
  146. +0 −99 c_src/boost/boost/preprocessor/iteration/detail/bounds/upper5.hpp
  147. +0 −99 c_src/boost/boost/preprocessor/iteration/detail/finish.hpp
  148. +0 −1,342 c_src/boost/boost/preprocessor/iteration/detail/iter/forward1.hpp
  149. +0 −1,338 c_src/boost/boost/preprocessor/iteration/detail/iter/forward2.hpp
  150. +0 −1,338 c_src/boost/boost/preprocessor/iteration/detail/iter/forward3.hpp
  151. +0 −1,338 c_src/boost/boost/preprocessor/iteration/detail/iter/forward4.hpp
  152. +0 −1,338 c_src/boost/boost/preprocessor/iteration/detail/iter/forward5.hpp
  153. +0 −1,296 c_src/boost/boost/preprocessor/iteration/detail/iter/reverse1.hpp
  154. +0 −1,296 c_src/boost/boost/preprocessor/iteration/detail/iter/reverse2.hpp
  155. +0 −1,296 c_src/boost/boost/preprocessor/iteration/detail/iter/reverse3.hpp
  156. +0 −1,296 c_src/boost/boost/preprocessor/iteration/detail/iter/reverse4.hpp
  157. +0 −1,296 c_src/boost/boost/preprocessor/iteration/detail/iter/reverse5.hpp
  158. +0 −812 c_src/boost/boost/preprocessor/iteration/detail/local.hpp
  159. +0 −782 c_src/boost/boost/preprocessor/iteration/detail/rlocal.hpp
  160. +0 −99 c_src/boost/boost/preprocessor/iteration/detail/start.hpp
  161. +0 −82 c_src/boost/boost/preprocessor/iteration/iterate.hpp
  162. +0 −26 c_src/boost/boost/preprocessor/iteration/local.hpp
  163. +0 −19 c_src/boost/boost/preprocessor/iteration/self.hpp
  164. +0 −279 c_src/boost/boost/preprocessor/list/detail/dmc/fold_left.hpp
  165. +0 −536 c_src/boost/boost/preprocessor/list/detail/edg/fold_left.hpp
  166. +0 −794 c_src/boost/boost/preprocessor/list/detail/edg/fold_right.hpp
  167. +0 −65 c_src/boost/boost/preprocessor/list/for_each_i.hpp
  168. +30 −0 c_src/boost/boost/preprocessor/logical/not.hpp
  169. +0 −536 c_src/boost/boost/preprocessor/repetition/detail/dmc/for.hpp
  170. +0 −534 c_src/boost/boost/preprocessor/repetition/detail/edg/for.hpp
  171. +0 −277 c_src/boost/boost/preprocessor/repetition/detail/msvc/for.hpp
  172. +54 −0 c_src/boost/boost/preprocessor/repetition/enum_binary_params.hpp
  173. +38 −0 c_src/boost/boost/preprocessor/repetition/enum_trailing_params.hpp
  174. +87 −0 c_src/boost/boost/preprocessor/repetition/repeat_from_to.hpp
  175. +49 −0 c_src/boost/boost/preprocessor/seq/cat.hpp
  176. +304 −0 c_src/boost/boost/preprocessor/seq/elem.hpp
  177. +288 −0 c_src/boost/boost/preprocessor/seq/enum.hpp
  178. +1,070 −0 c_src/boost/boost/preprocessor/seq/fold_left.hpp
  179. +61 −0 c_src/boost/boost/preprocessor/seq/for_each_i.hpp
  180. +44 −0 c_src/boost/boost/preprocessor/seq/seq.hpp
  181. +547 −0 c_src/boost/boost/preprocessor/seq/size.hpp
  182. +48 −0 c_src/boost/boost/preprocessor/seq/transform.hpp
  183. +0 −269 c_src/boost/boost/preprocessor/slot/detail/counter.hpp
  184. +0 −49 c_src/boost/boost/preprocessor/slot/detail/def.hpp
  185. +0 −247 c_src/boost/boost/preprocessor/slot/detail/shared.hpp
  186. +0 −267 c_src/boost/boost/preprocessor/slot/detail/slot1.hpp
  187. +0 −267 c_src/boost/boost/preprocessor/slot/detail/slot2.hpp
  188. +0 −267 c_src/boost/boost/preprocessor/slot/detail/slot3.hpp
  189. +0 −267 c_src/boost/boost/preprocessor/slot/detail/slot4.hpp
  190. +0 −267 c_src/boost/boost/preprocessor/slot/detail/slot5.hpp
  191. +0 −32 c_src/boost/boost/preprocessor/slot/slot.hpp
  192. +33 −0 c_src/boost/boost/preprocessor/stringize.hpp
  193. +0 −62 c_src/boost/boost/preprocessor/tuple/to_list.hpp
  194. +91 −0 c_src/boost/boost/throw_exception.hpp
  195. +72 −0 c_src/boost/boost/type_traits/add_pointer.hpp
  196. +17 −0 c_src/boost/boost/type_traits/conversion_traits.hpp
  197. +51 −0 c_src/boost/boost/type_traits/has_trivial_constructor.hpp
  198. +64 −0 c_src/boost/boost/type_traits/has_trivial_copy.hpp
  199. +49 −0 c_src/boost/boost/type_traits/has_trivial_destructor.hpp
  200. +229 −0 c_src/boost/boost/type_traits/is_empty.hpp
  201. +143 −0 c_src/boost/boost/type_traits/is_pod.hpp
  202. +48 −0 c_src/boost/boost/type_traits/is_stateless.hpp
  203. +90 −0 c_src/boost/boost/type_traits/remove_const.hpp
  204. +92 −0 c_src/boost/boost/type_traits/remove_pointer.hpp
  205. +20 −0 c_src/boost/boost/utility.hpp
  206. +102 −0 c_src/boost/boost/utility/addressof.hpp
  207. +87 −0 c_src/boost/boost/utility/base_from_member.hpp
  208. +708 −0 c_src/boost/boost/utility/binary.hpp
  209. +4 −4 c_src/ewma.hpp
  210. +5 −3 c_src/histogram_metric.hpp
  211. +4 −4 c_src/meter_metric.hpp
  212. +84 −0 c_src/sample.hpp
  213. BIN rebar
  214. +5 −5 rebar.config
  215. +39 −22 src/basho_metrics_nifs.erl
@@ -29,20 +29,29 @@
#include <cmath>
#include <vector>
#include <cstring>
+extern "C" {
+ #include <pthread.h>
+}
static ErlNifResourceType* histogram_RESOURCE;
static ErlNifResourceType* meter_RESOURCE;
static const unsigned long DEFAULT_RESERVOIR_SIZE = 1028;
+static const unsigned long DEFAULT_WINDOW_WIDTH = 60000;
+static const unsigned long DEFAULT_METER_TICK_INTERVAL = 1000;
struct meter_handle
{
+ pthread_mutex_t m;
+ unsigned long tick_interval;
meter<> *p;
};
struct histogram_handle
{
+ pthread_mutex_t m;
std::size_t size;
+ std::size_t width;
histogram<> *p;
};
@@ -64,15 +73,17 @@ static ERL_NIF_TERM ATOM_ONE;
static ERL_NIF_TERM ATOM_FIVE;
static ERL_NIF_TERM ATOM_FIFTEEN;
static ERL_NIF_TERM ATOM_SIZE;
+static ERL_NIF_TERM ATOM_WINDOW_WIDTH;
static ERL_NIF_TERM ATOM_STDDEV;
+static ERL_NIF_TERM ATOM_TICK_INTERVAL;
static ErlNifFunc nif_funcs[] =
{
{"histogram_new", 1, histogram_new},
{"histogram_update", 2, histogram_update},
{"histogram_stats", 1, histogram_stats},
{"histogram_clear", 1, histogram_clear},
- {"meter_new", 0, meter_new},
+ {"meter_new", 1, meter_new},
{"meter_update", 2, meter_update},
{"meter_tick", 1, meter_tick},
{"meter_stats", 1, meter_stats},
@@ -113,6 +124,33 @@ ERL_NIF_TERM parse_histogram_option(ErlNifEnv* env, ERL_NIF_TERM item,
handle.size = sample_size;
}
}
+ if (option[0] == ATOM_WINDOW_WIDTH)
+ {
+ unsigned long window_width;
+ if (enif_get_ulong(env, option[1], &window_width))
+ {
+ handle.width = window_width;
+ }
+ }
+ }
+ return ATOM_OK;
+}
+
+ERL_NIF_TERM parse_meter_option(ErlNifEnv* env, ERL_NIF_TERM item,
+ meter_handle& handle)
+{
+ int arity;
+ const ERL_NIF_TERM* option;
+ if (enif_get_tuple(env, item, &arity, &option))
+ {
+ if (option[0] == ATOM_TICK_INTERVAL)
+ {
+ unsigned long tick_interval;
+ if (enif_get_ulong(env, option[1], &tick_interval))
+ {
+ handle.tick_interval = tick_interval;
+ }
+ }
}
return ATOM_OK;
}
@@ -126,9 +164,11 @@ ERL_NIF_TERM histogram_new(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
if (enif_is_list(env, argv[0]))
{
memset(handle, '\0', sizeof(histogram_handle));
+ pthread_mutex_init(&(handle->m), NULL);
handle->size = DEFAULT_RESERVOIR_SIZE;
+ handle->width = DEFAULT_WINDOW_WIDTH;
fold(env, argv[0], parse_histogram_option, *handle);
- handle->p = new histogram<>(handle->size);
+ handle->p = new histogram<>(handle->size, handle->width);
ERL_NIF_TERM result = enif_make_resource(env, handle);
enif_release_resource(handle);
return enif_make_tuple2(env, ATOM_OK, result);
@@ -144,7 +184,9 @@ ERL_NIF_TERM histogram_clear(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]
histogram_handle* handle;
if (enif_get_resource(env,argv[0],histogram_RESOURCE,(void**)&handle))
{
+ pthread_mutex_lock(&(handle->m));
handle->p->clear();
+ pthread_mutex_unlock(&(handle->m));
return ATOM_OK;
}
else
@@ -160,7 +202,9 @@ ERL_NIF_TERM histogram_update(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[
if (enif_get_resource(env,argv[0],histogram_RESOURCE,(void**)&handle) &&
enif_get_ulong(env, argv[1], &sample))
{
+ pthread_mutex_lock(&(handle->m));
handle->p->update(sample);
+ pthread_mutex_unlock(&(handle->m));
return ATOM_OK;
}
else
@@ -174,12 +218,16 @@ ERL_NIF_TERM histogram_stats(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]
histogram_handle* handle;
if (enif_get_resource(env,argv[0],histogram_RESOURCE,(void**)&handle))
{
+ pthread_mutex_lock(&(handle->m));
+
std::vector<double> percentiles;
percentiles.push_back(0.500);
percentiles.push_back(0.950);
percentiles.push_back(0.990);
std::vector<double> scores(handle->p->percentiles(percentiles));
- return enif_make_list8(env,
+
+ ERL_NIF_TERM result =
+ enif_make_list8(env,
STAT_TUPLE(ATOM_MIN, handle->p->min()),
STAT_TUPLE(ATOM_MAX, handle->p->max()),
STAT_TUPLE(ATOM_MEAN, handle->p->mean()),
@@ -189,6 +237,8 @@ ERL_NIF_TERM histogram_stats(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]
STAT_TUPLE(ATOM_P95, scores[1]),
STAT_TUPLE(ATOM_P99, scores[2]));
+ pthread_mutex_unlock(&(handle->m));
+ return result;
}
else
return enif_make_badarg(env);
@@ -199,19 +249,31 @@ ERL_NIF_TERM meter_new(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
meter_handle *handle =
(meter_handle *)enif_alloc_resource(meter_RESOURCE,
sizeof(meter_handle));
- memset(handle, '\0', sizeof(meter_handle));
- handle->p = new meter<>;
- ERL_NIF_TERM result = enif_make_resource(env, handle);
- enif_release_resource(handle);
- return enif_make_tuple2(env, ATOM_OK, result);
+ if (enif_is_list(env, argv[0]))
+ {
+ memset(handle, '\0', sizeof(meter_handle));
+ pthread_mutex_init(&(handle->m), NULL);
+ handle->tick_interval = DEFAULT_METER_TICK_INTERVAL;
+ fold(env, argv[0], parse_meter_option, *handle);
+ handle->p = new meter<>(handle->tick_interval);
+ ERL_NIF_TERM result = enif_make_resource(env, handle);
+ enif_release_resource(handle);
+ return enif_make_tuple2(env, ATOM_OK, result);
+ }
+ else
+ {
+ return enif_make_badarg(env);
+ }
}
ERL_NIF_TERM meter_tick(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
meter_handle *handle;
if (enif_get_resource(env,argv[0],meter_RESOURCE,(void**)&handle))
{
+ pthread_mutex_lock(&(handle->m));
handle->p->tick();
+ pthread_mutex_unlock(&(handle->m));
return ATOM_OK;
}
else
@@ -227,7 +289,9 @@ ERL_NIF_TERM meter_update(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
if (enif_get_resource(env,argv[0],meter_RESOURCE,(void**)&handle) &&
enif_get_ulong(env, argv[1], &sample))
{
+ pthread_mutex_lock(&(handle->m));
handle->p->mark(sample);
+ pthread_mutex_unlock(&(handle->m));
return ATOM_OK;
}
else
@@ -241,13 +305,18 @@ ERL_NIF_TERM meter_stats(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
meter_handle* handle;
if (enif_get_resource(env,argv[0],meter_RESOURCE,(void**)&handle))
{
- return enif_make_list4(env,
+ pthread_mutex_lock(&(handle->m));
+
+ ERL_NIF_TERM result =
+ enif_make_list4(env,
enif_make_tuple2(env,ATOM_COUNT,
enif_make_ulong(env, handle->p->count())),
enif_make_tuple2(env,ATOM_ONE,
enif_make_double(env,handle->p->one())),
enif_make_tuple2(env,ATOM_FIVE,enif_make_double(env, handle->p->five())),
enif_make_tuple2(env,ATOM_FIFTEEN,enif_make_double(env, handle->p->fifteen())));
+ pthread_mutex_unlock(&(handle->m));
+ return result;
}
else
return enif_make_badarg(env);
@@ -256,12 +325,18 @@ ERL_NIF_TERM meter_stats(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
static void histogram_resource_cleanup(ErlNifEnv* env, void* arg)
{
histogram_handle* handle = (histogram_handle*)arg;
+
+ pthread_mutex_destroy(&(handle->m));
+
delete handle->p;
}
static void meter_resource_cleanup(ErlNifEnv* env, void* arg)
{
meter_handle* handle = (meter_handle*)arg;
+
+ pthread_mutex_destroy(&(handle->m));
+
delete handle->p;
}
@@ -299,7 +374,9 @@ static int on_load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info)
ATOM(ATOM_FIVE, "five");
ATOM(ATOM_FIFTEEN, "fifteen");
ATOM(ATOM_SIZE, "size");
+ ATOM(ATOM_WINDOW_WIDTH, "window_width");
ATOM(ATOM_STDDEV, "stddev");
+ ATOM(ATOM_TICK_INTERVAL, "tick_interval");
return 0;
}
@@ -0,0 +1,24 @@
+// (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000.
+// Use, modification and distribution are subject to the Boost Software License,
+// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt).
+//
+// See http://www.boost.org/libs/utility for most recent version including documentation.
+
+// See boost/detail/call_traits.hpp and boost/detail/ob_call_traits.hpp
+// for full copyright notices.
+
+#ifndef BOOST_CALL_TRAITS_HPP
+#define BOOST_CALL_TRAITS_HPP
+
+#ifndef BOOST_CONFIG_HPP
+#include <boost/config.hpp>
+#endif
+
+#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
+#include <boost/detail/ob_call_traits.hpp>
+#else
+#include <boost/detail/call_traits.hpp>
+#endif
+
+#endif // BOOST_CALL_TRAITS_HPP
@@ -0,0 +1,69 @@
+#ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED
+#define BOOST_CHECKED_DELETE_HPP_INCLUDED
+
+// MS compatible compilers support #pragma once
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+//
+// boost/checked_delete.hpp
+//
+// Copyright (c) 2002, 2003 Peter Dimov
+// Copyright (c) 2003 Daniel Frey
+// Copyright (c) 2003 Howard Hinnant
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/utility/checked_delete.html for documentation.
+//
+
+namespace boost
+{
+
+// verify that types are complete for increased safety
+
+template<class T> inline void checked_delete(T * x)
+{
+ // intentionally complex - simplification causes regressions
+ typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
+ (void) sizeof(type_must_be_complete);
+ delete x;
+}
+
+template<class T> inline void checked_array_delete(T * x)
+{
+ typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
+ (void) sizeof(type_must_be_complete);
+ delete [] x;
+}
+
+template<class T> struct checked_deleter
+{
+ typedef void result_type;
+ typedef T * argument_type;
+
+ void operator()(T * x) const
+ {
+ // boost:: disables ADL
+ boost::checked_delete(x);
+ }
+};
+
+template<class T> struct checked_array_deleter
+{
+ typedef void result_type;
+ typedef T * argument_type;
+
+ void operator()(T * x) const
+ {
+ boost::checked_array_delete(x);
+ }
+};
+
+} // namespace boost
+
+#endif // #ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED
Oops, something went wrong.

0 comments on commit 0b74746

Please sign in to comment.