RTEMS CPU Kit with SuperCore  4.11.2
threadimpl.h
Go to the documentation of this file.
1 
10 /*
11  * COPYRIGHT (c) 1989-2008.
12  * On-Line Applications Research Corporation (OAR).
13  *
14  * Copyright (c) 2014 embedded brains GmbH.
15  *
16  * The license and distribution terms for this file may be
17  * found in the file LICENSE in this distribution or at
18  * http://www.rtems.org/license/LICENSE.
19  */
20 
21 #ifndef _RTEMS_SCORE_THREADIMPL_H
22 #define _RTEMS_SCORE_THREADIMPL_H
23 
24 #include <rtems/score/thread.h>
25 #include <rtems/score/assert.h>
26 #include <rtems/score/chainimpl.h>
27 #include <rtems/score/interr.h>
28 #include <rtems/score/isr.h>
29 #include <rtems/score/objectimpl.h>
31 #include <rtems/score/statesimpl.h>
32 #include <rtems/score/sysstate.h>
34 #include <rtems/score/todimpl.h>
35 #include <rtems/config.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
50 #define THREAD_STATUS_PROXY_BLOCKING 0x1111111
51 
56 
62 
67 #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
69 #endif
70 
71 #if !defined(__DYNAMIC_REENT__)
72 
79 #endif
80 
81 #define THREAD_CHAIN_NODE_TO_THREAD( node ) \
82  RTEMS_CONTAINER_OF( node, Thread_Control, Wait.Node.Chain )
83 
84 #define THREAD_RBTREE_NODE_TO_THREAD( node ) \
85  RTEMS_CONTAINER_OF( node, Thread_Control, Wait.Node.RBTree )
86 
87 #if defined(RTEMS_SMP)
88 #define THREAD_RESOURCE_NODE_TO_THREAD( node ) \
89  RTEMS_CONTAINER_OF( node, Thread_Control, Resource_node )
90 #endif
91 
98 
106 void _Thread_Create_idle(void);
107 
116 
130  Thread_Control *the_thread,
131  size_t stack_size
132 );
133 
139 void _Thread_Stack_Free(
140  Thread_Control *the_thread
141 );
142 
156 bool _Thread_Initialize(
157  Objects_Information *information,
158  Thread_Control *the_thread,
159  const struct Scheduler_Control *scheduler,
160  void *stack_area,
161  size_t stack_size,
162  bool is_fp,
163  Priority_Control priority,
164  bool is_preemptible,
165  Thread_CPU_budget_algorithms budget_algorithm,
167  uint32_t isr_level,
168  Objects_Name name
169 );
170 
187 bool _Thread_Start(
188  Thread_Control *the_thread,
189  Thread_Start_types the_prototype,
190  void *entry_point,
191  void *pointer_argument,
192  Thread_Entry_numeric_type numeric_argument,
193  Per_CPU_Control *cpu
194 );
195 
196 bool _Thread_Restart(
197  Thread_Control *the_thread,
198  Thread_Control *executing,
199  void *pointer_argument,
200  Thread_Entry_numeric_type numeric_argument
201 );
202 
203 void _Thread_Yield( Thread_Control *executing );
204 
205 bool _Thread_Set_life_protection( bool protect );
206 
207 void _Thread_Life_action_handler(
208  Thread_Control *executing,
209  Thread_Action *action,
210  Per_CPU_Control *cpu,
211  ISR_Level level
212 );
213 
223 void _Thread_Kill_zombies( void );
224 
232 void _Thread_Close( Thread_Control *the_thread, Thread_Control *executing );
233 
246  Thread_Control *the_thread,
247  States_Control state
248 );
249 
262  Thread_Control *the_thread,
263  States_Control state
264 );
265 
275  Thread_Control *the_thread
276 )
277 {
278  _Thread_Clear_state( the_thread, STATES_ALL_SET );
279 }
280 
290  Thread_Control *the_thread
291 );
292 
308 void _Thread_Handler( void );
309 
318 void *_Thread_Global_construction( void );
319 
331  Objects_Id id,
332  void *ignored
333 );
334 
340  Priority_Control left,
341  Priority_Control right
342 )
343 {
344  return left > right;
345 }
346 
352  Priority_Control left,
353  Priority_Control right
354 )
355 {
356  return _Thread_Priority_less_than( left, right ) ? right : left;
357 }
358 
373  Thread_Control *the_thread,
374  Priority_Control *new_priority,
375  void *arg
376 );
377 
395  Thread_Control *the_thread,
396  Priority_Control new_priority,
397  void *arg,
399  bool prepend_it
400 );
401 
415  Thread_Control *the_thread,
416  Priority_Control new_priority
417 );
418 
424 void _Thread_Restore_priority( Thread_Control *the_thread );
425 
443  Thread_Control *the_thread,
444  Priority_Control new_priority,
445  Priority_Control *old_priority,
446  bool prepend_it
447 );
448 
471  Objects_Id id,
472  Objects_Locations *location
473 );
474 
481  Objects_Id id,
482  Objects_Locations *location,
483  ISR_lock_Context *lock_context
484 );
485 
486 RTEMS_INLINE_ROUTINE Per_CPU_Control *_Thread_Get_CPU(
487  const Thread_Control *thread
488 )
489 {
490 #if defined(RTEMS_SMP)
491  return thread->Scheduler.cpu;
492 #else
493  (void) thread;
494 
495  return _Per_CPU_Get();
496 #endif
497 }
498 
499 RTEMS_INLINE_ROUTINE void _Thread_Set_CPU(
500  Thread_Control *thread,
501  Per_CPU_Control *cpu
502 )
503 {
504 #if defined(RTEMS_SMP)
505  thread->Scheduler.cpu = cpu;
506 #else
507  (void) thread;
508  (void) cpu;
509 #endif
510 }
511 
518  const Thread_Control *the_thread
519 )
520 {
521  return ( the_thread == _Thread_Executing );
522 }
523 
524 #if defined(RTEMS_SMP)
525 
532 RTEMS_INLINE_ROUTINE bool _Thread_Is_executing_on_a_processor(
533  const Thread_Control *the_thread
534 )
535 {
536  return _CPU_Context_Get_is_executing( &the_thread->Registers );
537 }
538 #endif
539 
546  Thread_Control *the_thread,
547  Timestamp_Control *time_of_context_switch
548 )
549 {
550  bool retval = false;
551 
553  #ifndef RTEMS_SMP
554  if ( _Thread_Executing->Object.id == the_thread->Object.id ) {
555  *time_of_context_switch = _Thread_Time_of_last_context_switch;
556  retval = true;
557  }
558  #else
559  if ( _Thread_Is_executing_on_a_processor( the_thread ) ) {
560  *time_of_context_switch =
561  _Thread_Get_CPU( the_thread )->time_of_last_context_switch;
562  retval = true;
563  }
564  #endif
566  return retval;
567 }
568 
569 
576  const Thread_Control *the_thread
577 )
578 {
579  return ( the_thread == _Thread_Heir );
580 }
581 
589  Thread_Control *the_thread
590 )
591 {
592  _Thread_Clear_state( the_thread, STATES_BLOCKED );
593 }
594 
601 {
602 #if defined(RTEMS_SMP)
603  ISR_Level level;
604 
605  _Giant_Release( _Per_CPU_Get() );
606 
607  _ISR_Disable_without_giant( level );
608  ( void ) level;
609 #endif
610 
611 #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
612  if ( executing->fp_context != NULL )
613  _Context_Restore_fp( &executing->fp_context );
614 #endif
615 
616  _CPU_Context_Restart_self( &executing->Registers );
617 }
618 
625 #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
627  const Thread_Control *the_thread
628 )
629 {
630  return ( the_thread == _Thread_Allocated_fp );
631 }
632 #endif
633 
634 /*
635  * If the CPU has hardware floating point, then we must address saving
636  * and restoring it as part of the context switch.
637  *
638  * The second conditional compilation section selects the algorithm used
639  * to context switch between floating point tasks. The deferred algorithm
640  * can be significantly better in a system with few floating point tasks
641  * because it reduces the total number of save and restore FP context
642  * operations. However, this algorithm can not be used on all CPUs due
643  * to unpredictable use of FP registers by some compilers for integer
644  * operations.
645  */
646 
647 RTEMS_INLINE_ROUTINE void _Thread_Save_fp( Thread_Control *executing )
648 {
649 #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
650 #if ( CPU_USE_DEFERRED_FP_SWITCH != TRUE )
651  if ( executing->fp_context != NULL )
652  _Context_Save_fp( &executing->fp_context );
653 #endif
654 #endif
655 }
656 
657 RTEMS_INLINE_ROUTINE void _Thread_Restore_fp( Thread_Control *executing )
658 {
659 #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
660 #if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
661  if ( (executing->fp_context != NULL) &&
662  !_Thread_Is_allocated_fp( executing ) ) {
663  if ( _Thread_Allocated_fp != NULL )
664  _Context_Save_fp( &_Thread_Allocated_fp->fp_context );
665  _Context_Restore_fp( &executing->fp_context );
666  _Thread_Allocated_fp = executing;
667  }
668 #else
669  if ( executing->fp_context != NULL )
670  _Context_Restore_fp( &executing->fp_context );
671 #endif
672 #endif
673 }
674 
680 #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
682 {
683  _Thread_Allocated_fp = NULL;
684 }
685 #endif
686 
693 {
694  return ( _Thread_Dispatch_necessary );
695 }
696 
702  const Thread_Control *the_thread
703 )
704 {
705  return ( the_thread == NULL );
706 }
707 
714  uint32_t code
715 )
716 {
717  return (code == THREAD_STATUS_PROXY_BLOCKING);
718 }
719 
720 RTEMS_INLINE_ROUTINE uint32_t _Thread_Get_maximum_internal_threads(void)
721 {
722  /* Idle threads */
723  uint32_t maximum_internal_threads =
725 
726  /* MPCI thread */
727 #if defined(RTEMS_MULTIPROCESSING)
728  if ( _System_state_Is_multiprocessing ) {
729  ++maximum_internal_threads;
730  }
731 #endif
732 
733  return maximum_internal_threads;
734 }
735 
736 RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Internal_allocate( void )
737 {
738  return (Thread_Control *)
739  _Objects_Allocate_unprotected( &_Thread_Internal_information );
740 }
741 
753  Per_CPU_Control *cpu_self
754 )
755 {
756  Thread_Control *heir;
757 
758  cpu_self->dispatch_necessary = false;
759 
760 #if defined( RTEMS_SMP )
761  /*
762  * It is critical that we first update the dispatch necessary and then the
763  * read the heir so that we don't miss an update by
764  * _Thread_Dispatch_update_heir().
765  */
766  _Atomic_Fence( ATOMIC_ORDER_SEQ_CST );
767 #endif
768 
769  heir = cpu_self->heir;
770  cpu_self->executing = heir;
771 
772  return heir;
773 }
774 
775 #if defined( RTEMS_SMP )
776 RTEMS_INLINE_ROUTINE void _Thread_Dispatch_update_heir(
777  Per_CPU_Control *cpu_self,
778  Per_CPU_Control *cpu_for_heir,
779  Thread_Control *heir
780 )
781 {
782  cpu_for_heir->heir = heir;
783 
784  /*
785  * It is critical that we first update the heir and then the dispatch
786  * necessary so that _Thread_Get_heir_and_make_it_executing() cannot miss an
787  * update.
788  */
789  _Atomic_Fence( ATOMIC_ORDER_SEQ_CST );
790 
791  /*
792  * Only update the dispatch necessary indicator if not already set to
793  * avoid superfluous inter-processor interrupts.
794  */
795  if ( !cpu_for_heir->dispatch_necessary ) {
796  cpu_for_heir->dispatch_necessary = true;
797 
798  if ( cpu_for_heir != cpu_self ) {
799  _Per_CPU_Send_interrupt( cpu_for_heir );
800  }
801  }
802 }
803 #endif
804 
805 RTEMS_INLINE_ROUTINE void _Thread_Update_cpu_time_used(
806  Thread_Control *executing,
807  Timestamp_Control *time_of_last_context_switch
808 )
809 {
810  Timestamp_Control uptime;
811  Timestamp_Control ran;
812 
813  _TOD_Get_uptime( &uptime );
815  time_of_last_context_switch,
816  &uptime,
817  &ran
818  );
819  *time_of_last_context_switch = uptime;
820  _Timestamp_Add_to( &executing->cpu_time_used, &ran );
821 }
822 
823 RTEMS_INLINE_ROUTINE void _Thread_Action_control_initialize(
824  Thread_Action_control *action_control
825 )
826 {
827  _Chain_Initialize_empty( &action_control->Chain );
828 }
829 
830 RTEMS_INLINE_ROUTINE void _Thread_Action_initialize(
831  Thread_Action *action,
832  Thread_Action_handler handler
833 )
834 {
835  action->handler = handler;
836  _Chain_Set_off_chain( &action->Node );
837 }
838 
840  _Thread_Action_ISR_disable_and_acquire_for_executing( ISR_Level *level )
841 {
842  Per_CPU_Control *cpu;
843 
844  _ISR_Disable_without_giant( *level );
845  cpu = _Per_CPU_Get();
846  _Per_CPU_Acquire( cpu );
847 
848  return cpu;
849 }
850 
851 RTEMS_INLINE_ROUTINE Per_CPU_Control *_Thread_Action_ISR_disable_and_acquire(
852  Thread_Control *thread,
853  ISR_Level *level
854 )
855 {
856  Per_CPU_Control *cpu;
857 
858  _ISR_Disable_without_giant( *level );
859  cpu = _Thread_Get_CPU( thread );
860  _Per_CPU_Acquire( cpu );
861 
862  return cpu;
863 }
864 
865 RTEMS_INLINE_ROUTINE void _Thread_Action_release_and_ISR_enable(
866  Per_CPU_Control *cpu,
867  ISR_Level level
868 )
869 {
870  _Per_CPU_Release_and_ISR_enable( cpu, level );
871 }
872 
873 RTEMS_INLINE_ROUTINE void _Thread_Add_post_switch_action(
874  Thread_Control *thread,
875  Thread_Action *action
876 )
877 {
878  Per_CPU_Control *cpu_of_thread;
879  ISR_Level level;
880 
881  cpu_of_thread = _Thread_Action_ISR_disable_and_acquire( thread, &level );
882  cpu_of_thread->dispatch_necessary = true;
883 
884 #if defined(RTEMS_SMP)
885  if ( _Per_CPU_Get() != cpu_of_thread ) {
886  _Per_CPU_Send_interrupt( cpu_of_thread );
887  }
888 #endif
889 
891  &thread->Post_switch_actions.Chain,
892  &action->Node
893  );
894 
895  _Thread_Action_release_and_ISR_enable( cpu_of_thread, level );
896 }
897 
898 RTEMS_INLINE_ROUTINE bool _Thread_Is_life_restarting(
899  Thread_Life_state life_state
900 )
901 {
902  return ( life_state & THREAD_LIFE_RESTARTING ) != 0;
903 }
904 
905 RTEMS_INLINE_ROUTINE bool _Thread_Is_life_terminating(
906  Thread_Life_state life_state
907 )
908 {
909  return ( life_state & THREAD_LIFE_TERMINATING ) != 0;
910 }
911 
912 RTEMS_INLINE_ROUTINE bool _Thread_Is_life_protected(
913  Thread_Life_state life_state
914 )
915 {
916  return ( life_state & THREAD_LIFE_PROTECTED ) != 0;
917 }
918 
919 RTEMS_INLINE_ROUTINE bool _Thread_Is_life_changing(
920  Thread_Life_state life_state
921 )
922 {
923  return ( life_state & THREAD_LIFE_RESTARTING_TERMINATING ) != 0;
924 }
925 
939  const Thread_Control *the_thread
940 )
941 {
942  bool owns_resources = the_thread->resource_count != 0;
943 
944 #if defined(RTEMS_SMP)
945  owns_resources = owns_resources
946  || _Resource_Node_owns_resources( &the_thread->Resource_node );
947 #endif
948 
949  return owns_resources;
950 }
951 
963  ISR_lock_Context *lock_context
964 )
965 {
966  Thread_Control *executing;
967 
968  _ISR_lock_ISR_disable( lock_context );
969  executing = _Thread_Executing;
970  _ISR_lock_Acquire( &executing->Lock.Default, lock_context );
971 
972  return executing;
973 }
974 
986  Thread_Control *the_thread,
987  ISR_lock_Context *lock_context
988 )
989 {
990  _Assert( _ISR_Get_level() != 0 );
991  _ISR_lock_Acquire( &the_thread->Lock.Default, lock_context );
992 }
993 
1004  Thread_Control *the_thread,
1005  ISR_lock_Context *lock_context
1006 )
1007 {
1008  _ISR_lock_ISR_disable_and_acquire( &the_thread->Lock.Default, lock_context );
1009 }
1010 
1022  ISR_lock_Control *lock,
1023  ISR_lock_Context *lock_context
1024 )
1025 {
1026  _ISR_lock_Release( lock, lock_context );
1027 }
1028 
1036  ISR_lock_Control *lock,
1037  ISR_lock_Context *lock_context
1038 )
1039 {
1040  _Thread_Lock_release_critical( lock, lock_context );
1041  _ISR_lock_ISR_enable( lock_context );
1042 }
1043 
1055  Thread_Control *the_thread,
1056  ISR_lock_Context *lock_context
1057 )
1058 {
1060 #if defined(RTEMS_SMP)
1061  &the_thread->Lock.Default,
1062 #else
1063  NULL,
1064 #endif
1065  lock_context
1066  );
1067 }
1068 
1077  Thread_Control *the_thread,
1078  ISR_lock_Context *lock_context
1079 )
1080 {
1081  _Thread_Lock_release_default_critical( the_thread, lock_context );
1082  _ISR_lock_ISR_enable( lock_context );
1083 }
1084 
1094  Thread_Control *the_thread,
1095  ISR_lock_Context *lock_context
1096 )
1097 {
1098 #if defined(RTEMS_SMP)
1099  ISR_lock_Control *lock;
1100 
1101  while ( true ) {
1102  uint32_t my_generation;
1103 
1104  _ISR_lock_ISR_disable( lock_context );
1105  my_generation = the_thread->Lock.generation;
1106 
1107  /*
1108  * Ensure that we read the initial lock generation before we obtain our
1109  * current lock.
1110  */
1111  _Atomic_Fence( ATOMIC_ORDER_ACQUIRE );
1112 
1113  lock = the_thread->Lock.current;
1114  _ISR_lock_Acquire( lock, lock_context );
1115 
1116  /*
1117  * Ensure that we read the second lock generation after we obtained our
1118  * current lock.
1119  */
1120  _Atomic_Fence( ATOMIC_ORDER_ACQUIRE );
1121 
1122  if ( the_thread->Lock.generation == my_generation ) {
1123  break;
1124  }
1125 
1126  _Thread_Lock_release( lock, lock_context );
1127  }
1128 
1129  return lock;
1130 #else
1131  _ISR_Disable( lock_context->isr_level );
1132 
1133  return NULL;
1134 #endif
1135 }
1136 
1137 #if defined(RTEMS_SMP)
1138 /*
1139  * Internal function, use _Thread_Lock_set() or _Thread_Lock_restore_default()
1140  * instead.
1141  */
1142 RTEMS_INLINE_ROUTINE void _Thread_Lock_set_unprotected(
1143  Thread_Control *the_thread,
1144  ISR_lock_Control *new_lock
1145 )
1146 {
1147  the_thread->Lock.current = new_lock;
1148 
1149  /*
1150  * Ensure that the new lock is visible before we update the generation
1151  * number. Otherwise someone would be able to read an up to date generation
1152  * number and an old lock.
1153  */
1154  _Atomic_Fence( ATOMIC_ORDER_RELEASE );
1155 
1156  /*
1157  * Since we set a new lock right before, this increment is not protected by a
1158  * lock and thus must be an atomic operation.
1159  */
1160  _Atomic_Fetch_add_uint(
1161  &the_thread->Lock.generation,
1162  1,
1163  ATOMIC_ORDER_RELAXED
1164  );
1165 }
1166 #endif
1167 
1177 #if defined(RTEMS_SMP)
1179  Thread_Control *the_thread,
1180  ISR_lock_Control *new_lock
1181 )
1182 {
1183  ISR_lock_Context lock_context;
1184 
1185  _Thread_Lock_acquire_default_critical( the_thread, &lock_context );
1186  _Assert( the_thread->Lock.current == &the_thread->Lock.Default );
1187  _Thread_Lock_set_unprotected( the_thread, new_lock );
1188  _Thread_Lock_release_default_critical( the_thread, &lock_context );
1189 }
1190 #else
1191 #define _Thread_Lock_set( the_thread, new_lock ) \
1192  do { } while ( 0 )
1193 #endif
1194 
1202 #if defined(RTEMS_SMP)
1204  Thread_Control *the_thread
1205 )
1206 {
1207  _Atomic_Fence( ATOMIC_ORDER_RELEASE );
1208 
1209  _Thread_Lock_set_unprotected( the_thread, &the_thread->Lock.Default );
1210 }
1211 #else
1212 #define _Thread_Lock_restore_default( the_thread ) \
1213  do { } while ( 0 )
1214 #endif
1215 
1219 #define THREAD_WAIT_FLAGS_INITIAL 0x0U
1220 
1224 #define THREAD_WAIT_STATE_MASK 0xffU
1225 
1233 #define THREAD_WAIT_STATE_INTEND_TO_BLOCK 0x1U
1234 
1238 #define THREAD_WAIT_STATE_BLOCKED 0x2U
1239 
1245 #define THREAD_WAIT_STATE_READY_AGAIN 0x4U
1246 
1250 #define THREAD_WAIT_CLASS_MASK 0xff00U
1251 
1255 #define THREAD_WAIT_CLASS_EVENT 0x100U
1256 
1260 #define THREAD_WAIT_CLASS_SYSTEM_EVENT 0x200U
1261 
1265 #define THREAD_WAIT_CLASS_OBJECT 0x400U
1266 
1267 RTEMS_INLINE_ROUTINE void _Thread_Wait_flags_set(
1268  Thread_Control *the_thread,
1269  Thread_Wait_flags flags
1270 )
1271 {
1272 #if defined(RTEMS_SMP)
1273  _Atomic_Store_uint( &the_thread->Wait.flags, flags, ATOMIC_ORDER_RELAXED );
1274 #else
1275  the_thread->Wait.flags = flags;
1276 #endif
1277 }
1278 
1279 RTEMS_INLINE_ROUTINE Thread_Wait_flags _Thread_Wait_flags_get(
1280  const Thread_Control *the_thread
1281 )
1282 {
1283 #if defined(RTEMS_SMP)
1284  return _Atomic_Load_uint( &the_thread->Wait.flags, ATOMIC_ORDER_RELAXED );
1285 #else
1286  return the_thread->Wait.flags;
1287 #endif
1288 }
1289 
1305  Thread_Control *the_thread,
1306  Thread_Wait_flags expected_flags,
1307  Thread_Wait_flags desired_flags
1308 )
1309 {
1310 #if defined(RTEMS_SMP)
1311  return _Atomic_Compare_exchange_uint(
1312  &the_thread->Wait.flags,
1313  &expected_flags,
1314  desired_flags,
1315  ATOMIC_ORDER_RELAXED,
1316  ATOMIC_ORDER_RELAXED
1317  );
1318 #else
1319  bool success = the_thread->Wait.flags == expected_flags;
1320 
1321  if ( success ) {
1322  the_thread->Wait.flags = desired_flags;
1323  }
1324 
1325  return success;
1326 #endif
1327 }
1328 
1335  Thread_Control *the_thread,
1336  Thread_Wait_flags expected_flags,
1337  Thread_Wait_flags desired_flags
1338 )
1339 {
1340  bool success;
1341 #if !defined(RTEMS_SMP)
1342  ISR_Level level;
1343 
1344  _ISR_Disable_without_giant( level );
1345 #endif
1346 
1348  the_thread,
1349  expected_flags,
1350  desired_flags
1351  );
1352 
1353 #if !defined(RTEMS_SMP)
1354  _ISR_Enable_without_giant( level );
1355 #endif
1356 
1357  return success;
1358 }
1359 
1371  Thread_Control *the_thread,
1372  Thread_queue_Control *new_queue
1373 )
1374 {
1375  the_thread->Wait.queue = new_queue;
1376 }
1377 
1389  Thread_Control *the_thread,
1390  const Thread_queue_Operations *new_operations
1391 )
1392 {
1393  the_thread->Wait.operations = new_operations;
1394 }
1395 
1406  Thread_Control *the_thread
1407 )
1408 {
1409  the_thread->Wait.operations = &_Thread_queue_Operations_default;
1410 }
1411 
1419  Thread_Control *the_thread,
1420  uint32_t timeout_code
1421 )
1422 {
1423  the_thread->Wait.timeout_code = timeout_code;
1424 }
1425 
1432 void _Thread_Timeout( Objects_Id id, void *arg );
1433 
1434 RTEMS_INLINE_ROUTINE void _Thread_Debug_set_real_processor(
1435  Thread_Control *the_thread,
1436  Per_CPU_Control *cpu
1437 )
1438 {
1439 #if defined(RTEMS_SMP) && defined(RTEMS_DEBUG)
1440  the_thread->Scheduler.debug_real_cpu = cpu;
1441 #else
1442  (void) the_thread;
1443  (void) cpu;
1444 #endif
1445 }
1446 
1447 #if !defined(__DYNAMIC_REENT__)
1448 
1453 {
1454  return _Thread_libc_reent;
1455 }
1456 
1462  struct _reent **libc_reent
1463 )
1464 {
1465  _Thread_libc_reent = libc_reent;
1466 }
1467 #endif
1468 
1471 #ifdef __cplusplus
1472 }
1473 #endif
1474 
1475 #if defined(RTEMS_MULTIPROCESSING)
1476 #include <rtems/score/threadmp.h>
1477 #endif
1478 
1479 #endif
1480 /* end of include file */
#define _Thread_Lock_set(the_thread, new_lock)
Sets a new thread lock.
Definition: threadimpl.h:1191
void(* Thread_Action_handler)(Thread_Control *thread, Thread_Action *action, struct Per_CPU_Control *cpu, ISR_Level level)
Thread action handler.
Definition: thread.h:456
Constants and Prototypes Related to the Internal Error Handler.
Thread_Control * _Thread_Get(Objects_Id id, Objects_Locations *location)
Maps thread Id to a TCB pointer.
Definition: threadget.c:56
RTEMS_INLINE_ROUTINE Priority_Control _Thread_Priority_highest(Priority_Control left, Priority_Control right)
Returns the highest priority of the left and right thread priorities in the intuitive sense of priori...
Definition: threadimpl.h:351
RTEMS_INLINE_ROUTINE void _Thread_Lock_release_critical(ISR_lock_Control *lock, ISR_lock_Context *lock_context)
Releases the thread lock inside a critical section (interrupts disabled).
Definition: threadimpl.h:1021
void _Thread_Stack_Free(Thread_Control *the_thread)
Deallocate thread stack.
Definition: threadstackfree.c:24
const Thread_queue_Operations * operations
The current thread queue operations.
Definition: thread.h:351
RTEMS_INLINE_ROUTINE bool _Thread_Is_proxy_blocking(uint32_t code)
Is proxy blocking.
Definition: threadimpl.h:713
Scheduler control.
Definition: scheduler.h:192
Objects_Control * _Objects_Allocate_unprotected(Objects_Information *information)
Allocates an object without locking the allocator mutex.
Definition: objectallocate.c:39
RTEMS_INLINE_ROUTINE void _Thread_Restart_self(Thread_Control *executing)
This routine resets the current context of the calling thread to that of its initial state...
Definition: threadimpl.h:600
RTEMS_INLINE_ROUTINE void _Thread_Unblock(Thread_Control *the_thread)
This routine clears any blocking state for the_thread.
Definition: threadimpl.h:588
#define THREAD_STATUS_PROXY_BLOCKING
The following structure contains the information necessary to manage a thread which it is waiting for...
Definition: threadimpl.h:50
uint32_t timeout_code
Code to set the timeout return code in _Thread_Timeout().
Definition: thread.h:322
Thread_queue_Control * queue
The current thread queue.
Definition: thread.h:332
#define _ISR_lock_ISR_disable_and_acquire(_lock, _context)
Acquires an ISR lock.
Definition: isrlock.h:205
Thread_Control * _Thread_Get_interrupt_disable(Objects_Id id, Objects_Locations *location, ISR_lock_Context *lock_context)
Gets a thread by its identifier.
Definition: threadget.c:78
struct Thread_Control * heir
This is the heir thread for this processor.
Definition: percpu.h:292
void _Thread_Handler(void)
Wrapper function for all threads.
Definition: threadhandler.c:27
void * _Thread_Global_construction(void)
Executes the global constructors and then restarts itself as the first initialization thread...
Definition: threadglobalconstruction.c:49
#define _ISR_lock_Acquire(_lock, _context)
Acquires an ISR lock inside an ISR disabled section.
Definition: isrlock.h:257
Data Related to the Management of Processor Interrupt Levels.
#define RTEMS_INLINE_ROUTINE
The following (in conjunction with compiler arguments) are used to choose between the use of static i...
Definition: basedefs.h:135
RTEMS_INLINE_ROUTINE bool _Thread_Is_executing(const Thread_Control *the_thread)
This function returns true if the_thread is the currently executing thread, and false otherwise...
Definition: threadimpl.h:517
#define _Context_Save_fp(_fp)
Save floating point context area.
Definition: context.h:162
RTEMS_INLINE_ROUTINE void _Thread_Lock_release(ISR_lock_Control *lock, ISR_lock_Context *lock_context)
Releases the thread lock.
Definition: threadimpl.h:1035
#define STATES_BLOCKED
This macro corresponds to a task waiting which is blocked.
Definition: statesimpl.h:109
bool(* Thread_Change_priority_filter)(Thread_Control *the_thread, Priority_Control *new_priority, void *arg)
Filters a thread priority change.
Definition: threadimpl.h:372
RTEMS_INLINE_ROUTINE void _Thread_Lock_acquire_default_critical(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Acquires the default thread lock inside a critical section (interrupts disabled). ...
Definition: threadimpl.h:985
void _Thread_Close(Thread_Control *the_thread, Thread_Control *executing)
Closes the thread.
Definition: threadrestart.c:311
void _Thread_Create_idle(void)
Create idle thread.
Definition: threadcreateidle.c:72
RTEMS_INLINE_ROUTINE struct _reent ** _Thread_Get_libc_reent(void)
This routine returns the C library re-enterant pointer.
Definition: threadimpl.h:1452
This is the structure used to manage sets of tasks which are blocked waiting to acquire a resource...
Definition: threadq.h:171
RTEMS_INLINE_ROUTINE ISR_lock_Control * _Thread_Lock_acquire(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Acquires the thread lock.
Definition: threadimpl.h:1093
#define _Context_Restore_fp(_fp)
Restore floating point context area.
Definition: context.h:151
void _Thread_Handler_initialization(void)
Initialize thread handler.
Definition: thread.c:43
void _Thread_Delay_ended(Objects_Id id, void *ignored)
Ended the delay of a thread.
#define _ISR_Get_level()
Return current interrupt level.
Definition: isrlevel.h:120
void _Thread_Raise_priority(Thread_Control *the_thread, Priority_Control new_priority)
Raises the priority of a thread.
Definition: threadchangepriority.c:99
RTEMS_INLINE_ROUTINE void _Chain_Initialize_empty(Chain_Control *the_chain)
Initialize this chain as empty.
Definition: chainimpl.h:613
void _Thread_Start_multitasking(void)
Start thread multitasking.
Definition: threadstartmultitasking.c:23
ISR lock control.
Definition: isrlock.h:56
Thread queue operations.
Definition: threadq.h:118
Constants and Structures Related with the Thread Control Block.
SCORE_EXTERN struct _reent ** _Thread_libc_reent
The C library re-enter-rant global pointer.
Definition: threadimpl.h:78
void _Thread_Enable_dispatch(void)
Enables thread dispatching and releases the Giant lock.
Thread_CPU_usage_t cpu_time_used
This field is the amount of CPU time consumed by this thread since it was created.
Definition: thread.h:777
uint32_t Priority_Control
The following type defines the control block used to manage thread priorities.
Definition: priority.h:56
Thread_Scheduler_control Scheduler
Scheduler related control.
Definition: thread.h:756
States_Control _Thread_Set_state(Thread_Control *the_thread, States_Control state)
Sets the specified thread state.
Definition: threadsetstate.c:28
RTEMS_INLINE_ROUTINE void _Thread_Disable_dispatch(void)
Disables thread dispatching and acquires the Giant lock.
Definition: threaddispatch.h:332
RTEMS_INLINE_ROUTINE bool _Thread_Wait_flags_try_change(Thread_Control *the_thread, Thread_Wait_flags expected_flags, Thread_Wait_flags desired_flags)
Tries to change the thread wait flags.
Definition: threadimpl.h:1334
#define rtems_configuration_get_maximum_processors()
Returns the configured maximum count of processors.
Definition: config.h:381
#define _ISR_lock_ISR_disable(_context)
Disables interrupts and saves the previous interrupt state in the ISR lock context.
Definition: isrlock.h:337
RTEMS_INLINE_ROUTINE void _Thread_Wait_restore_default_operations(Thread_Control *the_thread)
Restores the default thread queue operations.
Definition: threadimpl.h:1405
RTEMS_INLINE_ROUTINE void _Thread_Lock_acquire_default(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Acquires the default thread lock.
Definition: threadimpl.h:1003
void(* Thread_CPU_budget_algorithm_callout)(Thread_Control *)
This defines thes the entry point for the thread specific timeslice budget management algorithm...
Definition: thread.h:173
Objects_Control Object
This field is the object management structure for each thread.
Definition: thread.h:673
uint32_t ISR_Level
The following type defines the control block used to manage the interrupt level portion of the status...
Definition: isrlevel.h:42
RTEMS_INLINE_ROUTINE bool _Thread_Is_heir(const Thread_Control *the_thread)
This function returns true if the_thread is the heir thread, and false otherwise. ...
Definition: threadimpl.h:575
RTEMS_INLINE_ROUTINE void _Thread_Wait_set_operations(Thread_Control *the_thread, const Thread_queue_Operations *new_operations)
Sets the thread queue operations.
Definition: threadimpl.h:1388
Control block to manage thread actions.
Definition: thread.h:490
This structure defines the Thread Control Block (TCB).
Definition: thread.h:671
#define _ISR_lock_ISR_enable(_context)
Restores the saved interrupt state of the ISR lock context.
Definition: isrlock.h:358
Per CPU Core Structure.
Definition: percpu.h:233
void _Thread_Load_environment(Thread_Control *the_thread)
Initializes enviroment for a thread.
Definition: threadloadenv.c:24
#define _Thread_Lock_restore_default(the_thread)
Restores the default thread lock.
Definition: threadimpl.h:1212
#define _ISR_lock_Release(_lock, _context)
Releases an ISR lock inside an ISR disabled section.
Definition: isrlock.h:279
void _Thread_Set_priority(Thread_Control *the_thread, Priority_Control new_priority, Priority_Control *old_priority, bool prepend_it)
Sets the priority of a thread.
Definition: threadsetpriority.c:45
Thread action.
Definition: thread.h:480
RTEMS_INLINE_ROUTINE bool _Thread_Is_allocated_fp(const Thread_Control *the_thread)
This function returns true if the floating point context of the_thread is currently loaded in the flo...
Definition: threadimpl.h:626
Thread_Life_state
Thread life states.
Definition: thread.h:501
Thread_Start_types
The following defines the ways in which the entry point for a thread can be invoked.
Definition: thread.h:119
uint32_t resource_count
This field is the number of mutexes currently held by this thread.
Definition: thread.h:713
Context_Control_fp * fp_context
This field points to the floating point context for this thread.
Definition: thread.h:792
Constants and Structures Associated with the Manipulation of Objects.
RTEMS_INLINE_ROUTINE time_t _Timestamp_Add_to(Timestamp_Control *_time, const Timestamp_Control *_add)
Adds two timestamps.
Definition: timestamp.h:181
RTEMS_INLINE_ROUTINE void _Thread_Wait_set_queue(Thread_Control *the_thread, Thread_queue_Control *new_queue)
Sets the thread queue.
Definition: threadimpl.h:1370
#define STATES_ALL_SET
All state bits set to one (provided for _Thread_Ready())
Definition: statesimpl.h:119
The following defines the structure for the information used to manage each class of objects...
Definition: objectimpl.h:136
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:83
RTEMS_INLINE_ROUTINE bool _Thread_Owns_resources(const Thread_Control *the_thread)
Returns true if the thread owns resources, and false otherwise.
Definition: threadimpl.h:938
Chain Handler API.
RTEMS_INLINE_ROUTINE void _Thread_Lock_release_default_critical(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Releases the default thread lock inside a critical section (interrupts disabled). ...
Definition: threadimpl.h:1054
RTEMS_INLINE_ROUTINE bool _Thread_Priority_less_than(Priority_Control left, Priority_Control right)
Returns true if the left thread priority is less than the right thread priority in the intuitive sens...
Definition: threadimpl.h:339
Time of Day Handler API.
Inlined Routines Associated with Thread State Information.
volatile bool dispatch_necessary
This is set to true when this processor needs to run the dispatcher.
Definition: percpu.h:308
bool _Thread_Initialize(Objects_Information *information, Thread_Control *the_thread, const struct Scheduler_Control *scheduler, void *stack_area, size_t stack_size, bool is_fp, Priority_Control priority, bool is_preemptible, Thread_CPU_budget_algorithms budget_algorithm, Thread_CPU_budget_algorithm_callout budget_callout, uint32_t isr_level, Objects_Name name)
Initialize thread.
struct bintime Timestamp_Control
Define the Timestamp control type.
Definition: timestamp.h:55
void _Thread_Kill_zombies(void)
Kills all zombie threads in the system.
Definition: threadrestart.c:149
Definition: inftrees.h:25
SCORE_EXTERN void * rtems_ada_self
Self for the GNU Ada Run-Time.
Definition: threadimpl.h:55
RTEMS_INLINE_ROUTINE void _Timestamp_Subtract(const Timestamp_Control *_start, const Timestamp_Control *_end, Timestamp_Control *_result)
Subtracts two timestamps.
Definition: timestamp.h:206
uint32_t States_Control
The following type defines the control block used to manage a thread&#39;s state.
Definition: states.h:41
struct Thread_Control * executing
This is the thread executing on this processor.
Definition: percpu.h:278
Context_Control Registers
This field contains the context of this thread.
Definition: thread.h:787
#define RTEMS_COMPILER_NO_RETURN_ATTRIBUTE
The following macro is a compiler specific way to indicate that the method will NOT return to the cal...
Definition: basedefs.h:162
RTEMS_INLINE_ROUTINE bool _Thread_Get_time_of_last_context_switch(Thread_Control *the_thread, Timestamp_Control *time_of_context_switch)
Returns true and sets time_of_context_switch to the time of the last context switch when the thread i...
Definition: threadimpl.h:545
Objects_Locations
This enumerated type lists the locations which may be returned by _Objects_Get.
Definition: objectimpl.h:117
CPU_Uint32ptr Thread_Entry_numeric_type
Type of the numeric argument of a thread entry function with at least one numeric argument...
Definition: thread.h:110
System State Handler API.
size_t _Thread_Stack_Allocate(Thread_Control *the_thread, size_t stack_size)
Allocate the requested stack space for the thread.
Definition: threadstackallocate.c:26
void _Thread_Change_priority(Thread_Control *the_thread, Priority_Control new_priority, void *arg, Thread_Change_priority_filter filter, bool prepend_it)
Changes the priority of a thread if allowed by the filter function.
Definition: threadchangepriority.c:25
Thread_Wait_flags flags
This field contains several flags used to control the wait class and state of a thread in case fine-g...
Definition: thread.h:341
RTEMS_INLINE_ROUTINE void _Thread_Deallocate_fp(void)
This routine is invoked when the currently loaded floating point context is now longer associated wit...
Definition: threadimpl.h:681
RTEMS_INLINE_ROUTINE bool _Thread_Wait_flags_try_change_critical(Thread_Control *the_thread, Thread_Wait_flags expected_flags, Thread_Wait_flags desired_flags)
Tries to change the thread wait flags inside a critical section (interrupts disabled).
Definition: threadimpl.h:1304
void _Thread_Restore_priority(Thread_Control *the_thread)
Sets the current to the real priority of a thread.
Definition: threadchangepriority.c:126
RTEMS_INLINE_ROUTINE void _Chain_Set_off_chain(Chain_Node *node)
Set off chain.
Definition: chainimpl.h:230
Timestamp_Control time_of_last_context_switch
This is the time of the last context switch on this CPU.
Definition: percpu.h:311
States_Control _Thread_Clear_state(Thread_Control *the_thread, States_Control state)
Clears the specified thread state.
Definition: threadclearstate.c:25
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
void _Thread_Timeout(Objects_Id id, void *arg)
General purpose thread wait timeout.
Definition: threadtimeout.c:36
Inlined Routines in the Object Handler.
RTEMS_INLINE_ROUTINE bool _Thread_Is_context_switch_necessary(void)
This function returns true if dispatching is disabled, and false otherwise.
Definition: threadimpl.h:692
Multiprocessing Portion of the Thread Package.
RTEMS_INLINE_ROUTINE Thread_Control * _Thread_Lock_acquire_default_for_executing(ISR_lock_Context *lock_context)
Acquires the default thread lock and returns the executing thread.
Definition: threadimpl.h:962
uint32_t Objects_Id
The following type defines the control block used to manage object IDs.
Definition: object.h:122
The following type defines the control block used to manage object names.
Definition: object.h:68
#define SCORE_EXTERN
The following ensures that all data is declared in the space of the initialization routine for either...
Definition: basedefs.h:81
RTEMS_INLINE_ROUTINE void _Thread_Ready(Thread_Control *the_thread)
Clears all thread states.
Definition: threadimpl.h:274
RTEMS_INLINE_ROUTINE void _Thread_Lock_release_default(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Releases the default thread lock.
Definition: threadimpl.h:1076
RTEMS_INLINE_ROUTINE void _Chain_Append_if_is_off_chain_unprotected(Chain_Control *the_chain, Chain_Node *the_node)
Append a node on the end of a chain if the node is in the off chain state (unprotected).
Definition: chainimpl.h:766
Thread_Wait_information Wait
This field is the blocking information for this thread.
Definition: thread.h:715
SCORE_EXTERN Thread_Control * _Thread_Allocated_fp
The following points to the thread whose floating point context is currently loaded.
Definition: threadimpl.h:68
#define _ISR_Disable(_level)
Disables interrupts on this processor.
Definition: isrlevel.h:58
SCORE_EXTERN Objects_Information _Thread_Internal_information
The following defines the information control block used to manage this class of objects.
Definition: threadimpl.h:61
RTEMS_INLINE_ROUTINE Thread_Control * _Thread_Get_heir_and_make_it_executing(Per_CPU_Control *cpu_self)
Gets the heir of the processor and makes it executing.
Definition: threadimpl.h:752
RTEMS_INLINE_ROUTINE void _Thread_Set_libc_reent(struct _reent **libc_reent)
This routine set the C library re-enterant pointer.
Definition: threadimpl.h:1461
RTEMS_INLINE_ROUTINE void _Thread_Wait_set_timeout_code(Thread_Control *the_thread, uint32_t timeout_code)
Sets the thread wait timeout code.
Definition: threadimpl.h:1418
RTEMS_INLINE_ROUTINE bool _Thread_Is_null(const Thread_Control *the_thread)
This function returns true if the_thread is NULL and false otherwise.
Definition: threadimpl.h:701
Thread_CPU_budget_algorithms
The following lists the algorithms used to manage the thread cpu budget.
Definition: thread.h:159
bool _Thread_Start(Thread_Control *the_thread, Thread_Start_types the_prototype, void *entry_point, void *pointer_argument, Thread_Entry_numeric_type numeric_argument, Per_CPU_Control *cpu)
Initializes thread and executes it.
Definition: threadstart.c:27
unsigned int Thread_Wait_flags
This type is able to contain several flags used to control the wait class and state of a thread...
Definition: thread.h:277
Objects_Id id
This is the object&#39;s ID.
Definition: object.h:236