Skip to content

Commit f52ef21

Browse files
committed
Cleanup: remove run_threads
There is nothing usefull you can do in run_threads due to callback() blocks on accept and only returns on a slave command. Return -1 did not break the while loop. It looks like a mistake. Never the less, this behavour is kept due to exiting all threads just because a socket error happened is most probably not desired.
1 parent 3a1f69c commit f52ef21

6 files changed

Lines changed: 9 additions & 39 deletions

File tree

src/rtapi/uspace_posix.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,6 @@ struct PosixApp : RtapiApp {
194194
#endif
195195
}
196196

197-
int run_threads(int fd, int (*callback)(int fd)) {
198-
while (callback(fd)) {
199-
/* nothing */
200-
}
201-
return 0;
202-
}
203-
204197
int task_self() {
205198
struct rtapi_task *task = reinterpret_cast<rtapi_task *>(pthread_getspecific(key));
206199
if (!task)

src/rtapi/uspace_rtai.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,6 @@ struct RtaiApp : RtapiApp {
175175
#endif
176176
}
177177

178-
int run_threads(int fd, int (*callback)(int fd)) {
179-
while (callback(fd)) {
180-
/* nothing */
181-
}
182-
return 0;
183-
}
184-
185178
int task_self() {
186179
struct rtapi_task *task = reinterpret_cast<rtapi_task *>(pthread_getspecific(key));
187180
if (!task)

src/rtapi/uspace_rtapi_app.hh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ struct RtapiApp {
108108
virtual void wait() = 0;
109109
virtual unsigned char do_inb(unsigned int port) = 0;
110110
virtual void do_outb(unsigned char value, unsigned int port) = 0;
111-
virtual int run_threads(int fd, int (*callback)(int fd)) = 0;
112111
virtual long long do_get_time(void) = 0;
113112
virtual void do_delay(long ns) = 0;
114113
static int find_rt_cpu_number();

src/rtapi/uspace_rtapi_main.cc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ static void *queue_function(void * /*arg*/) {
8787
return nullptr;
8888
}
8989

90-
static int sim_rtapi_run_threads(int fd, int (*callback)(int fd));
91-
9290
template <class T> T DLSYM(void *handle, const std::string &name) {
9391
return (T)(dlsym(handle, name.c_str()));
9492
}
@@ -454,21 +452,25 @@ static int slave(int fd, const std::vector<std::string> &args) {
454452
}
455453
}
456454

457-
static int callback(int fd) {
455+
//Processes incoming command on socket
456+
//This function blocks on accept until a client connects
457+
//return: true if master should continue
458+
// false if master should exit
459+
static bool master_process_socket_command(int fd) {
458460
struct sockaddr_un client_addr;
459461
memset(&client_addr, 0, sizeof(client_addr));
460462
socklen_t len = sizeof(client_addr);
461463
int fd1 = accept(fd, (sockaddr *)&client_addr, &len);
462464
if (fd1 < 0) {
463465
rtapi_print_msg(RTAPI_MSG_ERR, "rtapi_app: failed to accept connection from slave: %s\n", strerror(errno));
464-
return -1;
466+
return true; //If there is a socket error, just continue
465467
} else {
466468
int result;
467469
std::vector<std::string> args;
468470
if (!recv_args(fd1, args)) {
469471
rtapi_print_msg(RTAPI_MSG_ERR, "rtapi_app: failed to read from slave: %s\n", strerror(errno));
470472
close(fd1);
471-
return -1;
473+
return true; //If there is a socket error, just continue
472474
}
473475

474476
result = handle_command(args);
@@ -501,7 +503,8 @@ static int master(int fd, const std::vector<std::string> &args) {
501503
if (force_exit || instance_count == 0)
502504
goto out;
503505
}
504-
sim_rtapi_run_threads(fd, callback);
506+
//Process commands as long as master should not exit
507+
while(master_process_socket_command(fd));
505508
out:
506509
pthread_cancel(queue_thread);
507510
pthread_join(queue_thread, nullptr);
@@ -962,10 +965,6 @@ long int simple_strtol(const char *nptr, char **endptr, int base) {
962965
return strtol(nptr, endptr, base);
963966
}
964967

965-
int sim_rtapi_run_threads(int fd, int (*callback)(int fd)) {
966-
return App().run_threads(fd, callback);
967-
}
968-
969968
long long rtapi_get_time() {
970969
return App().do_get_time();
971970
}

src/rtapi/uspace_xenomai.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,6 @@ struct XenomaiApp : RtapiApp {
188188
#endif
189189
}
190190

191-
int run_threads(int fd, int (*callback)(int fd)) {
192-
while (callback(fd)) {
193-
/* nothing */
194-
}
195-
return 0;
196-
}
197-
198191
int task_self() {
199192
struct rtapi_task *task = reinterpret_cast<rtapi_task *>(pthread_getspecific(key));
200193
if (!task)

src/rtapi/uspace_xenomai_evl.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,6 @@ struct EvlApp : RtapiApp {
209209
#endif
210210
}
211211

212-
int run_threads(int fd, int (*callback)(int fd)) {
213-
while (callback(fd)) {
214-
/* nothing */
215-
}
216-
return 0;
217-
}
218-
219212
int task_self() {
220213
struct rtapi_task *task = reinterpret_cast<rtapi_task *>(pthread_getspecific(key));
221214
if (!task)

0 commit comments

Comments
 (0)