Initial libuv support build.

This commit is contained in:
XMRig 2017-06-04 20:52:21 +03:00
parent 7741c341c7
commit 668b23c5b0
47 changed files with 1819 additions and 384 deletions

View file

@ -1,151 +0,0 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "xmrig.h"
#include "applog.h"
#include "threads.h"
#include <sys/time.h>
#include <string.h>
#ifdef WIN32
# include "compat/winansi.h"
#endif
#include "options.h"
MUTEX applog_mutex;
void applog_init()
{
MUTEX_INIT(applog_mutex);
}
void applog(int prio, const char *fmt, ...)
{
if (opt_background) {
return;
}
va_list ap;
va_start(ap, fmt);
struct tm tm;
struct tm *tm_p;
time_t now = time(NULL);
MUTEX_LOCK(applog_mutex);
tm_p = localtime(&now);
memcpy(&tm, tm_p, sizeof(tm));
MUTEX_UNLOCK(applog_mutex);
const char* color = "";
if (opt_colors) {
switch (prio) {
case LOG_ERR: color = CL_RED; break;
case LOG_WARNING: color = CL_YLW; break;
case LOG_NOTICE: color = CL_WHT; break;
case LOG_INFO: color = ""; break;
case LOG_DEBUG: color = CL_GRY; break;
case LOG_BLUE:
prio = LOG_NOTICE;
color = CL_CYN;
break;
case LOG_GREEN:
prio = LOG_NOTICE;
color = CL_LGR;
break;
}
}
const int len = 64 + strlen(fmt) + 2;
char *f = alloca(len);
sprintf(f, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s\n",
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec,
color,
fmt,
opt_colors ? CL_N : ""
);
MUTEX_LOCK(applog_mutex);
vfprintf(stderr, f, ap);
fflush(stderr);
MUTEX_UNLOCK(applog_mutex);
va_end(ap);
}
void applog_notime(int prio, const char *fmt, ...)
{
if (opt_background) {
return;
}
va_list ap;
va_start(ap, fmt);
const char* color = "";
if (opt_colors) {
switch (prio) {
case LOG_ERR: color = CL_RED; break;
case LOG_WARNING: color = CL_LYL; break;
case LOG_NOTICE: color = CL_WHT; break;
case LOG_INFO: color = ""; break;
case LOG_DEBUG: color = CL_GRY; break;
case LOG_BLUE:
prio = LOG_NOTICE;
color = CL_CYN;
break;
}
}
const int len = 64 + strlen(fmt) + 2;
char *f = alloca(len);
sprintf(f, "%s%s%s\n",
color,
fmt,
opt_colors ? CL_N : ""
);
MUTEX_LOCK(applog_mutex);
vfprintf(stderr, f, ap);
fflush(stderr);
MUTEX_UNLOCK(applog_mutex);
va_end(ap);
}

View file

@ -1,75 +0,0 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __APPLOG_H__
#define __APPLOG_H__
enum {
LOG_ERR,
LOG_WARNING,
LOG_NOTICE,
LOG_INFO,
LOG_DEBUG,
LOG_BLUE = 0x10,
LOG_GREEN
};
#define CL_N "\x1B[0m"
#define CL_RED "\x1B[31m"
#define CL_GRN "\x1B[32m"
#define CL_YLW "\x1B[33m"
#define CL_BLU "\x1B[34m"
#define CL_MAG "\x1B[35m"
#define CL_CYN "\x1B[36m"
#define CL_BLK "\x1B[22;30m" /* black */
#define CL_RD2 "\x1B[22;31m" /* red */
#define CL_GR2 "\x1B[22;32m" /* green */
#define CL_BRW "\x1B[22;33m" /* brown */
#define CL_BL2 "\x1B[22;34m" /* blue */
#define CL_MA2 "\x1B[22;35m" /* magenta */
#define CL_CY2 "\x1B[22;36m" /* cyan */
#define CL_SIL "\x1B[22;37m" /* gray */
#ifdef WIN32
#define CL_GRY "\x1B[01;30m" /* dark gray */
#else
#define CL_GRY "\x1B[90m" /* dark gray selectable in putty */
#endif
#define CL_LRD "\x1B[01;31m" /* light red */
#define CL_LGR "\x1B[01;32m" /* light green */
#define CL_LYL "\x1B[01;33m" /* light yellow */
#define CL_LBL "\x1B[01;34m" /* light blue */
#define CL_LMA "\x1B[01;35m" /* light magenta */
#define CL_LCY "\x1B[01;36m" /* light cyan */
#define CL_WHT "\x1B[01;37m" /* white */
#define OPT_COLOR(color, text) (opt_colors ? (color text CL_N) : text)
void applog_init();
void applog(int prio, const char *fmt, ...);
void applog_notime(int prio, const char *fmt, ...);
#endif /* __APPLOG_H__ */

View file

@ -1,41 +0,0 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __THREADS_H__
#define __THREADS_H__
#if defined(WIN32) && defined(USE_NATIVE_THREADS)
# include <windows.h>
# define MUTEX CRITICAL_SECTION
# define MUTEX_INIT(mutex) InitializeCriticalSection(&mutex)
# define MUTEX_LOCK(mutex) EnterCriticalSection(&mutex)
# define MUTEX_UNLOCK(mutex) LeaveCriticalSection(&mutex)
#else
# include <pthread.h>
# define MUTEX pthread_mutex_t
# define MUTEX_INIT(mutex) pthread_mutex_init(&mutex, NULL)
# define MUTEX_LOCK(mutex) pthread_mutex_lock(&mutex)
# define MUTEX_UNLOCK(mutex) pthread_mutex_unlock(&mutex)
#endif
#endif /* __THREADS_H__ */