Permalink
Browse files

Merge commit 'HEAD@{2}'

  • Loading branch information...
2 parents 3fc685e + 59a3cc3 commit ce6352e88c22154d53316bae04b0b110db61519b @argv0 argv0 committed Aug 30, 2011
@@ -25,14 +25,8 @@
#include <vector>
static ErlNifResourceType* histogram_RESOURCE;
-static ErlNifResourceType* counter_RESOURCE;
static ErlNifResourceType* meter_RESOURCE;
-struct counter
-{
- boost::atomic_uint64_t value;
-};
-
struct meter_handle
{
meter<> *p;
@@ -43,17 +37,11 @@ struct histogram_handle
histogram<> *p;
};
-struct counter_handle
-{
- counter *p;
-};
-
// Atoms (initialized in on_load)
static ERL_NIF_TERM ATOM_TRUE;
static ERL_NIF_TERM ATOM_FALSE;
static ERL_NIF_TERM ATOM_OK;
static ERL_NIF_TERM ATOM_ERROR;
-static ERL_NIF_TERM ATOM_NOT_FOUND;
static ERL_NIF_TERM ATOM_MIN;
static ERL_NIF_TERM ATOM_MAX;
static ERL_NIF_TERM ATOM_MEAN;
@@ -72,9 +60,6 @@ static ErlNifFunc nif_funcs[] =
{"histogram_update", 2, histogram_update},
{"histogram_stats", 1, histogram_stats},
{"histogram_clear", 1, histogram_clear},
- {"counter_new", 0, counter_new},
- {"counter_increment", 1, counter_increment},
- {"counter_value", 1, counter_value},
{"meter_new", 0, meter_new},
{"meter_update", 2, meter_update},
{"meter_tick", 1, meter_tick},
@@ -84,42 +69,6 @@ static ErlNifFunc nif_funcs[] =
#define ATOM(Id, Value) { Id = enif_make_atom(env, Value); }
#define STAT_TUPLE(Key, Value) enif_make_tuple2(env, Key, enif_make_long(env, Value))
-ERL_NIF_TERM counter_new(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
-{
- counter_handle* handle =
- (counter_handle *)enif_alloc_resource(counter_RESOURCE,
- sizeof(counter_handle));
- memset(handle, '\0', sizeof(counter_handle));
- handle->p = new counter;
- ERL_NIF_TERM result = enif_make_resource(env, handle);
- enif_release_resource(handle);
- return enif_make_tuple2(env, ATOM_OK, result);
-}
-
-ERL_NIF_TERM counter_increment(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
-{
- counter_handle* handle;
- if (enif_get_resource(env,argv[0], counter_RESOURCE,(void**)&handle))
- {
- ++handle->p->value;
- return ATOM_OK;
- }
- else
- {
- return enif_make_badarg(env);
- }
-}
-
-ERL_NIF_TERM counter_value(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
-{
- counter_handle* handle;
- if (enif_get_resource(env,argv[0], counter_RESOURCE,(void**)&handle))
- return enif_make_uint64(env, handle->p->value);
- else
- return enif_make_badarg(env);
-}
-
-
ERL_NIF_TERM histogram_new(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
histogram_handle *handle =
@@ -232,7 +181,9 @@ 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_list3(env,
+ return 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())),
@@ -254,12 +205,6 @@ static void meter_resource_cleanup(ErlNifEnv* env, void* arg)
delete handle->p;
}
-static void counter_resource_cleanup(ErlNifEnv* env, void* arg)
-{
- counter_handle* handle = (counter_handle*)arg;
- delete handle->p;
-}
-
static int on_load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info)
{
ErlNifResourceFlags flags = (ErlNifResourceFlags)
@@ -270,12 +215,6 @@ static int on_load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info)
&histogram_resource_cleanup,
flags,
NULL);
- counter_RESOURCE = enif_open_resource_type(env,
- NULL,
- "counter_resource",
- &counter_resource_cleanup,
- flags,
- NULL);
meter_RESOURCE = enif_open_resource_type(env,
NULL,
"meter_resource",
@@ -287,7 +226,6 @@ static int on_load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info)
ATOM(ATOM_ERROR, "error");
ATOM(ATOM_TRUE, "true");
ATOM(ATOM_FALSE, "false");
- ATOM(ATOM_NOT_FOUND, "not_found");
ATOM(ATOM_MIN, "min");
ATOM(ATOM_MAX, "max");
ATOM(ATOM_MEAN, "mean");
View
@@ -1,6 +1,6 @@
// -------------------------------------------------------------------
//
-//
+// basho_metrics: fast performance metrics for Erlang.
//
// Copyright (c) 2011 Basho Technologies, Inc. All Rights Reserved.
//
@@ -19,8 +19,8 @@
// under the License.
//
// -------------------------------------------------------------------
-#ifndef INCL_ELEVELDB_H
-#define INCL_ELEVELDB_H
+#ifndef BASHO_METRICS_NIFS_H_
+#define BASHO_METRICS_NIFS_H_
extern "C" {
@@ -31,10 +31,6 @@ ERL_NIF_TERM histogram_new(ErlNifEnv*, int, const ERL_NIF_TERM[]);
ERL_NIF_TERM histogram_stats(ErlNifEnv*, int, const ERL_NIF_TERM[]);
ERL_NIF_TERM histogram_clear(ErlNifEnv*, int, const ERL_NIF_TERM[]);
-ERL_NIF_TERM counter_new(ErlNifEnv*, int, const ERL_NIF_TERM[]);
-ERL_NIF_TERM counter_increment(ErlNifEnv*, int, const ERL_NIF_TERM[]);
-ERL_NIF_TERM counter_value(ErlNifEnv*, int, const ERL_NIF_TERM[]);
-
ERL_NIF_TERM meter_new(ErlNifEnv*, int, const ERL_NIF_TERM[]);
ERL_NIF_TERM meter_update(ErlNifEnv*, int, const ERL_NIF_TERM[]);
ERL_NIF_TERM meter_tick(ErlNifEnv*,int, const ERL_NIF_TERM[]);
@@ -1,23 +0,0 @@
-Boost Software License - Version 1.0 - August 17th, 2003
-
-Permission is hereby granted, free of charge, to any person or organization
-obtaining a copy of the software and accompanying documentation covered by
-this license (the "Software") to use, reproduce, display, distribute,
-execute, and transmit the Software, and to prepare derivative works of the
-Software, and to permit third-parties to whom the Software is furnished to
-do so, all subject to the following:
-
-The copyright notices in the Software and this entire statement, including
-the above license grant, this restriction and the following disclaimer,
-must be included in all copies of the Software, in whole or in part, and
-all derivative works of the Software, unless such copies or derivative
-works are solely in the form of machine-executable object code generated by
-a source language processor.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
-SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
-FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
@@ -1,204 +0,0 @@
-#ifndef BOOST_ATOMIC_HPP
-#define BOOST_ATOMIC_HPP
-
-// Copyright (c) 2009 Helge Bahmann
-//
-// 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)
-
-#include <cstddef>
-
-#include <boost/memory_order.hpp>
-#include <boost/atomic/platform.hpp>
-#include <boost/atomic/detail/base.hpp>
-#include <boost/atomic/detail/integral-casts.hpp>
-
-namespace boost {
-
-template<typename T>
-class atomic : public detail::atomic::internal_atomic<T> {
-public:
- typedef detail::atomic::internal_atomic<T> super;
-
- atomic() {}
- explicit atomic(T v) : super(v) {}
-private:
- atomic(const atomic &);
- void operator=(const atomic &);
-};
-
-
-template<>
-class atomic<bool> : private detail::atomic::internal_atomic<bool> {
-public:
- typedef detail::atomic::internal_atomic<bool> super;
-
- atomic() {}
- explicit atomic(bool v) : super(v) {}
-
- using super::load;
- using super::store;
- using super::compare_exchange_strong;
- using super::compare_exchange_weak;
- using super::exchange;
- using super::is_lock_free;
-
- operator bool(void) const volatile {return load();}
- bool operator=(bool v) volatile {store(v); return v;}
-private:
- atomic(const atomic &);
- void operator=(const atomic &);
-};
-
-template<>
-class atomic<void *> : private detail::atomic::internal_atomic<void *, sizeof(void *), int> {
-public:
- typedef detail::atomic::internal_atomic<void *, sizeof(void *), int> super;
-
- atomic() {}
- explicit atomic(void * p) : super(p) {}
- using super::load;
- using super::store;
- using super::compare_exchange_strong;
- using super::compare_exchange_weak;
- using super::exchange;
- using super::is_lock_free;
-
- operator void *(void) const volatile {return load();}
- void * operator=(void * v) volatile {store(v); return v;}
-
-private:
- atomic(const atomic &);
- void * operator=(const atomic &);
-};
-
-/* FIXME: pointer arithmetic still missing */
-
-template<typename T>
-class atomic<T *> : private detail::atomic::internal_atomic<intptr_t> {
-public:
- typedef detail::atomic::internal_atomic<intptr_t> super;
-
- atomic() {}
- explicit atomic(T * p) : super((intptr_t)p) {}
-
- T *load(memory_order order=memory_order_seq_cst) const volatile
- {
- return (T*)super::load(order);
- }
- void store(T *v, memory_order order=memory_order_seq_cst) volatile
- {
- super::store((intptr_t)v, order);
- }
- bool compare_exchange_strong(
- T * &expected,
- T * desired,
- memory_order order=memory_order_seq_cst) volatile
- {
- return compare_exchange_strong(expected, desired, order, detail::atomic::calculate_failure_order(order));
- }
- bool compare_exchange_weak(
- T * &expected,
- T *desired,
- memory_order order=memory_order_seq_cst) volatile
- {
- return compare_exchange_weak(expected, desired, order, detail::atomic::calculate_failure_order(order));
- }
- bool compare_exchange_weak(
- T * &expected,
- T *desired,
- memory_order success_order,
- memory_order failure_order) volatile
- {
- intptr_t expected_=(intptr_t)expected, desired_=(intptr_t)desired;
- bool success=super::compare_exchange_weak(expected_, desired_, success_order, failure_order);
- expected=(T*)expected_;
- return success;
- }
- bool compare_exchange_strong(
- T * &expected,
- T *desired,
- memory_order success_order,
- memory_order failure_order) volatile
- {
- intptr_t expected_=(intptr_t)expected, desired_=(intptr_t)desired;
- bool success=super::compare_exchange_strong(expected_, desired_, success_order, failure_order);
- expected=(T*)expected_;
- return success;
- }
- T *exchange(T * replacement, memory_order order=memory_order_seq_cst) volatile
- {
- return (T*)super::exchange((intptr_t)replacement, order);
- }
- using super::is_lock_free;
-
- operator T *(void) const volatile {return load();}
- T * operator=(T * v) volatile {store(v); return v;}
-
- T * fetch_add(ptrdiff_t diff, memory_order order=memory_order_seq_cst) volatile
- {
- return (T*)super::fetch_add(diff*sizeof(T), order);
- }
- T * fetch_sub(ptrdiff_t diff, memory_order order=memory_order_seq_cst) volatile
- {
- return (T*)super::fetch_sub(diff*sizeof(T), order);
- }
-
- T *operator++(void) volatile {return fetch_add(1)+1;}
- T *operator++(int) volatile {return fetch_add(1);}
- T *operator--(void) volatile {return fetch_sub(1)-1;}
- T *operator--(int) volatile {return fetch_sub(1);}
-private:
- atomic(const atomic &);
- T * operator=(const atomic &);
-};
-
-class atomic_flag : private atomic<int> {
-public:
- typedef atomic<int> super;
- using super::is_lock_free;
-
- atomic_flag(bool initial_state) : super(initial_state?1:0) {}
- atomic_flag() {}
-
- bool test_and_set(memory_order order=memory_order_seq_cst)
- {
- return super::exchange(1, order) != 0;
- }
- void clear(memory_order order=memory_order_seq_cst)
- {
- super::store(0, order);
- }
-};
-
-typedef atomic<char> atomic_char;
-typedef atomic<unsigned char> atomic_uchar;
-typedef atomic<signed char> atomic_schar;
-typedef atomic<uint8_t> atomic_uint8_t;
-typedef atomic<int8_t> atomic_int8_t;
-typedef atomic<unsigned short> atomic_ushort;
-typedef atomic<short> atomic_short;
-typedef atomic<uint16_t> atomic_uint16_t;
-typedef atomic<int16_t> atomic_int16_t;
-typedef atomic<unsigned int> atomic_uint;
-typedef atomic<int> atomic_int;
-typedef atomic<uint32_t> atomic_uint32_t;
-typedef atomic<int32_t> atomic_int32_t;
-typedef atomic<unsigned long> atomic_ulong;
-typedef atomic<long> atomic_long;
-typedef atomic<uint64_t> atomic_uint64_t;
-typedef atomic<int64_t> atomic_int64_t;
-typedef atomic<unsigned long long> atomic_ullong;
-typedef atomic<long long> atomic_llong;
-typedef atomic<void*> atomic_address;
-typedef atomic<bool> atomic_bool;
-
-static inline void atomic_thread_fence(memory_order order)
-{
- detail::atomic::platform_atomic_thread_fence<memory_order>(order);
-}
-
-}
-
-#endif
Oops, something went wrong.

0 comments on commit ce6352e

Please sign in to comment.