Skip to content

Commit 6468d43

Browse files
rustyrussellendothermicdev
authored andcommitted
ccan: update for FreeBSD compile fixes.
Also gets some new timemono helpers, but we don't use them (yet). Changelog-Fixed: Compilation on FreeBSD. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Closes: #7758
1 parent 9d160eb commit 6468d43

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

ccan/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
CCAN imported from http://ccodearchive.net.
22

3-
CCAN version: init-2590-gaf04734d
3+
CCAN version: init-2593-gca094039

ccan/ccan/fdpass/fdpass.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <sys/socket.h>
44
#include <errno.h>
55
#include <string.h>
6+
#include <sys/types.h>
67

78
bool fdpass_send(int sockout, int fd)
89
{

ccan/ccan/time/test/run-monotonic.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ int main(void)
77
struct timemono t1, t2;
88
struct timerel t3;
99

10-
plan_tests(5);
10+
plan_tests(10);
1111

1212
/* Test time_mono */
1313
t1 = time_mono();
1414
t2 = time_mono();
1515

16-
ok1(!time_less_(t2.ts, t1.ts));
16+
ok1(!timemono_before(t2, t1));
1717

1818
t3.ts.tv_sec = 1;
1919
t3.ts.tv_nsec = 0;
@@ -24,5 +24,11 @@ int main(void)
2424
ok1(timemono_add(t1, t3).ts.tv_sec == t1.ts.tv_sec + 1);
2525
ok1(timemono_add(t2, t3).ts.tv_nsec == t2.ts.tv_nsec);
2626

27+
ok1(timemono_sub(timemono_add(t1, t3), t3).ts.tv_sec == t1.ts.tv_sec);
28+
ok1(timemono_sub(timemono_add(t1, t3), t3).ts.tv_nsec == t1.ts.tv_nsec);
29+
30+
ok1(timemono_after(timemono_add(t1, t3), t1));
31+
ok1(!timemono_after(t1, timemono_add(t1, t3)));
32+
ok1(!timemono_after(t1, t1));
2733
return exit_status();
2834
}

ccan/ccan/time/time.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,23 @@ static inline bool time_greater(struct timerel a, struct timerel b)
193193
return time_greater_(a.ts, b.ts);
194194
}
195195

196+
/**
197+
* timemono_after - is a after b?
198+
* @a: one monotonic time.
199+
* @b: another monotonic time.
200+
*
201+
* Example:
202+
* static bool timed_out(const struct timemono *start)
203+
* {
204+
* #define TIMEOUT time_from_msec(1000)
205+
* return timemono_after(time_mono(), timemono_add(*start, TIMEOUT));
206+
* }
207+
*/
208+
static inline bool timemono_after(struct timemono a, struct timemono b)
209+
{
210+
return time_greater_(a.ts, b.ts);
211+
}
212+
196213
static inline bool time_less_(struct timespec a, struct timespec b)
197214
{
198215
if (TIME_CHECK(a).tv_sec < TIME_CHECK(b).tv_sec)
@@ -220,6 +237,23 @@ static inline bool time_before(struct timeabs a, struct timeabs b)
220237
return time_less_(a.ts, b.ts);
221238
}
222239

240+
/**
241+
* timemono_before - is a before b?
242+
* @a: one monotonic time.
243+
* @b: another monotonic time.
244+
*
245+
* Example:
246+
* static bool still_valid(const struct timemono *start)
247+
* {
248+
* #define TIMEOUT time_from_msec(1000)
249+
* return timemono_before(time_mono(), timemono_add(*start, TIMEOUT));
250+
* }
251+
*/
252+
static inline bool timemono_before(struct timemono a, struct timemono b)
253+
{
254+
return time_less_(a.ts, b.ts);
255+
}
256+
223257
/**
224258
* time_less - is a before b?
225259
* @a: one relative time.
@@ -404,6 +438,29 @@ static inline struct timeabs timeabs_sub(struct timeabs abs, struct timerel rel)
404438
return t;
405439
}
406440

441+
/**
442+
* timemono_sub - subtract a relative time from a monotonic time
443+
* @mono: the monotonic time.
444+
* @rel: the relative time.
445+
*
446+
* This returns a well formed struct timemono of @mono - @rel.
447+
*
448+
* Example:
449+
* // We do one every second.
450+
* static struct timemono previous_time(void)
451+
* {
452+
* return timemono_sub(time_mono(), time_from_msec(1000));
453+
* }
454+
*/
455+
static inline struct timemono timemono_sub(struct timemono mono, struct timerel rel)
456+
{
457+
struct timemono t;
458+
459+
t.ts = time_sub_(mono.ts, rel.ts);
460+
return t;
461+
}
462+
463+
407464
static inline struct timespec time_add_(struct timespec a, struct timespec b)
408465
{
409466
struct timespec sum;
@@ -488,6 +545,8 @@ static inline struct timerel timerel_add(struct timerel a, struct timerel b)
488545
* @div: number to divide it by.
489546
*
490547
* Example:
548+
* #include <sys/wait.h>
549+
*
491550
* // How long does it take to do a fork?
492551
* static struct timerel forking_time(void)
493552
* {

0 commit comments

Comments
 (0)