ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
ADD_DEFINITIONS("-DLOG_TAG=\"COM_CORE\"")
ADD_DEFINITIONS("-DNDEBUG")
+ADD_DEFINITIONS("-D_USE_ECORE_TIME_GET")
ADD_LIBRARY(${PROJECT_NAME} SHARED
src/dlist.c
*/
extern const char *util_basename(const char *name);
+extern double util_timestamp(void);
#define CRITICAL_SECTION_BEGIN(handle) \
do { \
Name: libcom-core
Summary: Library for the light-weight IPC
-Version: 0.5.2
+Version: 0.5.3
Release: 1
Group: HomeTF/Framework
License: Apache License
struct packet *packet;
int payload_size;
va_list va;
- struct timeval tv;
if (strlen(cmd) >= PACKET_MAX_CMD) {
ErrPrint("Command is too long\n");
}
packet->state = VALID;
- gettimeofday(&tv, NULL);
packet->data->head.source = 0lu;
packet->data->head.destination = 0lu;
packet->data->head.mask = 0xFFFFFFFF;
- packet->data->head.seq = tv.tv_sec + tv.tv_usec / 1000000.0f;
+ packet->data->head.seq = util_timestamp();
packet->data->head.type = PACKET_REQ;
packet->data->head.version = PACKET_VERSION;
strncpy(packet->data->head.command, cmd, sizeof(packet->data->head.command));
int payload_size;
struct packet *result;
va_list va;
- struct timeval tv;
if (strlen(cmd) >= PACKET_MAX_CMD) {
ErrPrint("Command is too long\n");
}
result->state = VALID;
- gettimeofday(&tv, NULL);
result->data->head.source = 0lu;
result->data->head.destination = 0lu;
result->data->head.mask = 0xFFFFFFFF;
- result->data->head.seq = tv.tv_sec + tv.tv_usec / 1000000.0f;
+ result->data->head.seq = util_timestamp();
result->data->head.type = PACKET_REQ_NOACK;
result->data->head.version = PACKET_VERSION;
strncpy(result->data->head.command, cmd, sizeof(result->data->head.command));
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
#include <sys/time.h>
#include <errno.h>
+#include <time.h>
+#include <dlog.h>
+#include "debug.h"
#include "util.h"
int errno;
+#if defined(_USE_ECORE_TIME_GET)
+static struct {
+ clockid_t type;
+} s_info = {
+ .type = CLOCK_MONOTONIC,
+};
+#endif
const char *util_basename(const char *name)
{
return length <= 0 ? name : name + length + (name[length] == '/');
}
+double util_timestamp(void)
+{
+#if defined(_USE_ECORE_TIME_GET)
+ struct timespec ts;
+
+ do {
+ if (clock_gettime(s_info.type, &ts) == 0) {
+ return ts.tv_sec + ts.tv_nsec / 1000000000.0f;
+ }
+
+ ErrPrint("%d: %s\n", s_info.type, strerror(errno));
+ if (s_info.type == CLOCK_MONOTONIC) {
+ s_info.type = CLOCK_REALTIME;
+ } else if (s_info.type == CLOCK_REALTIME) {
+ break;
+ }
+ } while (1);
+
+ return 0.0f;
+#else
+ struct timeval tv;
+
+ if (gettimeofday(&tv, NULL) < 0) {
+ ErrPrint("gettimeofday: %s\n", strerror(errno));
+ tv.tv_sec = rand();
+ tv.tv_usec = rand();
+ }
+
+ return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
+#endif
+}
+
/* End of a file */