@@ -120,6 +120,7 @@ static term nif_erlang_list_to_integer_1(Context *ctx, int argc, term argv[]);
120120static term nif_erlang_list_to_float_1 (Context * ctx , int argc , term argv []);
121121static term nif_erlang_list_to_atom_1 (Context * ctx , int argc , term argv []);
122122static term nif_erlang_list_to_existing_atom_1 (Context * ctx , int argc , term argv []);
123+ static term nif_erlang_monotonic_time_1 (Context * ctx , int argc , term argv []);
123124static term nif_erlang_iolist_size_1 (Context * ctx , int argc , term argv []);
124125static term nif_erlang_iolist_to_binary_1 (Context * ctx , int argc , term argv []);
125126static term nif_erlang_open_port_2 (Context * ctx , int argc , term argv []);
@@ -453,6 +454,12 @@ static const struct Nif concat_nif =
453454 .nif_ptr = nif_erlang_concat_2
454455};
455456
457+ static const struct Nif monotonic_time_nif =
458+ {
459+ .base .type = NIFFunctionType ,
460+ .nif_ptr = nif_erlang_monotonic_time_1
461+ };
462+
456463static const struct Nif system_time_nif =
457464{
458465 .base .type = NIFFunctionType ,
@@ -1288,6 +1295,28 @@ term nif_erlang_make_ref_0(Context *ctx, int argc, term argv[])
12881295 return term_from_ref_ticks (ref_ticks , ctx );
12891296}
12901297
1298+ term nif_erlang_monotonic_time_1 (Context * ctx , int argc , term argv [])
1299+ {
1300+ UNUSED (ctx );
1301+ UNUSED (argc );
1302+
1303+ struct timespec ts ;
1304+ sys_monotonic_time (& ts );
1305+
1306+ if (argv [0 ] == SECOND_ATOM ) {
1307+ return make_maybe_boxed_int64 (ctx , ts .tv_sec );
1308+
1309+ } else if (argv [0 ] == MILLISECOND_ATOM ) {
1310+ return make_maybe_boxed_int64 (ctx , ((int64_t ) ts .tv_sec ) * 1000 + ts .tv_nsec / 1000000 );
1311+
1312+ } else if (argv [0 ] == MICROSECOND_ATOM ) {
1313+ return make_maybe_boxed_int64 (ctx , ((int64_t ) ts .tv_sec ) * 1000000 + ts .tv_nsec / 1000 );
1314+
1315+ } else {
1316+ RAISE_ERROR (BADARG_ATOM );
1317+ }
1318+ }
1319+
12911320term nif_erlang_system_time_1 (Context * ctx , int argc , term argv [])
12921321{
12931322 UNUSED (ctx );
0 commit comments