• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nasa / trick / 25520945172

07 May 2026 08:42PM UTC coverage: 56.784% (-0.009%) from 56.793%
25520945172

push

github

web-flow
Add Linux LLVM 22 support (#2096)

12915 of 22744 relevant lines covered (56.78%)

298895.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.27
/trick_source/sim_services/ThreadBase/SysThread.cpp
1

2
#include <iostream>
3
#include <sstream>
4
#include <stdio.h>
5
#if __linux__
6
#include <sys/syscall.h>
7
#include <sys/types.h>
8
#include <sched.h>
9
#endif
10
#include <signal.h>
11
#include <algorithm>
12
#include <time.h>
13

14
#include "trick/SysThread.hh"
15

16
bool Trick::SysThread::shutdown_finished = false;
17

18
// Construct On First Use to avoid the Static Initialization Fiasco
19
pthread_mutex_t& Trick::SysThread::list_mutex() {
3,564✔
20
    static pthread_mutex_t list_mutex = PTHREAD_MUTEX_INITIALIZER;
21
    return list_mutex;
3,564✔
22
} 
23

24
pthread_cond_t& Trick::SysThread::list_empty_cv() {
×
25
    static pthread_cond_t list_empty_cv = PTHREAD_COND_INITIALIZER;
26
    return list_empty_cv;
×
27
} 
28

29
std::vector<Trick::SysThread *>& Trick::SysThread::all_sys_threads() {
1,350✔
30
    static std::vector<SysThread *> all_sys_threads;
1,350✔
31
    return all_sys_threads;
1,350✔
32
}
33

34
Trick::SysThread::SysThread(std::string in_name) : ThreadBase(in_name) {
804✔
35
    pthread_mutex_init(&_restart_pause_mutex, NULL);
804✔
36
    pthread_cond_init(&_thread_has_paused_cv, NULL);
804✔
37
    pthread_cond_init(&_thread_wakeup_cv, NULL);
804✔
38
    _thread_has_paused = true;
804✔
39
    _thread_should_pause = false;
804✔
40

41
    pthread_mutex_lock(&(list_mutex()));
804✔
42
    all_sys_threads().push_back(this);
804✔
43
    pthread_mutex_unlock(&(list_mutex()));
804✔
44
}
804✔
45

46

47
Trick::SysThread::~SysThread() {
791✔
48
    pthread_mutex_lock(&(list_mutex()));
791✔
49
    if (!shutdown_finished) {
791✔
50
        all_sys_threads().erase(std::remove(all_sys_threads().begin(), all_sys_threads().end(), this), all_sys_threads().end());
43✔
51
    }
52
    pthread_mutex_unlock(&(list_mutex()));
791✔
53
}
791✔
54

55
int Trick::SysThread::ensureAllShutdown() {
187✔
56
    pthread_mutex_lock(&(list_mutex()));
187✔
57

58
    // Cancel all threads
59
    for (SysThread * thread : all_sys_threads()) {
941✔
60
        thread->cancel_thread();
754✔
61
    }
62

63
    // Join all threads
64
    for (SysThread * thread : all_sys_threads()) {
941✔
65
        thread->join_thread();
754✔
66
    }
67

68
    // Success!
69
    shutdown_finished = true;
187✔
70
    pthread_mutex_unlock(&(list_mutex()));
187✔
71

72
    return 0;
187✔
73
}
74

75
// To be called from main thread
76
void Trick::SysThread::force_thread_to_pause() {
11✔
77
    pthread_mutex_lock(&_restart_pause_mutex);
11✔
78
    // Tell thread to pause, and wait for it to signal that it has
79
    _thread_should_pause = true;
11✔
80
    while (!_thread_has_paused) {
11✔
81
        pthread_cond_wait(&_thread_has_paused_cv, &_restart_pause_mutex);
×
82
    }
83
    pthread_mutex_unlock(&_restart_pause_mutex);
11✔
84
}
11✔
85

86
// To be called from main thread
87
void Trick::SysThread::unpause_thread() {
11✔
88
    pthread_mutex_lock(&_restart_pause_mutex);
11✔
89
    // Tell thread to wake up
90
    _thread_should_pause = false;
11✔
91
    pthread_cond_signal(&_thread_wakeup_cv);
11✔
92
    pthread_mutex_unlock(&_restart_pause_mutex);
11✔
93
}
11✔
94

95

96
// To be called from this thread
97
void Trick::SysThread::test_pause() {
2,776,287✔
98
    pthread_mutex_lock(&_restart_pause_mutex) ;
2,776,287✔
99
    if (_thread_should_pause) {
2,776,287✔
100
        // Tell main thread that we're pausing
101
        _thread_has_paused = true;
×
102
        pthread_cond_signal(&_thread_has_paused_cv);
×
103
        
104
        // Wait until we're told to wake up
105
        while (_thread_should_pause) {
×
106
            pthread_cond_wait(&_thread_wakeup_cv, &_restart_pause_mutex);
×
107
        }
108
    }
109

110
    _thread_has_paused = false;
2,776,287✔
111
    pthread_mutex_unlock(&_restart_pause_mutex) ;
2,776,287✔
112
}
2,776,287✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc