Skip to content

Commit

Permalink
feat times: added initial functions
Browse files Browse the repository at this point in the history
Signed-off-by: John Sanpe <[email protected]>
  • Loading branch information
sanpeqf committed Feb 29, 2024
1 parent 1dd1a9a commit 2a2a275
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set(SRCS
${PROJECT_SOURCE_DIR}/src/connection/connection.c
${PROJECT_SOURCE_DIR}/src/core/xdbd_buf.c
${PROJECT_SOURCE_DIR}/src/core/xdbd_pool.c
${PROJECT_SOURCE_DIR}/src/core/xdbd_times.c
${PROJECT_SOURCE_DIR}/src/event/select/xdbd_select.c
${PROJECT_SOURCE_DIR}/src/event/xdbd_event.c
${PROJECT_SOURCE_DIR}/src/event/xdbd_timer.c
Expand Down
31 changes: 31 additions & 0 deletions src/core/xdbd_times.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright(c) 2024 John Sanpe <[email protected]>
*/

#include <bfdev.h>
#include <xdbd.h>
#include <time.h>
#include <sys/time.h>

volatile xdbd_msec_t xdbd_current_msec;

static xdbd_msec_t
xdbd_monotonic_time(void)
{
struct timespec ts;
time_t sec;
long msec;

clock_gettime(CLOCK_MONOTONIC, &ts);
sec = ts.tv_sec;
msec = ts.tv_nsec / 1000000;

return (xdbd_msec_t) sec * 1000 + msec;
}

void
xdbd_time_update(void)
{
xdbd_current_msec = xdbd_monotonic_time();
}
16 changes: 16 additions & 0 deletions src/core/xdbd_times.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright(c) 2024 John Sanpe <[email protected]>
*/

#ifndef __xdbd_times__H__
#define __xdbd_times__H__

#include <xdbd.h>

extern volatile xdbd_msec_t xdbd_current_msec;

void
xdbd_time_update(void);

#endif /* __xdbd_times__H__ */

0 comments on commit 2a2a275

Please sign in to comment.