Skip to content

Commit 7fcb2af

Browse files
committed
removing the need to keep track of a vector of TIDs
1 parent 5e282d2 commit 7fcb2af

2 files changed

Lines changed: 3 additions & 62 deletions

File tree

include/tracr/marker_management_engine.hpp

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include <fstream> // To store files
3030
#include <iomanip>
3131
#include <iostream>
32-
#include <mutex>
3332
#include <nlohmann/json.hpp>
3433
#include <sched.h> // sched_getcpu()
3534
#include <string>
@@ -63,43 +62,6 @@ constexpr size_t CAPACITY = TRACR_CAPACITY;
6362
#define debug_print(fmt, ...)
6463
#endif
6564

66-
/**
67-
* A way to keep the tracrThreads save when adding/erasing
68-
*/
69-
inline std::mutex tracrThreadIDsMutex;
70-
71-
/**
72-
* A list of all the created _tracrThreadIDs
73-
*/
74-
inline std::vector<pid_t> tracrThreadIDs;
75-
76-
/**
77-
* Adding a new tracr thread
78-
*
79-
* This is thread save.
80-
*/
81-
inline void addTraCRThread(pid_t tid) {
82-
// We have to lock this as this method can be called from multiple threads
83-
std::lock_guard<std::mutex> lock(tracrThreadIDsMutex);
84-
tracrThreadIDs.push_back(tid);
85-
}
86-
87-
/**
88-
*
89-
*/
90-
inline void eraseTraCRThread(const pid_t tid) {
91-
std::lock_guard<std::mutex> lock(tracrThreadIDsMutex);
92-
93-
auto it = std::find(tracrThreadIDs.begin(), tracrThreadIDs.end(), tid);
94-
95-
if (it == tracrThreadIDs.end()) {
96-
std::cerr << "Thread not found in tracr proc list!\n";
97-
std::exit(EXIT_FAILURE);
98-
}
99-
100-
tracrThreadIDs.erase(it);
101-
}
102-
10365
/**
10466
* Our nanosecond timer
10567
*

include/tracr/tracr_core.hpp

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,10 @@ static inline void instrumentation_thread_init() {
8585
std::exit(EXIT_FAILURE);
8686
}
8787

88-
pid_t this_tid = syscall(SYS_gettid);
89-
90-
for (const auto &tid : tracrThreadIDs) {
91-
if (this_tid == tid) {
92-
std::cerr << "TraCR thread with this TID already exists in the list in "
93-
"tracr proc\n";
94-
std::exit(EXIT_FAILURE);
95-
}
96-
}
97-
9888
// Add tracr Thread
89+
pid_t this_tid = syscall(SYS_gettid);
9990
tracrThread = std::make_unique<TraCRThread>(this_tid);
10091

101-
// Add the new TraCR Thread
102-
addTraCRThread(this_tid);
103-
10492
// Increase global thread counter
10593
++num_tracr_threads;
10694
}
@@ -123,10 +111,6 @@ static inline void instrumentation_thread_finalize() {
123111
// Finalize the thread now (destructor of it is also called)
124112
tracrThread.reset();
125113

126-
// If it exists check if it is inside the tracr proc list
127-
// If yes, erase it, else abort
128-
eraseTraCRThread(syscall(SYS_gettid));
129-
130114
// Decrease global thread counter
131115
--num_tracr_threads;
132116
}
@@ -180,10 +164,9 @@ static inline void instrumentation_end() {
180164

181165
// Flushing the trace of this TraCR thread/proc now (if enabled)
182166
if (flush_enabled) {
183-
if (num_tracr_threads.load() != 1 || tracrThreadIDs.size() != 1) {
167+
if (num_tracr_threads.load() != 1) {
184168
std::cerr << "Only one(this) TraCR Threads allowed but got: "
185-
<< num_tracr_threads.load() << ":" << tracrThreadIDs.size()
186-
<< "\n";
169+
<< num_tracr_threads.load() << "\n";
187170
std::exit(EXIT_FAILURE);
188171
}
189172

@@ -197,10 +180,6 @@ static inline void instrumentation_end() {
197180
// Destroys the TraCR Thread pointer and calls the destructor
198181
tracrThread.reset();
199182

200-
// If it exists check if it is inside the tracr proc list
201-
// If yes, erase it, else abort
202-
eraseTraCRThread(syscall(SYS_gettid));
203-
204183
// Decrease global thread counter
205184
--num_tracr_threads;
206185

0 commit comments

Comments
 (0)