OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [score/] [src/] [threadqdequeuepriority.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
2
 *  Thread Queue Handler
3
 *
4
 *
5
 *  COPYRIGHT (c) 1989-1999.
6
 *  On-Line Applications Research Corporation (OAR).
7
 *
8
 *  The license and distribution terms for this file may be
9
 *  found in the file LICENSE in this distribution or at
10
 *  http://www.OARcorp.com/rtems/license.html.
11
 *
12
 *  threadqdequeuepriority.c,v 1.2 1999/11/17 17:50:40 joel Exp
13
 */
14
 
15
#include <rtems/system.h>
16
#include <rtems/score/chain.h>
17
#include <rtems/score/isr.h>
18
#include <rtems/score/object.h>
19
#include <rtems/score/states.h>
20
#include <rtems/score/thread.h>
21
#include <rtems/score/threadq.h>
22
#include <rtems/score/tqdata.h>
23
 
24
/*PAGE
25
 *
26
 *  _Thread_queue_Dequeue_priority
27
 *
28
 *  This routine removes a thread from the specified PRIORITY based
29
 *  threadq, unblocks it, and cancels its timeout timer.
30
 *
31
 *  Input parameters:
32
 *    the_thread_queue - pointer to thread queue
33
 *
34
 *  Output parameters:
35
 *    returns - thread dequeued or NULL
36
 *
37
 *  INTERRUPT LATENCY:
38
 *    only case
39
 */
40
 
41
Thread_Control *_Thread_queue_Dequeue_priority(
42
  Thread_queue_Control *the_thread_queue
43
)
44
{
45
  unsigned32      index;
46
  ISR_Level       level;
47
  Thread_Control *the_thread = NULL;  /* just to remove warnings */
48
  Thread_Control *new_first_thread;
49
  Chain_Node     *new_first_node;
50
  Chain_Node     *new_second_node;
51
  Chain_Node     *last_node;
52
  Chain_Node     *next_node;
53
  Chain_Node     *previous_node;
54
 
55
  _ISR_Disable( level );
56
  for( index=0 ;
57
       index < TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS ;
58
       index++ ) {
59
    if ( !_Chain_Is_empty( &the_thread_queue->Queues.Priority[ index ] ) ) {
60
      the_thread = (Thread_Control *)
61
                    the_thread_queue->Queues.Priority[ index ].first;
62
      goto dequeue;
63
    }
64
  }
65
 
66
  switch ( the_thread_queue->sync_state ) {
67
    case THREAD_QUEUE_SYNCHRONIZED:
68
    case THREAD_QUEUE_SATISFIED:
69
      _ISR_Enable( level );
70
      return NULL;
71
 
72
    case THREAD_QUEUE_NOTHING_HAPPENED:
73
    case THREAD_QUEUE_TIMEOUT:
74
      the_thread_queue->sync_state = THREAD_QUEUE_SATISFIED;
75
      _ISR_Enable( level );
76
      return _Thread_Executing;
77
  }
78
 
79
dequeue:
80
  new_first_node   = the_thread->Wait.Block2n.first;
81
  new_first_thread = (Thread_Control *) new_first_node;
82
  next_node        = the_thread->Object.Node.next;
83
  previous_node    = the_thread->Object.Node.previous;
84
 
85
  if ( !_Chain_Is_empty( &the_thread->Wait.Block2n ) ) {
86
    last_node       = the_thread->Wait.Block2n.last;
87
    new_second_node = new_first_node->next;
88
 
89
    previous_node->next      = new_first_node;
90
    next_node->previous      = new_first_node;
91
    new_first_node->next     = next_node;
92
    new_first_node->previous = previous_node;
93
 
94
    if ( !_Chain_Has_only_one_node( &the_thread->Wait.Block2n ) ) {
95
                                                /* > two threads on 2-n */
96
      new_second_node->previous =
97
                _Chain_Head( &new_first_thread->Wait.Block2n );
98
 
99
      new_first_thread->Wait.Block2n.first = new_second_node;
100
      new_first_thread->Wait.Block2n.last  = last_node;
101
 
102
      last_node->next = _Chain_Tail( &new_first_thread->Wait.Block2n );
103
    }
104
  } else {
105
    previous_node->next = next_node;
106
    next_node->previous = previous_node;
107
  }
108
 
109
  if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
110
    _ISR_Enable( level );
111
    _Thread_Unblock( the_thread );
112
  } else {
113
    _Watchdog_Deactivate( &the_thread->Timer );
114
    _ISR_Enable( level );
115
    (void) _Watchdog_Remove( &the_thread->Timer );
116
    _Thread_Unblock( the_thread );
117
  }
118
 
119
#if defined(RTEMS_MULTIPROCESSING)
120
  if ( !_Objects_Is_local_id( the_thread->Object.id ) )
121
    _Thread_MP_Free_proxy( the_thread );
122
#endif
123
  return( the_thread );
124
}
125
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.