Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
Threading.h
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#ifndef THREADING_H
7#define THREADING_H
8
9#include <atomic>
10#include <assert.h>
11#include <cstdint>
12#include <thread>
13
14namespace Skyfire
15{
16
18 {
19 public:
20 Runnable() : m_refs(0) { }
21 virtual ~Runnable() { }
22 virtual void run() = 0;
23
24 void incReference() { ++m_refs; }
26 {
27 if (!--m_refs)
28 delete this;
29 }
30 private:
31 std::atomic<long> m_refs;
32 };
33
44
45#define MAXPRIORITYNUM (Realtime + 1)
46
48 {
49 public:
51 int getPriority(Priority p) const;
52
53 private:
55 };
56
57 class Thread
58 {
59 public:
60 Thread();
61 explicit Thread(Runnable* instance);
62 ~Thread();
63
64 bool start();
65 bool wait();
66 void destroy();
67
68 void suspend();
69 void resume();
70
71 void setPriority(Priority type);
72
73 static void Sleep(unsigned long msecs);
74 static uint64_t currentId();
75 static std::thread::native_handle_type currentHandle();
76 static Thread* current();
77
78 private:
79 Thread(const Thread&);
81
82 static void ThreadTask(Runnable* param);
83
84 uint64_t m_iThreadId;
85 std::thread m_thread;
88 };
89
90}
91
92#endif
#define MAXPRIORITYNUM
Definition Threading.h:45
void incReference()
Definition Threading.h:24
virtual ~Runnable()
Definition Threading.h:21
void decReference()
Definition Threading.h:25
std::atomic< long > m_refs
Definition Threading.h:31
virtual void run()=0
static Thread * current()
Thread & operator=(const Thread &)
void setPriority(Priority type)
std::thread m_thread
Definition Threading.h:85
static void ThreadTask(Runnable *param)
Thread(const Thread &)
static std::thread::native_handle_type currentHandle()
uint64_t m_iThreadId
Definition Threading.h:84
static uint64_t currentId()
Runnable * m_task
Definition Threading.h:86
static void Sleep(unsigned long msecs)
int getPriority(Priority p) const
Definition Threading.cpp:19
int m_priority[MAXPRIORITYNUM]
Definition Threading.h:54
@ Highest
Definition Threading.h:41
@ Realtime
Definition Threading.h:42