Cogs.Core
Threads.MacOS.cpp
1#include "Threads.h"
2
3#include "../Logging/Logger.h"
4
5#include <assert.h>
6#include <pthread.h>
7
8namespace {
10}
11
12void Cogs::Threads::setName(Thread& thread, const std::string& name) {
13 if(thread.get_id() == std::this_thread::get_id()) {
14 pthread_setname_np(name.c_str());
15 }
16 else {
17 LOG_ERROR(logger, "Attempting to set the name (%s) of thread %d from outside the thread.", name.c_str(), pthread_threadid_np(thread.native_handle(), nullptr));
18 }
19}
20
21void Cogs::Threads::sleep(int milliseconds) {
22 std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
23}
24
25void Cogs::Threads::yield() {
26 std::this_thread::yield();
27}
28
29size_t Cogs::Threads::hardwareConcurrency() {
30 return std::thread::hardware_concurrency();
31}
Log implementation class.
Definition: LogManager.h:139
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Definition: LogManager.h:180