source: rtems/cpukit/score/src/threadqenqueuepriority.c @ 64adc13

4.115
Last change on this file since 64adc13 was 64adc13, checked in by Joel Sherrill <joel.sherrill@…>, on 07/24/11 at 23:55:15

2011-07-24 Joel Sherrill <joel.sherrill@…>

  • ftpd/ftpd.c, libcsupport/src/geteuid.c, libcsupport/src/getgroups.c, libcsupport/src/getpgrp.c, libcsupport/src/getpid.c, libcsupport/src/getppid.c, libcsupport/src/setpgid.c, libcsupport/src/setsid.c, libcsupport/src/utsname.c, libmisc/stackchk/check.c, posix/include/rtems/posix/mqueue.h, posix/inline/rtems/posix/cond.inl, posix/inline/rtems/posix/mqueue.inl, posix/inline/rtems/posix/mutex.inl, posix/inline/rtems/posix/pthread.inl, posix/inline/rtems/posix/semaphore.inl, posix/inline/rtems/posix/timer.inl, posix/src/alarm.c, posix/src/barrierattrdestroy.c, posix/src/barrierattrgetpshared.c, posix/src/barrierattrinit.c, posix/src/barrierattrsetpshared.c, posix/src/cleanuppop.c, posix/src/cleanuppush.c, posix/src/clockgetcpuclockid.c, posix/src/clockgetenableattr.c, posix/src/clockgetres.c, posix/src/clockgettime.c, posix/src/clocksetenableattr.c, posix/src/clocksettime.c, posix/src/cond.c, posix/src/condattrdestroy.c, posix/src/condattrgetpshared.c, posix/src/condattrinit.c, posix/src/condattrsetpshared.c, posix/src/condbroadcast.c, posix/src/conddefaultattributes.c, posix/src/conddestroy.c, posix/src/condinit.c, posix/src/condsignal.c, posix/src/condsignalsupp.c, posix/src/condtimedwait.c, posix/src/condwait.c, posix/src/condwaitsupp.c, posix/src/keygetspecific.c, posix/src/keyrundestructors.c, posix/src/keysetspecific.c, posix/src/mprotect.c, posix/src/mqueue.c, posix/src/mqueuecreatesupp.c, posix/src/mqueuedeletesupp.c, posix/src/mqueuegetattr.c, posix/src/mqueuenotify.c, posix/src/mqueuereceive.c, posix/src/mqueuesend.c, posix/src/mqueuesendsupp.c, posix/src/mqueuesetattr.c, posix/src/mqueuetimedreceive.c, posix/src/mqueuetimedsend.c, posix/src/mqueuetranslatereturncode.c, posix/src/mqueueunlink.c, posix/src/mutex.c, posix/src/mutexattrdestroy.c, posix/src/mutexattrgetprioceiling.c, posix/src/mutexattrgetprotocol.c, posix/src/mutexattrgetpshared.c, posix/src/mutexattrinit.c, posix/src/mutexattrsetprioceiling.c, posix/src/mutexattrsetprotocol.c, posix/src/mutexattrsetpshared.c, posix/src/mutexdestroy.c, posix/src/mutexgetprioceiling.c, posix/src/mutexinit.c, posix/src/mutexlock.c, posix/src/mutexlocksupp.c, posix/src/mutexsetprioceiling.c, posix/src/mutextimedlock.c, posix/src/mutextrylock.c, posix/src/mutexunlock.c, posix/src/nanosleep.c, posix/src/psignal.c, posix/src/psignalchecksignal.c, posix/src/psignalclearprocesssignals.c, posix/src/psignalclearsignals.c, posix/src/psignalsetprocesssignals.c, posix/src/psignalunblockthread.c, posix/src/pthreadinitthreads.c, posix/src/rwlockattrdestroy.c, posix/src/rwlockattrgetpshared.c, posix/src/rwlockattrinit.c, posix/src/rwlockattrsetpshared.c, posix/src/semaphore.c, posix/src/semaphoredeletesupp.c, posix/src/semaphorenametoid.c, posix/src/semaphorewaitsupp.c, posix/src/semclose.c, posix/src/semdestroy.c, posix/src/semgetvalue.c, posix/src/seminit.c, posix/src/semopen.c, posix/src/sempost.c, posix/src/semtimedwait.c, posix/src/semtrywait.c, posix/src/semunlink.c, posix/src/semwait.c, posix/src/sysconf.c, posix/src/testcancel.c, posix/src/ualarm.c, rtems/src/clockgetuptime.c, rtems/src/clockset.c, rtems/src/clocksetnsecshandler.c, rtems/src/clocktick.c, rtems/src/clocktodtoseconds.c, rtems/src/clocktodvalidate.c, rtems/src/dpmem.c, rtems/src/dpmemcreate.c, rtems/src/dpmemdelete.c, rtems/src/dpmemexternal2internal.c, rtems/src/dpmemident.c, rtems/src/dpmeminternal2external.c, rtems/src/event.c, rtems/src/eventmp.c, rtems/src/eventreceive.c, rtems/src/eventseize.c, rtems/src/eventsend.c, rtems/src/eventsurrender.c, rtems/src/eventtimeout.c, rtems/src/mp.c, rtems/src/msg.c, rtems/src/msgmp.c, rtems/src/msgqallocate.c, rtems/src/msgqbroadcast.c, rtems/src/msgqcreate.c, rtems/src/msgqdelete.c, rtems/src/msgqflush.c, rtems/src/msgqgetnumberpending.c, rtems/src/msgqident.c, rtems/src/msgqreceive.c, rtems/src/msgqtranslatereturncode.c, rtems/src/msgqurgent.c, rtems/src/part.c, rtems/src/partcreate.c, rtems/src/partdelete.c, rtems/src/partgetbuffer.c, rtems/src/partident.c, rtems/src/partmp.c, rtems/src/partreturnbuffer.c, rtems/src/ratemon.c, rtems/src/ratemoncancel.c, rtems/src/ratemoncreate.c, rtems/src/ratemondelete.c, rtems/src/ratemongetstatistics.c, rtems/src/ratemongetstatus.c, rtems/src/ratemonident.c, rtems/src/ratemonperiod.c, rtems/src/ratemonresetstatistics.c, rtems/src/ratemontimeout.c, rtems/src/region.c, rtems/src/regioncreate.c, rtems/src/regiondelete.c, rtems/src/regionextend.c, rtems/src/regiongetfreeinfo.c, rtems/src/regiongetinfo.c, rtems/src/regiongetsegment.c, rtems/src/regiongetsegmentsize.c, rtems/src/regionident.c, rtems/src/regionmp.c, rtems/src/regionprocessqueue.c, rtems/src/regionresizesegment.c, rtems/src/regionreturnsegment.c, rtems/src/rtemsobjectgetclassicname.c, rtems/src/rtemstimer.c, rtems/src/sem.c, rtems/src/semcreate.c, rtems/src/semdelete.c, rtems/src/semflush.c, rtems/src/semident.c, rtems/src/semmp.c, rtems/src/semobtain.c, rtems/src/semrelease.c, rtems/src/semtranslatereturncode.c, rtems/src/signal.c, rtems/src/signalcatch.c, rtems/src/signalmp.c, rtems/src/signalsend.c, rtems/src/taskcreate.c, rtems/src/taskdelete.c, rtems/src/taskgetnote.c, rtems/src/taskident.c, rtems/src/taskinitusers.c, rtems/src/taskissuspended.c, rtems/src/taskmp.c, rtems/src/taskrestart.c, rtems/src/taskresume.c, rtems/src/tasks.c, rtems/src/tasksetnote.c, rtems/src/tasksetpriority.c, rtems/src/taskstart.c, rtems/src/tasksuspend.c, rtems/src/taskwakeafter.c, rtems/src/taskwakewhen.c, rtems/src/timercancel.c, rtems/src/timercreate.c, rtems/src/timerdelete.c, rtems/src/timerfireafter.c, rtems/src/timerfirewhen.c, rtems/src/timergetinfo.c, rtems/src/timerident.c, rtems/src/timerreset.c, rtems/src/timerserverfireafter.c, rtems/src/timerserverfirewhen.c, sapi/src/debug.c, sapi/src/extension.c, sapi/src/posixapi.c, sapi/src/rtemsapi.c, score/src/apiext.c, score/src/chain.c, score/src/corebarrier.c, score/src/corebarrierrelease.c, score/src/corebarrierwait.c, score/src/coremsgbroadcast.c, score/src/coremsgclose.c, score/src/coremsgflush.c, score/src/coremsgflushsupp.c, score/src/coremsgflushwait.c, score/src/coremsginsert.c, score/src/coremsgseize.c, score/src/coremsgsubmit.c, score/src/coremutex.c, score/src/coremutexflush.c, score/src/coremutexseize.c, score/src/corerwlock.c, score/src/corerwlockobtainread.c, score/src/corerwlockobtainwrite.c, score/src/corerwlockrelease.c, score/src/coresem.c, score/src/coresemflush.c, score/src/coresemsurrender.c, score/src/corespinlock.c, score/src/corespinlockrelease.c, score/src/corespinlockwait.c, score/src/coretod.c, score/src/coretodset.c, score/src/coretodtickle.c, score/src/heap.c, score/src/interr.c, score/src/mpci.c, score/src/objectallocate.c, score/src/objectextendinformation.c, score/src/objectfree.c, score/src/objectget.c, score/src/objectgetisr.c, score/src/objectgetnext.c, score/src/objectgetnoprotection.c, score/src/objectinitializeinformation.c, score/src/objectmp.c, score/src/objectnametoid.c, score/src/objectnametoidstring.c, score/src/objectshrinkinformation.c, score/src/rbtree.c, score/src/threaddelayended.c, score/src/threadhandler.c, score/src/threadinitialize.c, score/src/threadloadenv.c, score/src/threadmp.c, score/src/threadq.c, score/src/threadqdequeue.c, score/src/threadqdequeuefifo.c, score/src/threadqdequeuepriority.c, score/src/threadqenqueue.c, score/src/threadqenqueuefifo.c, score/src/threadqenqueuepriority.c, score/src/threadqextract.c, score/src/threadqextractfifo.c, score/src/threadqextractpriority.c, score/src/threadqextractwithproxy.c, score/src/threadqfirst.c, score/src/threadqfirstfifo.c, score/src/threadqfirstpriority.c, score/src/threadqflush.c, score/src/threadqrequeue.c, score/src/threadstackallocate.c, score/src/threadstartmultitasking.c, score/src/watchdog.c, score/src/watchdogadjust.c, score/src/watchdoginsert.c, score/src/watchdogremove.c, score/src/watchdogtickle.c: Remove /*PAGE markers which were interpreted by a long dead print script.
  • Property mode set to 100644
File size: 5.9 KB
Line 
1/*
2 *  Thread Queue Handler - Enqueue By Priority
3 *
4 *  COPYRIGHT (c) 1989-2009.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <rtems/system.h>
19#include <rtems/score/chain.h>
20#include <rtems/score/isr.h>
21#include <rtems/score/object.h>
22#include <rtems/score/states.h>
23#include <rtems/score/thread.h>
24#include <rtems/score/threadq.h>
25#include <rtems/score/tqdata.h>
26
27/*
28 *  Support the user forcing the unrolling to be disabled.
29 */
30#if __RTEMS_DO_NOT_UNROLL_THREADQ_ENQUEUE_PRIORITY__
31  #undef CPU_UNROLL_ENQUEUE_PRIORITY
32  #define CPU_UNROLL_ENQUEUE_PRIORITY FALSE
33#endif
34
35/*
36 *  _Thread_queue_Enqueue_priority
37 *
38 *  This routine places a blocked thread on a priority thread queue.
39 *
40 *  Input parameters:
41 *    the_thread_queue - pointer to threadq
42 *    thread           - thread to insert
43 *
44 *  Output parameters: NONE
45 *
46 *  INTERRUPT LATENCY:
47 *    forward less than
48 *    forward equal
49 */
50
51Thread_blocking_operation_States _Thread_queue_Enqueue_priority (
52  Thread_queue_Control *the_thread_queue,
53  Thread_Control       *the_thread,
54  ISR_Level            *level_p
55)
56{
57  Priority_Control     search_priority;
58  Thread_Control      *search_thread;
59  ISR_Level            level;
60  Chain_Control       *header;
61  uint32_t             header_index;
62  Chain_Node          *the_node;
63  Chain_Node          *next_node;
64  Chain_Node          *previous_node;
65  Chain_Node          *search_node;
66  Priority_Control     priority;
67  States_Control       block_state;
68
69  _Chain_Initialize_empty( &the_thread->Wait.Block2n );
70
71  priority     = the_thread->current_priority;
72  header_index = _Thread_queue_Header_number( priority );
73  header       = &the_thread_queue->Queues.Priority[ header_index ];
74  block_state  = the_thread_queue->state;
75
76  if ( _Thread_queue_Is_reverse_search( priority ) )
77    goto restart_reverse_search;
78
79restart_forward_search:
80  search_priority = PRIORITY_MINIMUM - 1;
81  _ISR_Disable( level );
82  search_thread = (Thread_Control *) _Chain_First( header );
83  while ( !_Chain_Is_tail( header, (Chain_Node *)search_thread ) ) {
84    search_priority = search_thread->current_priority;
85    if ( priority <= search_priority )
86      break;
87
88#if ( CPU_UNROLL_ENQUEUE_PRIORITY == TRUE )
89    search_thread = (Thread_Control *) search_thread->Object.Node.next;
90    if ( _Chain_Is_tail( header, (Chain_Node *)search_thread ) )
91      break;
92    search_priority = search_thread->current_priority;
93    if ( priority <= search_priority )
94      break;
95#endif
96    _ISR_Flash( level );
97    if ( !_States_Are_set( search_thread->current_state, block_state) ) {
98      _ISR_Enable( level );
99      goto restart_forward_search;
100    }
101    search_thread =
102       (Thread_Control *)search_thread->Object.Node.next;
103  }
104
105  if ( the_thread_queue->sync_state !=
106       THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED )
107    goto synchronize;
108
109  the_thread_queue->sync_state = THREAD_BLOCKING_OPERATION_SYNCHRONIZED;
110
111  if ( priority == search_priority )
112    goto equal_priority;
113
114  search_node   = (Chain_Node *) search_thread;
115  previous_node = search_node->previous;
116  the_node      = (Chain_Node *) the_thread;
117
118  the_node->next         = search_node;
119  the_node->previous     = previous_node;
120  previous_node->next    = the_node;
121  search_node->previous  = the_node;
122  the_thread->Wait.queue = the_thread_queue;
123  _ISR_Enable( level );
124  return THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED;
125
126restart_reverse_search:
127  search_priority     = PRIORITY_MAXIMUM + 1;
128
129  _ISR_Disable( level );
130  search_thread = (Thread_Control *) _Chain_Last( header );
131  while ( !_Chain_Is_head( header, (Chain_Node *)search_thread ) ) {
132    search_priority = search_thread->current_priority;
133    if ( priority >= search_priority )
134      break;
135#if ( CPU_UNROLL_ENQUEUE_PRIORITY == TRUE )
136    search_thread = (Thread_Control *) search_thread->Object.Node.previous;
137    if ( _Chain_Is_head( header, (Chain_Node *)search_thread ) )
138      break;
139    search_priority = search_thread->current_priority;
140    if ( priority >= search_priority )
141      break;
142#endif
143    _ISR_Flash( level );
144    if ( !_States_Are_set( search_thread->current_state, block_state) ) {
145      _ISR_Enable( level );
146      goto restart_reverse_search;
147    }
148    search_thread = (Thread_Control *)
149                         search_thread->Object.Node.previous;
150  }
151
152  if ( the_thread_queue->sync_state !=
153       THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED )
154    goto synchronize;
155
156  the_thread_queue->sync_state = THREAD_BLOCKING_OPERATION_SYNCHRONIZED;
157
158  if ( priority == search_priority )
159    goto equal_priority;
160
161  search_node = (Chain_Node *) search_thread;
162  next_node   = search_node->next;
163  the_node    = (Chain_Node *) the_thread;
164
165  the_node->next          = next_node;
166  the_node->previous      = search_node;
167  search_node->next       = the_node;
168  next_node->previous    = the_node;
169  the_thread->Wait.queue = the_thread_queue;
170  _ISR_Enable( level );
171  return THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED;
172
173equal_priority:               /* add at end of priority group */
174  search_node   = _Chain_Tail( &search_thread->Wait.Block2n );
175  previous_node = search_node->previous;
176  the_node      = (Chain_Node *) the_thread;
177
178  the_node->next         = search_node;
179  the_node->previous     = previous_node;
180  previous_node->next    = the_node;
181  search_node->previous  = the_node;
182  the_thread->Wait.queue = the_thread_queue;
183  _ISR_Enable( level );
184  return THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED;
185
186synchronize:
187  /*
188   *  An interrupt completed the thread's blocking request.
189   *  For example, the blocking thread could have been given
190   *  the mutex by an ISR or timed out.
191   *
192   *  WARNING! Returning with interrupts disabled!
193   */
194  *level_p = level;
195  return the_thread_queue->sync_state;
196}
Note: See TracBrowser for help on using the repository browser.