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

nasa / trick / 4691235275

pending completion
4691235275

push

github

GitHub
SIM_aircraft Waypoint Update (#1466)

12428 of 21393 relevant lines covered (58.09%)

74619.08 hits per line

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

94.44
/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

13
#include "trick/SysThread.hh"
14

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

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

23
pthread_cond_t& Trick::SysThread::list_empty_cv() {
2✔
24
    static pthread_cond_t list_empty_cv = PTHREAD_COND_INITIALIZER;
25
    return list_empty_cv;
2✔
26
} 
27

28
std::vector<Trick::SysThread *>& Trick::SysThread::all_sys_threads() {
3,997✔
29
    static std::vector<SysThread *> all_sys_threads;
3,997✔
30
    return all_sys_threads;
3,997✔
31
}
32

33
Trick::SysThread::SysThread(std::string in_name, bool sd) : self_deleting(sd), ThreadBase(in_name) {
984✔
34
    pthread_mutex_lock(&(list_mutex()));
984✔
35
    all_sys_threads().push_back(this);
984✔
36
    pthread_mutex_unlock(&(list_mutex()));
984✔
37
}
984✔
38

39

40
Trick::SysThread::~SysThread() {
983✔
41
    pthread_mutex_lock(&(list_mutex()));
983✔
42
    if (!shutdown_finished) {
983✔
43
        all_sys_threads().erase(std::remove(all_sys_threads().begin(), all_sys_threads().end(), this), all_sys_threads().end());
31✔
44
        if (all_sys_threads().size() == 0) {
31✔
45
            pthread_cond_signal(&(list_empty_cv()));
2✔
46
        }
47
    }
48
    pthread_mutex_unlock(&(list_mutex()));
983✔
49
}
983✔
50

51
int Trick::SysThread::ensureAllShutdown() {
238✔
52
    pthread_mutex_lock(&(list_mutex()));
238✔
53

54
    for (SysThread * thread : all_sys_threads()) {
1,191✔
55
        thread->cancel_thread();
953✔
56
    }
57

58
    auto it = all_sys_threads().begin();
238✔
59
    while (it != all_sys_threads().end()){
1,191✔
60
        SysThread * thread = *it;
953✔
61
        if (!(thread->self_deleting)) {
953✔
62
            thread->join_thread();
953✔
63
            it = all_sys_threads().erase(it);
953✔
64
        } else {
65
            ++it;
×
66
        }
67
    }
68

69
    while (all_sys_threads().size() != 0) {
238✔
70
        pthread_cond_wait(&(list_empty_cv()), &(list_mutex()));
×
71
    }
72

73
    shutdown_finished = true;
238✔
74
    pthread_mutex_unlock(&(list_mutex()));
238✔
75

76
    return 0;
238✔
77
}
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