Skip to content

Commit

Permalink
[added] thread numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
karlbunch committed Mar 8, 2022
1 parent a7e868f commit e5ea329
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions MMOEngine/src/system/thread/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace ThreadNs {

}

std::atomic<int> Thread::threadCounter;
std::atomic<uint32> Thread::threadCounter;
UniqueReference<ThreadInitializer*> Thread::threadInitializer;

pthread_once_t Thread::initThread = PTHREAD_ONCE_INIT;
Expand Down Expand Up @@ -80,7 +80,8 @@ Thread::Thread() {
pthread_attr_init(&attributes);
memset(&thread, 0, sizeof(thread));

name = "Thread " + String::valueOf(++threadCounter);
threadNumber = ++threadCounter;
name = "Thread " + String::valueOf(threadNumber);
customName = name.replaceFirst(" ", "-");
}

Expand Down
7 changes: 6 additions & 1 deletion MMOEngine/src/system/thread/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ namespace sys {
pthread_t thread;
pthread_attr_t attributes;

uint32 threadNumber;
String name;
String customName;

static std::atomic<int> threadCounter;
static std::atomic<uint32> threadCounter;
static pthread_once_t initThread;

static ThreadLocal<Thread*> currentThread;
Expand Down Expand Up @@ -165,6 +166,10 @@ namespace sys {
return threadInitializer;
}

uint32 getThreadNumber() {
return threadNumber;
}

const String& getName() {
return name;
}
Expand Down

0 comments on commit e5ea329

Please sign in to comment.