From ab837b1a185170a0c00c7176ff3c59a700e03e05 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 10 Nov 2015 14:18:11 -0500 Subject: [PATCH] core/idle: Convert file to C Signed-off-by: Anna Schumaker --- core/{idle.cpp => idle.c} | 10 +++++----- core/library.cpp | 2 ++ gui/manager.cpp | 2 +- include/core/idle.h | 3 ++- include/tests/test.h | 2 ++ tests/core/Sconscript | 2 +- tests/core/{idle.cpp => idle.c} | 10 +++++----- tests/core/library.cpp | 2 +- 8 files changed, 19 insertions(+), 14 deletions(-) rename core/{idle.cpp => idle.c} (81%) rename tests/core/{idle.cpp => idle.c} (86%) diff --git a/core/idle.cpp b/core/idle.c similarity index 81% rename from core/idle.cpp rename to core/idle.c index 45a87f42..08b07134 100644 --- a/core/idle.cpp +++ b/core/idle.c @@ -1,4 +1,4 @@ -/** +/* * Copyright 2013 (c) Anna Schumaker. */ #include @@ -18,7 +18,7 @@ static float serviced = 0.0; void idle_schedule(void (*func)(void *), void *data) { - struct idle_task *task = new idle_task; + struct idle_task *task = g_malloc(sizeof(struct idle_task)); task->idle_func = func; task->idle_data = data; @@ -30,10 +30,10 @@ bool idle_run_task() { struct idle_task *task; - if (g_queue_get_length(&idle_queue) > 0) { - task = (struct idle_task *)g_queue_pop_head(&idle_queue); + if (!g_queue_is_empty(&idle_queue)) { + task = g_queue_pop_head(&idle_queue); task->idle_func(task->idle_data); - delete task; + g_free(task); serviced++; } diff --git a/core/library.cpp b/core/library.cpp index 559db796..4d0cff64 100644 --- a/core/library.cpp +++ b/core/library.cpp @@ -1,7 +1,9 @@ /** * Copyright 2013 (c) Anna Schumaker. */ +extern "C" { #include +} #include #include diff --git a/gui/manager.cpp b/gui/manager.cpp index 62755092..4a45ffc6 100644 --- a/gui/manager.cpp +++ b/gui/manager.cpp @@ -3,8 +3,8 @@ */ extern "C" { #include -} #include +} #include #include #include diff --git a/include/core/idle.h b/include/core/idle.h index 29fc65d8..f4cc7067 100644 --- a/include/core/idle.h +++ b/include/core/idle.h @@ -1,4 +1,4 @@ -/** +/* * Copyright 2013 (c) Anna Schumaker. * * The idle queue is used to schedule function calls to run at a @@ -13,6 +13,7 @@ */ #ifndef OCARINA_CORE_IDLE_H #define OCARINA_CORE_IDLE_H +#include /* Called to schedule a function to run later. */ void idle_schedule(void (*)(void *), void *); diff --git a/include/tests/test.h b/include/tests/test.h index 09c734a4..1716a9e5 100644 --- a/include/tests/test.h +++ b/include/tests/test.h @@ -16,6 +16,7 @@ static inline gchar *stos(const char *s) { return g_strdup(s); } static inline gchar *utos(unsigned int u) { return g_strdup_printf("%u", u); } static inline gchar *itos(int i) { return g_strdup_printf("%i", i); } +static inline gchar *ftos(float f) { return g_strdup_printf("%f", f); } static inline gchar *btos(bool b) { return g_strdup(b ? "true" : "false"); } static inline gchar *ptos(void *p) { return g_strdup_printf("%p", p); } @@ -26,6 +27,7 @@ static inline gchar *ptos(void *p) { return g_strdup_printf("%p", p); } bool: btos, \ unsigned int: utos, \ int: itos, \ + float:ftos, \ void *:ptos \ ) (x)) #endif /* __cplusplus */ diff --git a/tests/core/Sconscript b/tests/core/Sconscript index 0b07913e..bfaac03f 100644 --- a/tests/core/Sconscript +++ b/tests/core/Sconscript @@ -22,7 +22,7 @@ res += [ CoreTest("set", "set.c") ] res += [ CoreTest("database", "database.c") ] res += [ CoreTest("index", "index.c") ] res += [ CoreTest("filter", "filter.c") ] -res += [ CoreTest("idle", "idle.cpp") ] +res += [ CoreTest("idle", "idle.c") ] res += SConscript("tags/Sconscript") res += [ CoreTest("queue", "queue.cpp") ] diff --git a/tests/core/idle.cpp b/tests/core/idle.c similarity index 86% rename from tests/core/idle.cpp rename to tests/core/idle.c index 8d5034e9..c5151025 100644 --- a/tests/core/idle.cpp +++ b/tests/core/idle.c @@ -4,7 +4,7 @@ */ #include #include -#include "test.h" +#include static unsigned int cur = -1; static bool func_passed = false; @@ -22,19 +22,19 @@ static void test_idle_queue(unsigned int n) cur = -1; test_equal(idle_progress(), (float)1.0); - test_equal(idle_run_task(), false); + test_equal(idle_run_task(), (bool)false); for (unsigned int i = 0; i < n; i++) idle_schedule(inc_cur, GINT_TO_POINTER(i)); test_equal(idle_progress(), (float)0.0); for (unsigned int i = 0; i < (n - 1); i++) { - test_loop_equal(idle_run_task(), true, i); + test_loop_equal(idle_run_task(), (bool)true, i); test_loop_equal(idle_progress(), ((i + 1) / (float)n), i); - test_loop_equal(func_passed, true, i); + test_loop_equal(func_passed, (bool)true, i); } test_loop_passed(); - test_equal(idle_run_task(), false); + test_equal(idle_run_task(), (bool)false); test_equal(idle_progress(), (float)1.0); } diff --git a/tests/core/library.cpp b/tests/core/library.cpp index 6df7713e..e51e2709 100644 --- a/tests/core/library.cpp +++ b/tests/core/library.cpp @@ -3,8 +3,8 @@ */ extern "C" { #include -} #include +} #include #include #include "test.h"