Use the new timer for the timestamps in the logging
Replace the platform specific code with the new timers.
This commit is contained in:
parent
eb4c150024
commit
ee31f24cfb
@ -27,11 +27,10 @@
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define NOGDI
|
#define NOGDI
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#else
|
|
||||||
#include <sys/time.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "context-private.h"
|
#include "context-private.h"
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
struct dc_context_t {
|
struct dc_context_t {
|
||||||
dc_loglevel_t loglevel;
|
dc_loglevel_t loglevel;
|
||||||
@ -39,11 +38,7 @@ struct dc_context_t {
|
|||||||
void *userdata;
|
void *userdata;
|
||||||
#ifdef ENABLE_LOGGING
|
#ifdef ENABLE_LOGGING
|
||||||
char msg[8192 + 32];
|
char msg[8192 + 32];
|
||||||
#ifdef _WIN32
|
dc_timer_t *timer;
|
||||||
LARGE_INTEGER timestamp, frequency;
|
|
||||||
#else
|
|
||||||
struct timeval timestamp;
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -134,23 +129,11 @@ logfunc (dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsign
|
|||||||
{
|
{
|
||||||
const char *loglevels[] = {"NONE", "ERROR", "WARNING", "INFO", "DEBUG", "ALL"};
|
const char *loglevels[] = {"NONE", "ERROR", "WARNING", "INFO", "DEBUG", "ALL"};
|
||||||
|
|
||||||
unsigned long seconds = 0, microseconds = 0;
|
dc_usecs_t now = 0;
|
||||||
|
dc_timer_now (context->timer, &now);
|
||||||
|
|
||||||
#ifdef _WIN32
|
unsigned long seconds = now / 1000000;
|
||||||
LARGE_INTEGER now, delta;
|
unsigned long microseconds = now % 1000000;
|
||||||
QueryPerformanceCounter(&now);
|
|
||||||
delta.QuadPart = now.QuadPart - context->timestamp.QuadPart;
|
|
||||||
delta.QuadPart *= 1000000;
|
|
||||||
delta.QuadPart /= context->frequency.QuadPart;
|
|
||||||
seconds = delta.QuadPart / 1000000;
|
|
||||||
microseconds = delta.QuadPart % 1000000;
|
|
||||||
#else
|
|
||||||
struct timeval now, delta;
|
|
||||||
gettimeofday (&now, NULL);
|
|
||||||
timersub (&now, &context->timestamp, &delta);
|
|
||||||
seconds = delta.tv_sec;
|
|
||||||
microseconds = delta.tv_usec;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (loglevel == DC_LOGLEVEL_ERROR || loglevel == DC_LOGLEVEL_WARNING) {
|
if (loglevel == DC_LOGLEVEL_ERROR || loglevel == DC_LOGLEVEL_WARNING) {
|
||||||
fprintf (stderr, "[%li.%06li] %s: %s [in %s:%d (%s)]\n",
|
fprintf (stderr, "[%li.%06li] %s: %s [in %s:%d (%s)]\n",
|
||||||
@ -187,12 +170,8 @@ dc_context_new (dc_context_t **out)
|
|||||||
|
|
||||||
#ifdef ENABLE_LOGGING
|
#ifdef ENABLE_LOGGING
|
||||||
memset (context->msg, 0, sizeof (context->msg));
|
memset (context->msg, 0, sizeof (context->msg));
|
||||||
#ifdef _WIN32
|
context->timer = NULL;
|
||||||
QueryPerformanceFrequency(&context->frequency);
|
dc_timer_new (&context->timer);
|
||||||
QueryPerformanceCounter(&context->timestamp);
|
|
||||||
#else
|
|
||||||
gettimeofday (&context->timestamp, NULL);
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*out = context;
|
*out = context;
|
||||||
@ -203,6 +182,10 @@ dc_context_new (dc_context_t **out)
|
|||||||
dc_status_t
|
dc_status_t
|
||||||
dc_context_free (dc_context_t *context)
|
dc_context_free (dc_context_t *context)
|
||||||
{
|
{
|
||||||
|
if (context == NULL)
|
||||||
|
return DC_STATUS_SUCCESS;
|
||||||
|
|
||||||
|
dc_timer_free (context->timer);
|
||||||
free (context);
|
free (context);
|
||||||
|
|
||||||
return DC_STATUS_SUCCESS;
|
return DC_STATUS_SUCCESS;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user