Browse Source

sched: Rename schev to sched. More comprehensive

Serj Kalichev 3 years ago
parent
commit
2d56e9c8df
7 changed files with 113 additions and 113 deletions
  1. 3 3
      faux/Makefile.am
  2. 28 0
      faux/sched.h
  3. 2 2
      faux/sched/Makefile.am
  4. 11 11
      faux/sched/ev.c
  5. 6 6
      faux/sched/private.h
  6. 63 63
      faux/sched/sched.c
  7. 0 28
      faux/schev.h

+ 3 - 3
faux/Makefile.am

@@ -18,7 +18,7 @@ nobase_include_HEADERS += \
 	faux/file.h \
 	faux/argv.h \
 	faux/time.h \
-	faux/schev.h \
+	faux/sched.h \
 	faux/testc_helpers.h
 
 EXTRA_DIST += \
@@ -33,7 +33,7 @@ EXTRA_DIST += \
 	faux/file/Makefile.am \
 	faux/argv/Makefile.am \
 	faux/time/Makefile.am \
-	faux/schev/Makefile.am \
+	faux/sched/Makefile.am \
 	faux/testc_helpers/Makefile.am
 
 include $(top_srcdir)/faux/base/Makefile.am
@@ -47,7 +47,7 @@ include $(top_srcdir)/faux/ini/Makefile.am
 include $(top_srcdir)/faux/file/Makefile.am
 include $(top_srcdir)/faux/argv/Makefile.am
 include $(top_srcdir)/faux/time/Makefile.am
-include $(top_srcdir)/faux/schev/Makefile.am
+include $(top_srcdir)/faux/sched/Makefile.am
 include $(top_srcdir)/faux/testc_helpers/Makefile.am
 
 if TESTC

+ 28 - 0
faux/sched.h

@@ -0,0 +1,28 @@
+/** @file event.h
+ * @brief Public interface for event schedule functions.
+ */
+
+#ifndef _faux_sched_h
+#define _faux_sched_h
+
+#include <faux/faux.h>
+#include <faux/time.h>
+
+#define FAUX_SCHED_NOW NULL
+
+typedef enum {
+	FAUX_SCHED_PERIODIC = BOOL_TRUE,
+	FAUX_SCHED_ONCE = BOOL_FALSE
+	} faux_sched_periodic_t;
+
+typedef struct faux_ev_s faux_ev_t;
+typedef struct faux_sched_s faux_sched_t;
+typedef faux_list_node_t faux_sched_node_t;
+
+
+C_DECL_BEGIN
+
+
+C_DECL_END
+
+#endif /* _faux_sched_h */

+ 2 - 2
faux/schev/Makefile.am → faux/sched/Makefile.am

@@ -1,6 +1,6 @@
 libfaux_la_SOURCES += \
-	faux/schev/ev.c \
-	faux/schev/schev.c
+	faux/sched/ev.c \
+	faux/sched/sched.c
 
 #if TESTC
 #libfaux_la_SOURCES += faux/event/testc_event.c

+ 11 - 11
faux/schev/ev.c → faux/sched/ev.c

@@ -8,7 +8,7 @@
 
 #include "private.h"
 #include "faux/str.h"
-#include "faux/schev.h"
+#include "faux/sched.h"
 
 int faux_ev_compare(const void *first, const void *second)
 {
@@ -49,7 +49,7 @@ faux_ev_t *faux_ev_new(const struct timespec *time, int ev_id, void *data)
 	// Initialize
 	ev->id = ev_id;
 	ev->data = data;
-	ev->periodic = FAUX_SCHEV_ONCE; // Not periodic by default
+	ev->periodic = FAUX_SCHED_ONCE; // Not periodic by default
 	ev->cycles_num = 0;
 	faux_nsec_to_timespec(&ev->interval, 0l);
 	faux_ev_reschedule(ev, time);
@@ -77,7 +77,7 @@ int faux_ev_periodic(faux_ev_t *ev,
 	if (!ev || !interval || cycles_num == 0)
 		return -1;
 
-	ev->periodic = FAUX_SCHEV_PERIODIC;
+	ev->periodic = FAUX_SCHED_PERIODIC;
 	ev->cycles_num = cycles_num;
 	ev->interval = *interval;
 
@@ -85,11 +85,11 @@ int faux_ev_periodic(faux_ev_t *ev,
 }
 
 
-faux_schev_periodic_t faux_ev_is_periodic(faux_ev_t *ev)
+faux_sched_periodic_t faux_ev_is_periodic(faux_ev_t *ev)
 {
 	assert(ev);
 	if (!ev)
-		return FAUX_SCHEV_ONCE;
+		return FAUX_SCHED_ONCE;
 
 	return ev->periodic;
 }
@@ -100,9 +100,9 @@ int faux_ev_dec_cycles(faux_ev_t *ev, int *new_cycles_num)
 	assert(ev);
 	if (!ev)
 		return -1;
-	if (ev->periodic != FAUX_SCHEV_PERIODIC)
+	if (ev->periodic != FAUX_SCHED_PERIODIC)
 		return -1; // Non-periodic event
-	if ((ev->cycles_num != FAUX_SCHEV_CYCLES_INFINITE) &&
+	if ((ev->cycles_num != FAUX_SCHED_CYCLES_INFINITE) &&
 		(ev->cycles_num > 0))
 		ev->cycles_num--;
 
@@ -126,7 +126,7 @@ int faux_ev_reschedule(faux_ev_t *ev, const struct timespec *new_time)
 		ev->time = *new_time;
 	} else { // Time isn't given so use "NOW"
 		struct timespec t = {};
-		clock_gettime(FAUX_SCHEV_CLOCK_SOURCE, &t);
+		clock_gettime(FAUX_SCHED_CLOCK_SOURCE, &t);
 		ev->time = t;
 	}
 
@@ -141,7 +141,7 @@ int faux_ev_reschedule_interval(faux_ev_t *ev)
 	assert(ev);
 	if (!ev)
 		return -1;
-	if (ev->periodic != FAUX_SCHEV_PERIODIC)
+	if (ev->periodic != FAUX_SCHED_PERIODIC)
 		return -1;
 	if (0 == ev->cycles_num)
 		return -1;
@@ -149,7 +149,7 @@ int faux_ev_reschedule_interval(faux_ev_t *ev)
 	faux_timespec_sum(&new_time, &ev->time, &ev->interval);
 	faux_ev_reschedule(ev, &new_time);
 
-	if (ev->cycles_num != FAUX_SCHEV_CYCLES_INFINITE)
+	if (ev->cycles_num != FAUX_SCHED_CYCLES_INFINITE)
 		faux_ev_dec_cycles(ev, NULL);
 
 	return 0;
@@ -165,7 +165,7 @@ int faux_ev_time_left(faux_ev_t *ev, struct timespec *left)
 	if (!ev || !left)
 		return -1;
 
-	clock_gettime(FAUX_SCHEV_CLOCK_SOURCE, &now);
+	clock_gettime(FAUX_SCHED_CLOCK_SOURCE, &now);
 	if (faux_timespec_cmp(&now, &ev->time) > 0) { // Already happend
 		faux_nsec_to_timespec(left, 0l);
 		return 0;

+ 6 - 6
faux/schev/private.h → faux/sched/private.h

@@ -1,22 +1,22 @@
 #include "faux/faux.h"
 #include "faux/list.h"
 #include "faux/time.h"
-#include "faux/schev.h"
+#include "faux/sched.h"
 
-#define FAUX_SCHEV_CLOCK_SOURCE CLOCK_MONOTONIC
+#define FAUX_SCHED_CLOCK_SOURCE CLOCK_MONOTONIC
 
-#define FAUX_SCHEV_CYCLES_INFINITE (-1)
+#define FAUX_SCHED_CYCLES_INFINITE (-1)
 
 struct faux_ev_s {
 	struct timespec time; // Planned time of event
 	struct timespec interval; // Time interval for periodic event
 	int cycles_num; // Number of cycles for periodic event
-	faux_schev_periodic_t periodic; // Periodic flag
+	faux_sched_periodic_t periodic; // Periodic flag
 	int id; // Type of event
 	void *data; // Arbitrary data linked to event
 };
 
-struct faux_schev_s {
+struct faux_sched_s {
 	faux_list_t *list;
 };
 
@@ -39,6 +39,6 @@ int faux_ev_time_left(faux_ev_t *ev, struct timespec *left);
 int faux_ev_id(const faux_ev_t *ev);
 void *faux_ev_data(const faux_ev_t *ev);
 const struct timespec *faux_ev_time(const faux_ev_t *ev);
-faux_schev_periodic_t faux_ev_is_periodic(faux_ev_t *ev);
+faux_sched_periodic_t faux_ev_is_periodic(faux_ev_t *ev);
 
 C_DECL_END

+ 63 - 63
faux/schev/schev.c → faux/sched/sched.c

@@ -11,57 +11,57 @@
 #include "faux/faux.h"
 #include "faux/time.h"
 #include "faux/list.h"
-#include "faux/schev.h"
+#include "faux/sched.h"
 
 
-/** @brief Allocates new schev (SCHedule EVent) object.
+/** @brief Allocates new sched (SCHedule EVent) object.
  *
- * Before working with schev object it must be allocated and initialized.
+ * Before working with sched object it must be allocated and initialized.
  *
- * @return Allocated and initialized schev object or NULL on error.
+ * @return Allocated and initialized sched object or NULL on error.
  */
-faux_schev_t *faux_schev_new(void)
+faux_sched_t *faux_sched_new(void)
 {
-	faux_schev_t *schev = NULL;
+	faux_sched_t *sched = NULL;
 
-	schev = faux_zmalloc(sizeof(*schev));
-	if (!schev)
+	sched = faux_zmalloc(sizeof(*sched));
+	if (!sched)
 		return NULL;
 
 	// Init
-	schev->list = faux_list_new(FAUX_LIST_SORTED, FAUX_LIST_NONUNIQUE,
+	sched->list = faux_list_new(FAUX_LIST_SORTED, FAUX_LIST_NONUNIQUE,
 		faux_ev_compare, NULL, faux_ev_free);
 
-	return schev;
+	return sched;
 }
 
 
-/** @brief Frees the schev object.
+/** @brief Frees the sched object.
  *
- * After using the schev object must be freed. Function frees object itself
- * and all events stored within schev object.
+ * After using the sched object must be freed. Function frees object itself
+ * and all events stored within sched object.
  */
-void faux_schev_free(faux_schev_t *schev)
+void faux_sched_free(faux_sched_t *sched)
 {
-	assert(schev);
-	if (!schev)
+	assert(sched);
+	if (!sched)
 		return;
 
-	faux_list_free(schev->list);
-	faux_free(schev);
+	faux_list_free(sched->list);
+	faux_free(sched);
 }
 
 
-static int _schev_schedule_ev(faux_schev_t *schev, faux_ev_t *ev)
+static int _sched_ev(faux_sched_t *sched, faux_ev_t *ev)
 {
 	faux_list_node_t *node = NULL;
 
-	assert(schev);
+	assert(sched);
 	assert(ev);
-	if (!schev || !ev)
+	if (!sched || !ev)
 		return -1;
 
-	node = faux_list_add(schev->list, ev);
+	node = faux_list_add(sched->list, ev);
 	if (!node) // Something went wrong
 		return -1;
 
@@ -76,11 +76,11 @@ static int _schev_schedule_ev(faux_schev_t *schev, faux_ev_t *ev)
  * @param [in] data Pointer to arbitrary data linked to event.
  * @param [in] periodic Periodic flag.
  * @param [in] period Periodic interval.
- * @param [in] cycles_num Number of cycles (FAUX_SCHEV_CYCLES_INFINITE for infinite).
+ * @param [in] cycles_num Number of cycles (FAUX_SCHED_CYCLES_INFINITE for infinite).
  * @return 0 - success, < 0 on error.
  */
-static int _schev_schedule(faux_schev_t *schev, const struct timespec *time,
-	int ev_id, void *data, faux_schev_periodic_t periodic,
+static int _sched(faux_sched_t *sched, const struct timespec *time,
+	int ev_id, void *data, faux_sched_periodic_t periodic,
 	const struct timespec *period, int cycles_num)
 {
 	faux_ev_t *ev = NULL;
@@ -89,10 +89,10 @@ static int _schev_schedule(faux_schev_t *schev, const struct timespec *time,
 	assert(ev);
 	if (!ev)
 		return -1;
-	if (FAUX_SCHEV_PERIODIC == periodic)
+	if (FAUX_SCHED_PERIODIC == periodic)
 		faux_ev_periodic(ev, period, cycles_num);
 
-	if (_schev_schedule_ev(schev, ev) < 0) { // Something went wrong
+	if (_sched_ev(sched, ev) < 0) { // Something went wrong
 		faux_ev_free(ev);
 		return -1;
 	}
@@ -109,11 +109,11 @@ static int _schev_schedule(faux_schev_t *schev, const struct timespec *time,
  * @param [in] data Pointer to arbitrary data linked to event.
  * @return 0 - success, < 0 on error.
  */
-int faux_schev_schedule(
-	faux_schev_t *schev, const struct timespec *time, int ev_id, void *data)
+int faux_sched_once(
+	faux_sched_t *sched, const struct timespec *time, int ev_id, void *data)
 {
-	return _schev_schedule(schev, time, ev_id, data,
-		FAUX_SCHEV_ONCE, NULL, 0);
+	return _sched(sched, time, ev_id, data,
+		FAUX_SCHED_ONCE, NULL, 0);
 }
 
 
@@ -128,22 +128,22 @@ int faux_schev_schedule(
  * @param [in] data Pointer to arbitrary data linked to event.
  * @return 0 - success, < 0 on error.
  */
-int faux_schev_schedule_interval(faux_schev_t *schev,
+int faux_sched_once_delayed(faux_sched_t *sched,
 	const struct timespec *interval, int ev_id, void *data)
 {
 	struct timespec t = {};
 	struct timespec plan = {};
 
-	assert(schev);
-	if (!schev)
+	assert(sched);
+	if (!sched)
 		return -1;
 
 	if (!interval)
-		return faux_schev_schedule(schev, FAUX_SCHEV_NOW, ev_id, data);
-	clock_gettime(FAUX_SCHEV_CLOCK_SOURCE, &t);
+		return faux_sched_once(sched, FAUX_SCHED_NOW, ev_id, data);
+	clock_gettime(FAUX_SCHED_CLOCK_SOURCE, &t);
 	faux_timespec_sum(&plan, &t, interval);
 
-	return faux_schev_schedule(schev, &plan, ev_id, data);
+	return faux_sched_once(sched, &plan, ev_id, data);
 }
 
 
@@ -157,12 +157,12 @@ int faux_schev_schedule_interval(faux_schev_t *schev,
  * @param [in] cycle_num Number of cycles.
  * @return 0 - success, < 0 on error.
  */
-int faux_schev_periodic(
-	faux_schev_t *schev, const struct timespec *time, int ev_id, void *data,
+int faux_sched_periodic(
+	faux_sched_t *sched, const struct timespec *time, int ev_id, void *data,
 	const struct timespec *period, int cycle_num)
 {
-	return _schev_schedule(schev, time, ev_id, data,
-		FAUX_SCHEV_ONCE, period, cycle_num);
+	return _sched(sched, time, ev_id, data,
+		FAUX_SCHED_ONCE, period, cycle_num);
 }
 
 
@@ -175,21 +175,21 @@ int faux_schev_periodic(
  * @param [in] cycle_num Number of cycles.
  * @return 0 - success, < 0 on error.
  */
-int faux_schev_periodic_delayed(
-	faux_schev_t *schev, int ev_id, void *data,
+int faux_sched_periodic_delayed(
+	faux_sched_t *sched, int ev_id, void *data,
 	const struct timespec *period, int cycle_num)
 {
 	struct timespec t = {};
 	struct timespec plan = {};
 
-	assert(schev);
+	assert(sched);
 	assert(period);
-	if (!schev || !period)
+	if (!sched || !period)
 		return -1;
 
-	clock_gettime(FAUX_SCHEV_CLOCK_SOURCE, &t);
+	clock_gettime(FAUX_SCHED_CLOCK_SOURCE, &t);
 	faux_timespec_sum(&plan, &t, period);
-	return faux_schev_periodic(schev, &plan, ev_id, data,
+	return faux_sched_periodic(sched, &plan, ev_id, data,
 		period, cycle_num);
 }
 
@@ -199,17 +199,17 @@ int faux_schev_periodic_delayed(
  * If event is in the past then return null interval.
  * If no events was scheduled then return -1.
  */
-int faux_schev_next_interval(faux_schev_t *schev, struct timespec *interval)
+int faux_sched_next_interval(faux_sched_t *sched, struct timespec *interval)
 {
 	faux_ev_t *ev = NULL;
 	faux_list_node_t *iter = NULL;
 
-	assert(schev);
+	assert(sched);
 	assert(interval);
-	if (!schev || !interval)
+	if (!sched || !interval)
 		return -1;
 
-	iter = faux_list_head(schev->list);
+	iter = faux_list_head(sched->list);
 	if (!iter)
 		return -1;
 	ev = (faux_ev_t *)faux_list_data(iter);
@@ -221,13 +221,13 @@ int faux_schev_next_interval(faux_schev_t *schev, struct timespec *interval)
  *
  *
  */
-void faux_schev_empty(faux_schev_t *schev)
+void faux_sched_empty(faux_sched_t *sched)
 {
-	assert(schev);
-	if (!schev)
+	assert(sched);
+	if (!sched)
 		return;
 
-	faux_list_empty(schev->list);
+	faux_list_empty(sched->list);
 }
 
 /** @brief Pop already coming events from list.
@@ -235,24 +235,24 @@ void faux_schev_empty(faux_schev_t *schev)
  * Pop (get and remove from list) timestamp if it's in the past.
  * If the timestamp is in the future then do nothing.
  */
-int faux_schev_pop(faux_schev_t *schev, int *ev_id, void **data)
+int faux_sched_pop(faux_sched_t *sched, int *ev_id, void **data)
 {
 	struct timespec now = {};
 	faux_list_node_t *iter = NULL;
 	faux_ev_t *ev = NULL;
 
-	assert(schev);
-	if (!schev)
+	assert(sched);
+	if (!sched)
 		return -1;
 
-	iter = faux_list_head(schev->list);
+	iter = faux_list_head(sched->list);
 	if (!iter)
 		return -1;
 	ev = (faux_ev_t *)faux_list_data(iter);
-	clock_gettime(FAUX_SCHEV_CLOCK_SOURCE, &now);
+	clock_gettime(FAUX_SCHED_CLOCK_SOURCE, &now);
 	if (faux_timespec_cmp(faux_ev_time(ev), &now) > 0)
 		return -1; // No events for this time
-	faux_list_takeaway(schev->list, iter); // Remove entry from list
+	faux_list_takeaway(sched->list, iter); // Remove entry from list
 
 	if (ev_id)
 		*ev_id = faux_ev_id(ev);
@@ -262,7 +262,7 @@ int faux_schev_pop(faux_schev_t *schev, int *ev_id, void **data)
 	if (faux_ev_reschedule_interval(ev) < 0) {
 		faux_ev_free(ev);
 	} else {
-		_schev_schedule_ev(schev, ev);
+		_sched_ev(sched, ev);
 	}
 
 	return 0;
@@ -277,7 +277,7 @@ void remove_ev(lub_list_t *list, int id)
 		return;
 	while (iter) {
 		lub_list_node_t *node = iter;
-		schev_t *tmp = (schev_t *)lub_list_node__get_data(node);
+		sched_t *tmp = (sched_t *)lub_list_node__get_data(node);
 		iter = lub_list_iterator_next(node);
 		if (tmp->id == id) {
 			lub_list_del(list, node);

+ 0 - 28
faux/schev.h

@@ -1,28 +0,0 @@
-/** @file event.h
- * @brief Public interface for event schedule functions.
- */
-
-#ifndef _faux_schev_h
-#define _faux_schev_h
-
-#include <faux/faux.h>
-#include <faux/time.h>
-
-#define FAUX_SCHEV_NOW NULL
-
-typedef enum {
-	FAUX_SCHEV_PERIODIC = BOOL_TRUE,
-	FAUX_SCHEV_ONCE = BOOL_FALSE
-	} faux_schev_periodic_t;
-
-typedef struct faux_ev_s faux_ev_t;
-typedef struct faux_schev_s faux_schev_t;
-typedef faux_list_node_t faux_schev_node_t;
-
-
-C_DECL_BEGIN
-
-
-C_DECL_END
-
-#endif /* _faux_schev_h */