Skip to content

Commit 7c7795c

Browse files
committed
Use custom bool. Minor changes in makefile.
1 parent 18eec6f commit 7c7795c

File tree

6 files changed

+16
-13
lines changed

6 files changed

+16
-13
lines changed

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#override CC := clang
22
override CFLAGS += -Wfatal-errors -O0 -g
33
override CPPFLAGS += -I. -Iinclude -DDEBUG
4-
override SERVER_LDFLAGS += -Llib -lraft -ljansson
5-
override CLIENT_LDFLAGS += -ljansson
4+
override HEART_LDFLAGS += -Llib -lraft -ljansson
65

76
AR = ar
87
ARFLAGS = -cru
@@ -17,7 +16,7 @@ lib/libraft.a: obj/raft.o obj/util.o | libdir objdir
1716

1817
bin/heart: obj/heart.o lib/libraft.a | bindir objdir
1918
$(CC) -o bin/heart $(CFLAGS) $(CPPFLAGS) \
20-
obj/heart.o $(SERVER_LDFLAGS)
19+
obj/heart.o $(HEART_LDFLAGS)
2120

2221
obj/%.o: src/%.c | objdir
2322
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<

example/heart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "raft.h"
1616
#include "util.h"
1717

18-
static void applier(void *state, raft_update_t update, bool snapshot) {
18+
static void applier(void *state, raft_update_t update, raft_bool_t snapshot) {
1919
json_error_t error;
2020

2121
json_t *patch = json_loadb(update.data, update.len, 0, &error);

include/raft.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
typedef struct raft_data_t *raft_t;
77
typedef struct raft_msg_data_t *raft_msg_t;
88

9+
typedef int raft_bool_t;
10+
911
typedef struct raft_update_t {
1012
int len;
1113
char *data;
@@ -17,7 +19,7 @@ typedef struct raft_update_t {
1719
// This should be a function that applies an 'update' to the state machine.
1820
// 'snapshot' is true if 'update' contains a snapshot. 'userdata' is the
1921
// userdata that raft was configured with.
20-
typedef void (*raft_applier_t)(void *userdata, raft_update_t update, bool snapshot);
22+
typedef void (*raft_applier_t)(void *userdata, raft_update_t update, raft_bool_t snapshot);
2123

2224
// This should be a function that makes a snapshot of the state machine. Used
2325
// for raft log compaction. 'userdata' is the userdata that raft was configured
@@ -48,10 +50,10 @@ raft_t raft_init(raft_config_t *config);
4850

4951
// Add a peer named 'id'. 'self' should be true, if that peer is this instance.
5052
// Only one peer should have 'self' == true.
51-
bool raft_peer_up(raft_t r, int id, char *host, int port, bool self);
53+
raft_bool_t raft_peer_up(raft_t r, int id, char *host, int port, raft_bool_t self);
5254

5355
// Remove a previously added peer named 'id'.
54-
bool raft_peer_down(raft_t r, int id);
56+
raft_bool_t raft_peer_down(raft_t r, int id);
5557

5658
// --- Log Actions ---
5759

@@ -60,7 +62,7 @@ bool raft_peer_down(raft_t r, int id);
6062
int raft_emit(raft_t r, raft_update_t update);
6163

6264
// Checks whether an entry at 'index' has been applied by the peer named 'id'.
63-
bool raft_applied(raft_t t, int id, int index);
65+
raft_bool_t raft_applied(raft_t t, int id, int index);
6466

6567
// --- Control ---
6668

@@ -85,7 +87,7 @@ void raft_handle_message(raft_t r, raft_msg_t m);
8587
int raft_create_udp_socket(raft_t r);
8688

8789
// Returns true if this peer thinks it is the leader.
88-
bool raft_is_leader(raft_t r);
90+
raft_bool_t raft_is_leader(raft_t r);
8991

9092
// Returns the id of the current leader, or NOBODY if no leader.
9193
int raft_get_leader(raft_t r);

include/util.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#ifndef UTIL_H
22
#define UTIL_H
33

4-
#include <stdbool.h>
54
#include <sys/stat.h>
65
#include <sys/time.h>
76
#include <fcntl.h>
87
#include <stdio.h>
98
#include <stdlib.h>
109

11-
bool inrange(int min, int x, int max);
10+
int inrange(int min, int x, int max);
1211

1312
static inline int min(int a, int b) {
1413
return a < b ? a : b;

src/raft.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
#include <assert.h>
33
#include <errno.h>
44
#include <limits.h>
5-
#include <stdbool.h>
65
#include <string.h>
76

87
#include "raft.h"
98
#include "util.h"
109

10+
#define bool raft_bool_t
11+
#define true 1
12+
#define false 0
13+
1114
#define DEFAULT_LISTENHOST "0.0.0.0"
1215
#define DEFAULT_LISTENPORT 6543
1316

src/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <unistd.h>
66
#include "util.h"
77

8-
bool inrange(int min, int x, int max) {
8+
int inrange(int min, int x, int max) {
99
assert(min <= max);
1010
return (min <= x) && (x <= max);
1111
}

0 commit comments

Comments
 (0)