Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7c7795c

Browse files
committed
Use custom bool. Minor changes in makefile.
1 parent18eec6f commit7c7795c

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
overrideCFLAGS += -Wfatal-errors -O0 -g
33
overrideCPPFLAGS += -I. -Iinclude -DDEBUG
4-
overrideSERVER_LDFLAGS += -Llib -lraft -ljansson
5-
overrideCLIENT_LDFLAGS += -ljansson
4+
overrideHEART_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-
staticvoidapplier(void*state,raft_update_tupdate,boolsnapshot) {
18+
staticvoidapplier(void*state,raft_update_tupdate,raft_bool_tsnapshot) {
1919
json_error_terror;
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
typedefstructraft_data_t*raft_t;
77
typedefstructraft_msg_data_t*raft_msg_t;
88

9+
typedefintraft_bool_t;
10+
911
typedefstructraft_update_t {
1012
intlen;
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-
typedefvoid (*raft_applier_t)(void*userdata,raft_update_tupdate,boolsnapshot);
22+
typedefvoid (*raft_applier_t)(void*userdata,raft_update_tupdate,raft_bool_tsnapshot);
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-
boolraft_peer_up(raft_tr,intid,char*host,intport,boolself);
53+
raft_bool_traft_peer_up(raft_tr,intid,char*host,intport,raft_bool_tself);
5254

5355
// Remove a previously added peer named 'id'.
54-
boolraft_peer_down(raft_tr,intid);
56+
raft_bool_traft_peer_down(raft_tr,intid);
5557

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

@@ -60,7 +62,7 @@ bool raft_peer_down(raft_t r, int id);
6062
intraft_emit(raft_tr,raft_update_tupdate);
6163

6264
// Checks whether an entry at 'index' has been applied by the peer named 'id'.
63-
boolraft_applied(raft_tt,intid,intindex);
65+
raft_bool_traft_applied(raft_tt,intid,intindex);
6466

6567
// --- Control ---
6668

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

8789
// Returns true if this peer thinks it is the leader.
88-
boolraft_is_leader(raft_tr);
90+
raft_bool_traft_is_leader(raft_tr);
8991

9092
// Returns the id of the current leader, or NOBODY if no leader.
9193
intraft_get_leader(raft_tr);

‎include/util.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#ifndefUTIL_H
22
#defineUTIL_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-
boolinrange(intmin,intx,intmax);
10+
intinrange(intmin,intx,intmax);
1211

1312
staticinlineintmin(inta,intb) {
1413
returna<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+
#definebool raft_bool_t
11+
#definetrue 1
12+
#definefalse 0
13+
1114
#defineDEFAULT_LISTENHOST "0.0.0.0"
1215
#defineDEFAULT_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-
boolinrange(intmin,intx,intmax) {
8+
intinrange(intmin,intx,intmax) {
99
assert(min <=max);
1010
return (min <=x)&& (x <=max);
1111
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp