Beispiel #1
0
static void _Thread_Make_zombie( Thread_Control *the_thread )
{
  ISR_lock_Context lock_context;
  Thread_Zombie_control *zombies = &_Thread_Zombies;

  if ( _Thread_Owns_resources( the_thread ) ) {
    _Terminate(
      INTERNAL_ERROR_CORE,
      false,
      INTERNAL_ERROR_RESOURCE_IN_USE
    );
  }

  _Objects_Close(
    _Objects_Get_information_id( the_thread->Object.id ),
    &the_thread->Object
  );

  _Thread_Set_state( the_thread, STATES_ZOMBIE );
  _Thread_queue_Extract_with_proxy( the_thread );
  _Watchdog_Remove_ticks( &the_thread->Timer );

  _ISR_lock_ISR_disable_and_acquire( &zombies->Lock, &lock_context );
  _Chain_Append_unprotected( &zombies->Chain, &the_thread->Object.Node );
  _ISR_lock_Release_and_ISR_enable( &zombies->Lock, &lock_context );
}
Beispiel #2
0
static void test_isr_locks( void )
{
  ISR_Level normal_interrupt_level = _ISR_Get_level();
  ISR_lock_Control initialized = ISR_LOCK_INITIALIZER;
  ISR_lock_Control lock;
  ISR_lock_Context lock_context;

  _ISR_lock_Initialize( &lock );
  rtems_test_assert( memcmp( &lock, &initialized, sizeof( lock ) ) == 0 );

  _ISR_lock_ISR_disable_and_acquire( &lock, &lock_context );
  rtems_test_assert( normal_interrupt_level != _ISR_Get_level() );
  _ISR_lock_Release_and_ISR_enable( &lock, &lock_context );

  rtems_test_assert( normal_interrupt_level == _ISR_Get_level() );

  _ISR_lock_Acquire( &lock, &lock_context );
  rtems_test_assert( normal_interrupt_level == _ISR_Get_level() );
  _ISR_lock_Release( &lock, &lock_context );

  rtems_test_assert( normal_interrupt_level == _ISR_Get_level() );

  _ISR_lock_Destroy( &lock );
  _ISR_lock_Destroy( &initialized );
}
static void _Thread_Add_to_zombie_chain( Thread_Control *the_thread )
{
  ISR_lock_Context       lock_context;
  Thread_Zombie_control *zombies;

  zombies = &_Thread_Zombies;
  _ISR_lock_ISR_disable_and_acquire( &zombies->Lock, &lock_context );
  _Chain_Append_unprotected( &zombies->Chain, &the_thread->Object.Node );
  _ISR_lock_Release_and_ISR_enable( &zombies->Lock, &lock_context );
}
Beispiel #4
0
void rtems_chain_prepend(
    rtems_chain_control *chain,
    rtems_chain_node *node
)
{
    ISR_Level level;

    _ISR_lock_ISR_disable_and_acquire( &chain->Lock, level );
    _Chain_Prepend_unprotected( &chain->Chain, node );
    _ISR_lock_Release_and_ISR_enable( &chain->Lock, level );
}
Beispiel #5
0
rtems_chain_node *rtems_chain_get( rtems_chain_control *chain )
{
    rtems_chain_node *node;
    ISR_Level level;

    _ISR_lock_ISR_disable_and_acquire( &chain->Lock, level );
    node = _Chain_Get_unprotected( &chain->Chain );
    _ISR_lock_Release_and_ISR_enable( &chain->Lock, level );

    return node;
}
Beispiel #6
0
void rtems_chain_explicit_extract(
    rtems_chain_control *chain,
    rtems_chain_node *node
)
{
ISR_Level level;

_ISR_lock_ISR_disable_and_acquire( &chain->Lock, level );
_Chain_Extract_unprotected( node );
_ISR_lock_Release_and_ISR_enable( &chain->Lock, level );
}
Beispiel #7
0
void rtems_chain_explicit_insert(
    rtems_chain_control *chain,
    rtems_chain_node *after_node,
    rtems_chain_node *node
)
{
    ISR_Level level;

    _ISR_lock_ISR_disable_and_acquire( &chain->Lock, level );
    _Chain_Insert_unprotected( after_node, node );
    _ISR_lock_Release_and_ISR_enable( &chain->Lock, level );
}
void _Thread_Kill_zombies( void )
{
  ISR_lock_Context lock_context;
  Thread_Zombie_control *zombies = &_Thread_Zombies;
  Thread_Control *the_thread;

  _ISR_lock_ISR_disable_and_acquire( &zombies->Lock, &lock_context );

  the_thread = (Thread_Control *) _Chain_Get_unprotected( &zombies->Chain );
  while ( the_thread != NULL ) {
    _ISR_lock_Release_and_ISR_enable( &zombies->Lock, &lock_context );

    _Thread_Wait_for_execution_stop( the_thread );
    _Thread_Free( the_thread );

    _ISR_lock_ISR_disable_and_acquire( &zombies->Lock, &lock_context );

    the_thread = (Thread_Control *) _Chain_Get_unprotected( &zombies->Chain );
  }

  _ISR_lock_Release_and_ISR_enable( &zombies->Lock, &lock_context );
}
Beispiel #9
0
unsigned int alarm(
  unsigned int seconds
)
{
  unsigned int      remaining;
  Watchdog_Control *the_watchdog;
  ISR_lock_Context  lock_context;
  ISR_lock_Context  lock_context2;
  Per_CPU_Control  *cpu;
  uint64_t          now;
  uint32_t          ticks_per_second;
  uint32_t          ticks;

  the_watchdog = &_POSIX_signals_Alarm_watchdog;
  ticks_per_second = TOD_TICKS_PER_SECOND;
  ticks = seconds * ticks_per_second;

  _ISR_lock_ISR_disable_and_acquire(
    &_POSIX_signals_Alarm_lock,
    &lock_context
  );

  cpu = _Watchdog_Get_CPU( the_watchdog );
  _Watchdog_Per_CPU_acquire_critical( cpu, &lock_context2 );
  now = cpu->Watchdog.ticks;

  remaining = (unsigned long) _Watchdog_Cancel(
    &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_RELATIVE ],
    the_watchdog,
    now
  );

  if ( ticks != 0 ) {
    cpu = _Per_CPU_Get();
    _Watchdog_Set_CPU( the_watchdog, cpu );
    _Watchdog_Insert(
      &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_RELATIVE ],
      the_watchdog,
      now + ticks
    );
  }

  _Watchdog_Per_CPU_release_critical( cpu, &lock_context2 );
  _ISR_lock_Release_and_ISR_enable(
    &_POSIX_signals_Alarm_lock,
    &lock_context
  );

  return ( remaining + ticks_per_second - 1 ) / ticks_per_second;
}
Beispiel #10
0
bool rtems_chain_append_with_empty_check(
    rtems_chain_control *chain,
    rtems_chain_node *node
)
{
    bool was_empty;
    ISR_Level level;

    _ISR_lock_ISR_disable_and_acquire( &chain->Lock, level );
    was_empty = _Chain_Append_with_empty_check_unprotected(
                    &chain->Chain,
                    node
                );
    _ISR_lock_Release_and_ISR_enable( &chain->Lock, level );

    return was_empty;
}
Beispiel #11
0
bool rtems_chain_get_with_empty_check(
    rtems_chain_control *chain,
    rtems_chain_node **node
)
{
    bool is_empty_now;
    ISR_Level level;

    _ISR_lock_ISR_disable_and_acquire( &chain->Lock, level );
    is_empty_now = _Chain_Get_with_empty_check_unprotected(
                       &chain->Chain,
                       node
                   );
    _ISR_lock_Release_and_ISR_enable( &chain->Lock, level );

    return is_empty_now;
}
Beispiel #12
0
static void _Thread_queue_Acquire( ISR_lock_Context *lock_context )
{
  _ISR_lock_ISR_disable_and_acquire( &_Thread_queue_Lock, lock_context );
}
Beispiel #13
0
static void _Thread_MP_Proxies_acquire( ISR_lock_Context *lock_context )
{
  _ISR_lock_ISR_disable_and_acquire( &_Thread_MP_Proxies_lock, lock_context );
}