Delete rtems_bsd_thread_chain

Rely on RTEMS object registration for threads.
This commit is contained in:
Sebastian Huber 2014-09-25 10:48:14 +02:00
parent ccbc70df3e
commit 6604dc893e
8 changed files with 69 additions and 98 deletions

View File

@ -201,15 +201,11 @@ struct rusage_ext {
* This is what is put to sleep and reactivated. * This is what is put to sleep and reactivated.
* Thread context. Processes may have multiple threads. * Thread context. Processes may have multiple threads.
*/ */
#ifdef __rtems__
#include <rtems/chain.h>
#endif /* __rtems__ */
struct thread { struct thread {
#ifdef __rtems__ #ifdef __rtems__
rtems_chain_node td_node;
Thread_Control *td_thread; Thread_Control *td_thread;
struct rtems_bsd_program_control *td_prog_ctrl; struct rtems_bsd_program_control *td_prog_ctrl;
char td_name [16]; char td_name[32];
#endif /* __rtems__ */ #endif /* __rtems__ */
#ifndef __rtems__ #ifndef __rtems__
struct mtx *volatile td_lock; /* replaces sched lock */ struct mtx *volatile td_lock; /* replaces sched lock */

View File

@ -68,8 +68,6 @@ struct sleepqueue {
void *sq_wchan; void *sq_wchan;
}; };
extern rtems_chain_control rtems_bsd_thread_chain;
struct thread * struct thread *
rtems_bsd_get_thread(const Thread_Control *thread); rtems_bsd_get_thread(const Thread_Control *thread);

View File

@ -70,8 +70,6 @@ extern const size_t rtems_bsd_nexus_device_count;
rtems_status_code rtems_bsd_initialize(void); rtems_status_code rtems_bsd_initialize(void);
void rtems_bsd_shell_initialize(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -18,17 +18,24 @@
#include <rtems/shell.h> #include <rtems/shell.h>
/* #ifdef __cplusplus
* Externs for all command definition structures extern "C" {
*/ #endif /* __cplusplus */
// #if RTEMS_NETWORKING
extern rtems_shell_cmd_t rtems_shell_PING_Command;
extern rtems_shell_cmd_t rtems_shell_PING6_Command;
extern rtems_shell_cmd_t rtems_shell_IFCONFIG_Command; extern rtems_shell_cmd_t rtems_shell_BSD_Command;
extern rtems_shell_cmd_t rtems_shell_ROUTE_Command;
extern rtems_shell_cmd_t rtems_shell_NETSTAT_Command; extern rtems_shell_cmd_t rtems_shell_PING_Command;
extern rtems_shell_cmd_t rtems_shell_DHCPCD_Command; extern rtems_shell_cmd_t rtems_shell_PING6_Command;
// #endif
extern rtems_shell_cmd_t rtems_shell_IFCONFIG_Command;
extern rtems_shell_cmd_t rtems_shell_ROUTE_Command;
extern rtems_shell_cmd_t rtems_shell_NETSTAT_Command;
extern rtems_shell_cmd_t rtems_shell_DHCPCD_Command;
extern rtems_shell_cmd_t rtems_shell_DHCPCD_Command;
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif

View File

@ -43,38 +43,13 @@
#include <rtems/bsd/sys/param.h> #include <rtems/bsd/sys/param.h>
#include <rtems/bsd/sys/types.h> #include <rtems/bsd/sys/types.h>
#include <sys/systm.h> #include <sys/systm.h>
#include <sys/kernel.h>
#include <rtems/bsd/sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
static void
suspend_all_threads(void)
{
const rtems_chain_control *chain = &rtems_bsd_thread_chain;
const rtems_chain_node *node = rtems_chain_immutable_first(chain);
rtems_id self = rtems_task_self();
while (!rtems_chain_is_tail(chain, node)) {
const struct thread *td = (const struct thread *) node;
rtems_id id = rtems_bsd_get_task_id(td);
if (id != self) {
rtems_task_suspend(id);
}
node = rtems_chain_immutable_next(node);
}
rtems_task_suspend(RTEMS_SELF);
}
void void
panic(const char *fmt, ...) panic(const char *fmt, ...)
{ {
va_list ap; va_list ap;
printf("*** BSD PANIC *** "); printf("\n*** BSD PANIC *** ");
va_start(ap, fmt); va_start(ap, fmt);
vprintf(fmt, ap); vprintf(fmt, ap);
@ -82,7 +57,7 @@ panic(const char *fmt, ...)
printf("\n"); printf("\n");
suspend_all_threads(); rtems_task_suspend(RTEMS_SELF);
/* FIXME */ /* FIXME */
rtems_fatal_error_occurred(0xdeadbeef); rtems_fatal_error_occurred(0xdeadbeef);

View File

@ -7,7 +7,7 @@
*/ */
/* /*
* Copyright (c) 2009-2013 embedded brains GmbH. All rights reserved. * Copyright (c) 2009-2014 embedded brains GmbH. All rights reserved.
* *
* embedded brains GmbH * embedded brains GmbH
* Dornierstr. 4 * Dornierstr. 4
@ -46,67 +46,71 @@
#include <sys/systm.h> #include <sys/systm.h>
#include <sys/proc.h> #include <sys/proc.h>
#include <rtems/bsd/bsd.h> #include <inttypes.h>
#include <rtems/shell.h>
#include <rtems/netcmds-config.h>
static void static void
rtems_bsd_dump_thread(void) rtems_bsd_dump_thread(Thread_Control *thread)
{ {
const rtems_chain_control *chain = &rtems_bsd_thread_chain; const struct thread *td = rtems_bsd_get_thread(thread);
const rtems_chain_node *node = rtems_chain_immutable_first(chain);
printf("thread dump:\n"); if (td != NULL) {
char buf[5];
const char *name = td->td_name;
while (!rtems_chain_is_tail(chain, node)) { if (name == NULL || name[0] == '\0') {
const struct thread *td = (const struct thread *) node; rtems_object_get_name(thread->Object.id, sizeof(buf), &buf[0]);
name = &buf[0];
}
printf("\t%s: 0x%08x\n", td->td_name, rtems_bsd_get_task_id(td)); fprintf(
stdout,
node = rtems_chain_immutable_next(node); " 0x%08" PRIx32 " | %8" PRIu32 " | %s\n",
thread->Object.id,
thread->current_priority,
name
);
} }
} }
static const char rtems_bsd_usage [] = static void
"bsd {all|condvar|thread|callout}"; rtems_bsd_dump_threads(void)
{
fprintf(
stdout,
"-------------------------------------------------------------------------------\n"
" BSD THREADS\n"
"------------+----------+-------------------------------------------------------\n"
" ID | PRIORITY | NAME\n"
"------------+----------+-------------------------------------------------------\n"
);
rtems_iterate_over_all_threads(rtems_bsd_dump_thread);
fprintf(
stdout,
"------------+----------+-------------------------------------------------------\n"
);
}
static const char rtems_bsd_usage[] = "bsd";
#define CMP(s) all || strcasecmp(argv [1], s) == 0 #define CMP(s) all || strcasecmp(argv [1], s) == 0
static int static int
rtems_bsd_info(int argc, char **argv) rtems_bsd_info(int argc, char **argv)
{ {
bool usage = true; rtems_bsd_dump_threads();
if (argc == 2) {
bool all = false;
if (CMP("all")) {
all = true;
}
if (CMP("thread")) {
rtems_bsd_dump_thread();
usage = false;
}
}
if (usage) {
puts(rtems_bsd_usage);
}
return 0; return 0;
} }
static rtems_shell_cmd_t rtems_bsd_info_command = { rtems_shell_cmd_t rtems_shell_BSD_Command = {
.name = "bsd", .name = "bsd",
.usage = rtems_bsd_usage, .usage = &rtems_bsd_usage[0],
.topic = "bsp", .topic = "bsp",
.command = rtems_bsd_info, .command = rtems_bsd_info,
.alias = NULL, .alias = NULL,
.next = NULL .next = NULL
}; };
void
rtems_bsd_shell_initialize(void)
{
rtems_shell_add_cmd_struct(&rtems_bsd_info_command);
}

View File

@ -57,8 +57,6 @@
#include <rtems/score/threadimpl.h> #include <rtems/score/threadimpl.h>
#include <rtems/score/threadqimpl.h> #include <rtems/score/threadqimpl.h>
RTEMS_CHAIN_DEFINE_EMPTY(rtems_bsd_thread_chain);
static size_t rtems_bsd_extension_index; static size_t rtems_bsd_extension_index;
static CHAIN_DEFINE_EMPTY(rtems_bsd_thread_delay_start_chain); static CHAIN_DEFINE_EMPTY(rtems_bsd_thread_delay_start_chain);
@ -162,15 +160,14 @@ rtems_bsd_extension_thread_create(
Thread_Control *created Thread_Control *created
) )
{ {
bool ok = true; bool ok;
if (rtems_bsd_is_bsd_thread(created)) { if (rtems_bsd_is_bsd_thread(created)) {
struct thread *td = rtems_bsd_thread_create(created, 0); struct thread *td = rtems_bsd_thread_create(created, 0);
ok = td != NULL; ok = td != NULL;
if (ok) { } else {
rtems_chain_append(&rtems_bsd_thread_chain, &td->td_node); ok = true;
}
} }
return ok; return ok;
@ -186,11 +183,6 @@ rtems_bsd_extension_thread_delete(
if (td != NULL) { if (td != NULL) {
seltdfini(td); seltdfini(td);
if (rtems_bsd_is_bsd_thread(deleted)) {
rtems_chain_extract(&td->td_node);
}
free(td->td_sleepqueue, M_TEMP); free(td->td_sleepqueue, M_TEMP);
free(td, M_TEMP); free(td, M_TEMP);
} }

View File

@ -309,6 +309,7 @@ SYSINIT_NEED_NET_PF_UNIX;
#define CONFIGURE_SHELL_USER_COMMANDS \ #define CONFIGURE_SHELL_USER_COMMANDS \
&bsp_interrupt_shell_command, \ &bsp_interrupt_shell_command, \
&rtems_shell_BSD_Command, \
&rtems_shell_PING_Command, \ &rtems_shell_PING_Command, \
&rtems_shell_ROUTE_Command, \ &rtems_shell_ROUTE_Command, \
&rtems_shell_NETSTAT_Command, \ &rtems_shell_NETSTAT_Command, \