Files
xmrig/src/base/kernel/Platform.h

66 lines
1.7 KiB
C
Raw Normal View History

2017-06-14 19:13:02 +03:00
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
2017-06-14 19:13:02 +03:00
*
* 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/>.
*/
2018-09-16 03:06:54 +03:00
#ifndef XMRIG_PLATFORM_H
#define XMRIG_PLATFORM_H
2017-06-14 19:13:02 +03:00
2019-10-06 14:40:42 +07:00
#include <cstdint>
2018-04-13 09:27:37 +07:00
2018-11-20 07:24:14 +07:00
#include "base/tools/String.h"
2018-04-13 09:27:37 +07:00
2019-10-06 14:40:42 +07:00
namespace xmrig {
2017-08-15 03:04:46 +03:00
class Platform
{
public:
2019-07-13 16:48:14 +07:00
static inline bool trySetThreadAffinity(int64_t cpu_id)
{
if (cpu_id < 0) {
return false;
}
return setThreadAffinity(static_cast<uint64_t>(cpu_id));
}
2018-04-13 09:27:37 +07:00
static bool setThreadAffinity(uint64_t cpu_id);
2017-08-16 13:19:14 +03:00
static void init(const char *userAgent);
2019-12-27 03:19:03 +07:00
static void setProcessPriority(int priority);
2017-08-15 08:19:55 +03:00
static void setThreadPriority(int priority);
2017-06-14 19:13:02 +03:00
static inline bool isUserActive(uint64_t ms) { return idleTime() < ms; }
static inline const String &userAgent() { return m_userAgent; }
2017-06-14 19:13:02 +03:00
2020-07-22 20:12:16 +02:00
static bool isOnBatteryPower();
static uint64_t idleTime();
2020-07-22 20:12:16 +02:00
2017-08-15 03:04:46 +03:00
private:
2018-09-16 03:06:54 +03:00
static char *createUserAgent();
2019-10-06 14:40:42 +07:00
static String m_userAgent;
2017-08-15 03:04:46 +03:00
};
2017-06-14 19:13:02 +03:00
2019-10-06 14:40:42 +07:00
} // namespace xmrig
2018-09-16 03:06:54 +03:00
#endif /* XMRIG_PLATFORM_H */