Skip to content

Commit 352c782

Browse files
committed
Cleanup: Get rid of global task_array and add static where possible
1 parent bdbf604 commit 352c782

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

src/rtapi/uspace_rtapi_app.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ rtapi_task::rtapi_task()
4848
{
4949
}
5050

51+
struct rtapi_task *RtapiApp::task_array[MAX_TASKS];
52+
5153
/* Priority functions. Uspace uses POSIX task priorities. */
5254

5355
int RtapiApp::prio_highest() const {

src/rtapi/uspace_rtapi_app.hh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ struct rtapi_task {
6666
void (*taskcode)(void *); /* pointer to task function */
6767
};
6868

69+
#define MAX_TASKS 64
70+
#define TASK_MAGIC 21979 /* random numbers used as signatures */
71+
#define TASK_MAGIC_INIT ((rtapi_task *)(-1))
72+
6973
struct RtapiApp {
7074

7175
RtapiApp(int policy = SCHED_OTHER) : policy(policy), period(0) {
@@ -99,6 +103,7 @@ struct RtapiApp {
99103
virtual void do_delay(long ns) = 0;
100104
int policy;
101105
long period;
106+
static struct rtapi_task *task_array[MAX_TASKS];
102107
};
103108

104109
template <class T = rtapi_task> T *rtapi_get_task(int task_id) {
@@ -108,12 +113,6 @@ template <class T = rtapi_task> T *rtapi_get_task(int task_id) {
108113
int find_rt_cpu_number();
109114
void set_namef(const char *fmt, ...);
110115

111-
#define MAX_TASKS 64
112-
#define TASK_MAGIC 21979 /* random numbers used as signatures */
113-
#define TASK_MAGIC_INIT ((rtapi_task *)(-1))
114-
115-
extern struct rtapi_task *task_array[MAX_TASKS];
116-
117116
extern uid_t euid, ruid; //ToDo: Improve
118117

119118
#define WITH_ROOT WithRoot root

src/rtapi/uspace_rtapi_main.cc

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@
5959
#include "hal/hal_priv.h"
6060
#include "uspace_common.h"
6161

62-
RtapiApp &App();
62+
static RtapiApp &App();
6363

6464
struct message_t {
6565
msg_level_t level;
6666
char msg[1024 - sizeof(level)];
6767
};
6868

69-
boost::lockfree::queue<message_t, boost::lockfree::capacity<128>> rtapi_msg_queue;
69+
static boost::lockfree::queue<message_t, boost::lockfree::capacity<128>> rtapi_msg_queue;
7070

71-
pthread_t queue_thread;
72-
void *queue_function(void * /*arg*/) {
71+
static pthread_t queue_thread;
72+
static void *queue_function(void * /*arg*/) {
7373
set_namef("rtapi_app:mesg");
7474
// note: can't use anything in this function that requires App() to exist
7575
// but it's OK to use functions that aren't safe for realtime (that's the
@@ -163,7 +163,7 @@ static int do_one_item(
163163
return 0;
164164
}
165165

166-
void remove_quotes(std::string &s) {
166+
static void remove_quotes(std::string &s) {
167167
s.erase(remove_copy(s.begin(), s.end(), s.begin(), '"'), s.end());
168168
}
169169

@@ -618,7 +618,7 @@ static void signal_handler(int sig, siginfo_t * /*si*/, void * /*uctx*/) {
618618
exit(1);
619619
}
620620

621-
const size_t PRE_ALLOC_SIZE = 1024 * 1024 * 32;
621+
const static size_t PRE_ALLOC_SIZE = 1024 * 1024 * 32;
622622
const static struct rlimit unlimited = {RLIM_INFINITY, RLIM_INFINITY};
623623
static void configure_memory() {
624624
int res = setrlimit(RLIMIT_MEMLOCK, &unlimited);
@@ -794,9 +794,6 @@ RtapiApp &App() {
794794
return *app;
795795
}
796796

797-
/* data for all tasks */
798-
struct rtapi_task *task_array[MAX_TASKS];
799-
800797
int rtapi_prio_highest(void) {
801798
return App().prio_highest();
802799
}

0 commit comments

Comments
 (0)