Commit 6c136ed2 authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

port large parts to C++

parent be1310ec
......@@ -69,8 +69,8 @@ if(CRITERION_FOUND AND TOPLEVEL_PROJECT)
endif()
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/include/villas/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/villas/config.h
${CMAKE_CURRENT_SOURCE_DIR}/include/villas/config.hpp.in
${CMAKE_CURRENT_BINARY_DIR}/include/villas/config.hpp
)
if(TOPLEVEL_PROJECT)
......
......@@ -30,11 +30,7 @@ enum class State {
PARSED = 2,
CHECKED = 3,
STARTED = 4,
LOADED = 4, /* alias for STARTED used by struct plugin */
OPENED = 4, /* alias for STARTED used by IO */
STOPPED = 5,
UNLOADED = 5, /* alias for STARTED used by struct plugin */
CLOSED = 5, /* alias for STARTED used by struct io */
PENDING_CONNECT = 6,
CONNECTED = 7,
PAUSED = 8,
......
......@@ -24,7 +24,7 @@
#include <jansson.h>
#include <villas/config.h>
#include <villas/config.hpp>
#if JANSSON_VERSION_HEX < 0x020A00
size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags);
......
......@@ -55,10 +55,3 @@
/** Width of log output in characters */
#define LOG_WIDTH 80
#define LOG_HEIGHT 25
/* Hard-coded cache line size */
#if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__)
#define CACHELINE_SIZE 64
#else
#error "Unsupported architecture"
#endif
......@@ -32,7 +32,7 @@
#include <fmt/core.h>
#include <jansson.h>
#include <villas/config.h>
#include <villas/config.hpp>
namespace villas {
......
......@@ -41,7 +41,7 @@ public:
using cnt_t = uintmax_t;
using idx_t = std::vector<cnt_t>::difference_type;
/** Initialize struct hist with supplied values and allocate memory for buckets. */
/** Initialize struct Hist with supplied values and allocate memory for buckets. */
Hist(int buckets = 0, cnt_t warmup = 0);
/** Reset all counters and values back to zero. */
......
......@@ -21,8 +21,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
/** @addtogroup fpga Kernel @{ */
#pragma once
#include <cstddef>
......@@ -140,5 +138,3 @@ public:
} /* namespace pci */
} /* namespace kernel */
} /* namespace villas */
/** @} */
......@@ -22,10 +22,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
/** @addtogroup kernel Kernel
* @{
*/
#pragma once
#include <pthread.h>
......@@ -53,5 +49,3 @@ bool isPreemptible();
} /* namespace villas */
} /* namespace kernel */
} /* namespace rt */
/** @} */
......@@ -7,8 +7,6 @@
* @copyright 2018, Daniel Krebs
*********************************************************************************/
/** @addtogroup fpga Kernel @{ */
#pragma once
#include <list>
......@@ -175,8 +173,6 @@ private:
std::list<std::unique_ptr<Group>> groups;
};
/** @} */
} /* namespace vfio */
} /* namespace kernel */
} /* namespace villas */
......@@ -42,25 +42,27 @@
#define LIST_INIT_STATIC(l) \
__attribute__((constructor(105))) static void UNIQUE(__ctor)() {\
int ret __attribute__((unused)); \
ret = vlist_init(l); \
ret = list_init(l); \
} \
__attribute__((destructor(105))) static void UNIQUE(__dtor)() { \
int ret __attribute__((unused)); \
ret = vlist_destroy(l, nullptr, false); \
ret = list_destroy(l, nullptr, false); \
}
#define vlist_length(list) ((list)->length)
#define vlist_at_safe(list, index) ((list)->length > index ? (list)->array[index] : nullptr)
#define vlist_at(list, index) ((list)->array[index])
#define list_length(list) ((list)->length)
#define list_at_safe(list, index) ((list)->length > index ? (list)->array[index] : nullptr)
#define list_at(list, index) ((list)->array[index])
#define vlist_first(list) vlist_at(list, 0)
#define vlist_last(list) vlist_at(list, (list)->length-1)
#define list_first(list) list_at(list, 0)
#define list_last(list) list_at(list, (list)->length-1)
namespace villas {
/** Callback to search or sort a list. */
typedef int (*cmp_cb_t)(const void *, const void *);
/* The list data structure. */
struct vlist {
struct List {
enum State state; /**< The state of this list. */
void **array; /**< Array of pointers to list elements */
size_t capacity; /**< Size of list::array in elements */
......@@ -72,62 +74,62 @@ struct vlist {
*
* @param l A pointer to the list data structure.
*/
int vlist_init(struct vlist *l) __attribute__ ((warn_unused_result));
int list_init(struct List *l) __attribute__ ((warn_unused_result));
/** Destroy a list and call destructors for all list elements
*
* @param free free() all list members during when calling vlist_destroy()
* @param free free() all list members during when calling list_destroy()
* @param dtor A function pointer to a desctructor which will be called for every list item when the list is destroyed.
* @param l A pointer to the list data structure.
*/
int vlist_destroy(struct vlist *l, dtor_cb_t dtor = nullptr, bool free = false) __attribute__ ((warn_unused_result));
int list_destroy(struct List *l, dtor_cb_t dtor = nullptr, bool free = false) __attribute__ ((warn_unused_result));
/** Append an element to the end of the list */
void vlist_push(struct vlist *l, void *p);
void list_push(struct List *l, void *p);
/** Clear list */
void vlist_clear(struct vlist *l);
void list_clear(struct List *l);
/** Remove all occurences of a list item */
void vlist_remove_all(struct vlist *l, void *p);
void list_remove_all(struct List *l, void *p);
int vlist_remove(struct vlist *l, size_t idx);
int list_remove(struct List *l, size_t idx);
int vlist_insert(struct vlist *l, size_t idx, void *p);
int list_insert(struct List *l, size_t idx, void *p);
/** Return the first element of the list for which cmp returns zero */
void * vlist_search(struct vlist *l, cmp_cb_t cmp, const void *ctx);
void * list_search(struct List *l, cmp_cb_t cmp, const void *ctx);
/** Returns the number of occurences for which cmp returns zero when called on all list elements. */
int vlist_count(struct vlist *l, cmp_cb_t cmp, void *ctx);
int list_count(struct List *l, cmp_cb_t cmp, void *ctx);
/** Return 0 if list contains pointer p */
int vlist_contains(struct vlist *l, void *p);
int list_contains(struct List *l, void *p);
/** Sort the list using the quicksort algorithm of libc */
void vlist_sort(struct vlist *l, cmp_cb_t cmp);
void list_sort(struct List *l, cmp_cb_t cmp);
/** Set single element in list */
int vlist_set(struct vlist *l, unsigned index, void *value);
int list_set(struct List *l, unsigned index, void *value);
/** Return index in list for value.
*
* @retval <0 No list entry matching \p value was found.
* @retval >=0 Entry \p value was found at returned index.
*/
ssize_t vlist_index(struct vlist *l, void *value);
ssize_t list_index(struct List *l, void *value);
/** Extend the list to the given length by filling new slots with given value. */
void vlist_extend(struct vlist *l, size_t len, void *val);
void list_extend(struct List *l, size_t len, void *val);
/** Remove all elements for which the callback returns a non-zero return code. */
void vlist_filter(struct vlist *l, dtor_cb_t cb);
void list_filter(struct List *l, dtor_cb_t cb);
/** Lookup an element from the list based on a name */
template<typename T>
T * vlist_lookup_name(struct vlist *l, const std::string &name)
T * list_lookup_name(struct List *l, const std::string &name)
{
return (T *) vlist_search(l, [](const void *a, const void *b) -> int {
return (T *) list_search(l, [](const void *a, const void *b) -> int {
auto *e = reinterpret_cast<const T *>(a);
auto *s = reinterpret_cast<const std::string *>(b);
......@@ -137,9 +139,11 @@ T * vlist_lookup_name(struct vlist *l, const std::string &name)
/** Lookup index of list element based on name */
template<typename T>
ssize_t vlist_lookup_index(struct vlist *l, const std::string &name)
ssize_t list_lookup_index(struct List *l, const std::string &name)
{
auto *f = vlist_lookup_name<T>(l, name);
auto *f = list_lookup_name<T>(l, name);
return f ? vlist_index(l, f) : -1;
return f ? list_index(l, f) : -1;
}
} /* namespace villas */
......@@ -21,10 +21,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
/** @addtogroup table Print fancy tables
* @{
*/
#pragma once
#include <vector>
......@@ -104,5 +100,3 @@ public:
};
} /* namespace villas */
/** @} */
......@@ -44,7 +44,7 @@
#endif
#if PERIODIC_TASK_IMPL == RDTSC
#include <villas/tsc.h>
#include <villas/tsc.hpp>
#endif
struct Task {
......@@ -61,7 +61,7 @@ struct Task {
#if PERIODIC_TASK_IMPL == TIMERFD
int fd; /**< The timerfd_create(2) file descriptior. */
#elif PERIODIC_TASK_IMPL == RDTSC
struct tsc tsc; /**< Initialized by tsc_init(). */
struct Tsc tsc; /**< Initialized by tsc_init(). */
#endif
/** Create a new task with the given rate. */
......
......@@ -25,7 +25,7 @@
#include <villas/log.hpp>
#include <villas/colors.hpp>
#include <villas/config.h>
#include <villas/config.hpp>
#include <villas/exceptions.hpp>
#include <villas/utils.hpp>
......
......@@ -45,7 +45,7 @@
#define bit_TSC_INVARIANT (1 << 8)
#define bit_RDTSCP (1 << 27)
struct tsc {
struct Tsc {
uint64_t frequency;
bool rdtscp_supported;
......@@ -53,7 +53,7 @@ struct tsc {
};
__attribute__((unused))
static uint64_t tsc_now(struct tsc *t)
static uint64_t tsc_now(struct Tsc *t)
{
uint32_t tsc_aux;
return t->rdtscp_supported
......@@ -61,6 +61,6 @@ static uint64_t tsc_now(struct tsc *t)
: __rdtsc();
}
int tsc_init(struct tsc *t) __attribute__ ((warn_unused_result));
int tsc_init(struct Tsc *t) __attribute__ ((warn_unused_result));
uint64_t tsc_rate_to_cycles(struct tsc *t, double rate);
uint64_t tsc_rate_to_cycles(struct Tsc *t, double rate);
......@@ -37,7 +37,7 @@
#include <openssl/sha.h>
#include <villas/config.h>
#include <villas/config.hpp>
#ifdef __GNUC__
#define LIKELY(x) __builtin_expect((x),1)
......
......@@ -26,7 +26,7 @@
#include <villas/utils.hpp>
#include <villas/hist.hpp>
#include <villas/config.h>
#include <villas/config.hpp>
#include <villas/table.hpp>
#include <villas/exceptions.hpp>
......
......@@ -34,7 +34,7 @@
#include <villas/log.hpp>
#include <villas/utils.hpp>
#include <villas/config.h>
#include <villas/config.hpp>
#include <villas/kernel/kernel.hpp>
#include <villas/kernel/kernel.hpp>
......
......@@ -29,7 +29,7 @@
#include <villas/log.hpp>
#include <villas/utils.hpp>
#include <villas/exceptions.hpp>
#include <villas/config.h>
#include <villas/config.hpp>
#include <villas/kernel/pci.hpp>
using namespace villas::kernel::pci;
......
......@@ -25,7 +25,7 @@
#include <villas/log.hpp>
#include <villas/cpuset.hpp>
#include <villas/config.h>
#include <villas/config.hpp>
#include <villas/utils.hpp>
#include <villas/exceptions.hpp>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment