2017-06-14 19:13:02 +03:00
|
|
|
/* XMRig
|
2023-08-06 20:26:07 +07:00
|
|
|
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
|
|
|
|
|
* Copyright (c) 2016-2023 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
|
|
|
|
2021-02-19 23:35:30 +07: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
|
|
|
|
2023-08-06 20:26:07 +07:00
|
|
|
# ifdef XMRIG_OS_WIN
|
2023-07-17 09:49:10 +02:00
|
|
|
static bool hasKeepalive();
|
2023-08-06 20:26:07 +07:00
|
|
|
# else
|
|
|
|
|
static constexpr bool hasKeepalive() { return true; }
|
|
|
|
|
# endif
|
2023-07-17 09:49:10 +02:00
|
|
|
|
2020-07-22 20:12:16 +02:00
|
|
|
static bool isOnBatteryPower();
|
2021-02-19 23:35:30 +07:00
|
|
|
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 */
|