Changeset c2f6513 in rtems-libbsd


Ignore:
Timestamp:
Nov 13, 2013, 3:52:02 PM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, c1e05b9ea378b2971e3d7704779112b4bc4296da, freebsd-9.3, 4a77611a223ea883fb548679b516d326a020d447
Children:
fafa9e2
Parents:
7f1836c
git-author:
Sebastian Huber <sebastian.huber@…> (11/13/13 15:52:02)
git-committer:
Sebastian Huber <sebastian.huber@…> (11/13/13 16:44:40)
Message:

threads: Delay thread start during initialization

The FreeBSD initialization is supposed to be single-threaded.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rtemsbsd/rtems/rtems-bsd-thread.c

    r7f1836c rc2f6513  
    6262static size_t rtems_bsd_extension_index;
    6363
     64static CHAIN_DEFINE_EMPTY(rtems_bsd_thread_delay_start_chain);
     65
     66static bool rtems_bsd_thread_ready_to_start;
     67
    6468struct thread *
    6569rtems_bsd_get_thread(const Thread_Control *thread)
     
    6872}
    6973
    70 static struct thread *
     74static Thread_Control *
    7175rtems_bsd_get_thread_by_id(rtems_id task_id)
    7276{
    73         struct thread *td = NULL;
    7477        Thread_Control *thread;
    7578        Objects_Locations location;
     
    7881        switch (location) {
    7982                case OBJECTS_LOCAL:
    80                         td = rtems_bsd_get_thread(thread);
    8183                        _Objects_Put(&thread->Object);
    8284                        break;
     
    8486                case OBJECTS_REMOTE:
    8587                        _Thread_Dispatch();
     88                        thread = NULL;
    8689                        break;
    8790#endif
    8891                default:
     92                        thread = NULL;
    8993                        break;
    9094        }
    9195
    92         return td;
     96        return thread;
    9397}
    9498
     
    199203
    200204static void
    201 rtems_bsd_threads_init(void *arg __unused)
     205rtems_bsd_threads_init_early(void *arg)
    202206{
    203207        rtems_id ext_id;
    204208        rtems_status_code sc;
     209
     210        (void) arg;
    205211
    206212        sc = rtems_extension_create(
     
    216222}
    217223
    218 SYSINIT(rtems_bsd_threads, SI_SUB_INTRINSIC, SI_ORDER_ANY, rtems_bsd_threads_init, NULL);
     224static void
     225rtems_bsd_threads_init_late(void *arg)
     226{
     227        Chain_Control *chain = &rtems_bsd_thread_delay_start_chain;
     228        Chain_Node *node;
     229
     230        (void) arg;
     231
     232        while ((node = _Chain_Get_unprotected(chain)) != NULL) {
     233                Thread_Control *thread = (Thread_Control *) node;
     234                rtems_status_code sc;
     235
     236                sc = rtems_task_start(thread->Object.id, (rtems_task_entry)
     237                    thread->Start.entry_point, thread->Start.numeric_argument);
     238                BSD_ASSERT(sc == RTEMS_SUCCESSFUL);
     239        }
     240
     241        rtems_bsd_thread_ready_to_start = true;
     242}
     243
     244SYSINIT(rtems_bsd_threads_early, SI_SUB_INTRINSIC, SI_ORDER_ANY,
     245    rtems_bsd_threads_init_early, NULL);
     246
     247SYSINIT(rtems_bsd_threads_late, SI_SUB_RUN_SCHEDULER, SI_ORDER_ANY,
     248    rtems_bsd_threads_init_late, NULL);
    219249
    220250static int
    221 rtems_bsd_thread_start(struct thread **td_ptr, void (*func)(void *), void *arg, int flags, int pages, const char *fmt, va_list ap)
     251rtems_bsd_thread_start(struct thread **td_ptr, void (*func)(void *), void *arg,
     252    int flags, int pages, const char *fmt, va_list ap)
    222253{
    223254        int eno = 0;
     
    236267        );
    237268        if (sc == RTEMS_SUCCESSFUL) {
    238                 struct thread *td = rtems_bsd_get_thread_by_id(task_id);
    239 
     269                Thread_Control *thread = rtems_bsd_get_thread_by_id(task_id);
     270                struct thread *td;
     271
     272                BSD_ASSERT(thread != NULL);
     273
     274                td = rtems_bsd_get_thread(thread);
    240275                BSD_ASSERT(td != NULL);
    241276
    242277                vsnprintf(td->td_name, sizeof(td->td_name), fmt, ap);
    243278
    244                 sc = rtems_task_start(task_id, (rtems_task_entry) func, (rtems_task_argument) arg);
    245                 BSD_ASSERT(sc == RTEMS_SUCCESSFUL);
     279                if (rtems_bsd_thread_ready_to_start) {
     280                        sc = rtems_task_start(task_id, (rtems_task_entry) func,
     281                            (rtems_task_argument) arg);
     282                        BSD_ASSERT(sc == RTEMS_SUCCESSFUL);
     283                } else {
     284                        thread->Start.entry_point = (Thread_Entry) func;
     285                        thread->Start.numeric_argument =
     286                            (Thread_Entry_numeric_type) arg;
     287                        _Chain_Append_unprotected(
     288                            &rtems_bsd_thread_delay_start_chain,
     289                            &thread->Object.Node);
     290                }
    246291
    247292                if (td_ptr != NULL) {
Note: See TracChangeset for help on using the changeset viewer.