This invention generally relates to ranked entities, and more particularly to ranked entities that are prioritized threads.
Computer programs are commonly made up of a number of threads that are run within an operating system. Each thread typically has a priority within a range of priority levels. This enables the operating system to determine which threads should have greater priority when a number of different threads are asking to be executed at the same time. Operating systems, depending on their design, can have a large number of different priority levels. For example, some operating systems may have only eight priority levels, while others may have 256 priority levels.
Real-time operating systems are those that guarantee execution of instructions within some predetermined, worst-case time limit, or bound. Because of this bound, real-time operating systems desirably must be able to enqueue prioritized threads to and dequeue prioritized threads from a priority queue that tracks all the threads within a predetermined maximum worst case limit. This is difficult to accomplish for a real-time operating system that has a large number of priority levels, without affecting its predictable performance too greatly. For this and other reasons, there is a need for the present invention.
The invention relates to a data structure for efficiently ordering a number of ranked entities, including linking a new entity to and delinking an entity from the ranked entities. More particularly, the invention relates to enqueuing prioritized threads to and dequeuing prioritized threads from a priority queue. A data structure in one embodiment includes a horizontally linked list, an array of a number of array entries, one or more vertically linked lists, and a head pointer.
The ranks of the entities are distributed over the array, such that each array entry has a corresponding range of ranks. Each array entry points to either null, or the entity having the greatest rank within that entry's range of ranks. The horizontally linked list links at least a subset of the ranked entities in a descending rank order direction, and optionally in an ascending rank order direction. Each entity in the horizontally linked list has a unique rank as compared to the ranks of the other entities in the horizontally linked list. Each vertically linked list links a subset of the number of entities having an identical rank in a first vertical direction and optionally in a second vertical direction. The head pointer points to the entity that has the greatest rank.
In the case of enqueuing prioritized threads to and dequeuing prioritized threads from a priority queue, the invention provides for efficient enqueuing and dequeuing with minimal impact on system performance, even where there are a large number of different priority levels. However, the invention is applicable to entities other than priorities for threads. The invention specifically encompasses machine-readable media and methods of varying scope. Other aspects, embodiments and advantages of the invention, beyond those described here, will become apparent by reading the detailed description and by referencing the drawings.
In the following detailed description of exemplary embodiments of the invention, reference is made to the accompanying drawings that form a part hereof, and in which is shown by way of illustration specific exemplary embodiments in which the invention may be practiced. These embodiments are described in sufficient detail to enable those skilled in the art to practice the invention. Other embodiments may be utilized, and logical, mechanical, electrical, and other changes may be made without departing from the spirit or scope of the present invention. The following detailed description is, therefore, not to be taken in a limiting sense, and the scope of the present invention is defined only by the appended claims.
Data Structure
An example is used where there are 20 ranks, distributed equally over five array entries 104a, 104b, 104c, 104d, and 104n. Array entry 104a corresponds to ranks 1-4, array entry 104b corresponds to ranks 5-8, entry 104c corresponds to ranks 9-12, entry 104d to ranks 13-16, and entry 104n to ranks 17-20. Each array entry points to one of the entities that have the greatest rank within the rank range for the array entry. Where there is no such entity, the array entry points to null. This corresponds to the situation where there is no entity having a rank within the rank range for the array entity. Array entry 104a points to the entity 108, which has a rank of 2. There are no entities with a rank between 5 and 8, so the array entry 104b points to null, as indicated by the arrow 116. The array entry 104c points to the entity 118, which has a rank of 11. The array entry 104d points to the entity 120, which has a rank of 13. There are no entities with a rank between 17 and 20, so the array entry 104n points to null, as indicated by the arrow 132.
The data structure 100 includes a horizontally linked list 103. The horizontally linked list 103 links a ranked entity for each of the different ranks of all the ranked entities. The ranked entities linked by horizontally linked list 103 thus each have a unique rank as compared to the ranks of the other entities linked by the list 103. For example, the horizontally linked list 103 links entities 108, 114, 118, 120, 122, and 130, which have ranks 2, 4, 11, 13, 14, and 15, respectively. The horizontally linked list 103 links the entities in a descending rank order, as indicated by the arrows 105. The horizontally linked list 103 links the entities optionally in an ascending rank order, as indicated by the arrows 107.
The data structure 100 can include one or more vertically linked lists, such as the vertically linked lists 109 and 111. Each vertically linked list links ranked entities that have the same rank. For example, the vertically linked list 109 links entities 108, 110, and 112, all of which have a rank of 2. Similarly, the vertically linked list 111 links entities 122, 124, 126, and 128, all of which have a rank of 14. Each vertically linked list links the entities in a first vertical direction, as indicated by the arrows 113. Each vertically linked list links the entities optionally in a second vertical direction, as indicated by the arrows 115. The data structure 100 also can include a head pointer 106 that points to one of the entities having the greatest rank that is within the horizontally linked list 103. For example, the head pointer 106 points to the entity 108, which has a rank of 2.
In summary, the data structure 100 uses the array 102 and the horizontally linked list 103 to efficiently order ranked entities. Where there are ranked entities that have equal rank, the data structure 100 also uses vertically linked lists, such as the vertically linked lists 109 and 111. Between the horizontally linked list 103, and the vertically linked lists 109 and 111, all of the ranked entities are linked into at least one of the linked lists. The next two sections of the detailed description describe how embodiments of the invention add and remove ranked entities to and from the data structure 100.
Removal of Ranked Entities
For example, if the entity 108 of
Referring back to
For example, if the entity 108 of
Referring back to
If the particular entry was not removed from a vertically linked list in 202, but was removed from the horizontally linked list in 204, then the array entry is adjusted to point to the next entity in the list, if the next entity has a rank within the rank range for the array entry. That is, the array entry is adjusted to point to the entity to which the particular entity had pointed to in the descending rank direction 105, if this entity has a rank within the rank range for the array entry. If the particular entity was not removed from a vertically linked list in 202, or was not removed from the horizontally linked list in 204, then the array entry is adjusted to point to null. Similarly, if the particular entity was removed from the horizontally linked list in 204, but the next entity in the list does not have a rank within the range for the array entry, then the array entry is adjusted to point to null.
For example, if the entity 108 of
Referring back to
For example, if the entity 108 of
Addition of Ranked Entities
If the array entry does not currently point to null, then the method proceeds to 410 from 404 instead of to 406. If the new entity has a rank greater than the rank of the entity currently pointed to by the array entry, referred to as the first entity in
If there already is a vertically linked list into which the new entity is to be linked, then the new entity is adjusted in the vertical direction 113 to point to the first entity in the list. The new entity is also adjusted in the vertical direction 115 to point to the former last entity in the list. The first entity in the list is adjusted to point to the new entity in the vertical direction 115, because the new entity is now the last entity in the list. The former last entity in the list is adjusted to point to the new entity in the vertical direction 113. If there is not already a vertically linked list into which the new entity is to be linked, then the new entity is the second and the last entity in a new vertically linked list. The first entity in the list is the other entity that has the same rank as the new entity. The first entity is adjusted to point to the new entity in the vertical directions 113 and 115, and the new entity is adjusted to point to the new entity in the vertical directions 113 and 115.
Still referring to
With respect to this last case, prior to insertion of the new entity within the horizontally linked list, the first entity identified in the previous paragraph points to the second entity in the descending rank order direction 105. Similarly, the second entity identified in the previous paragraph points to the first entity in the ascending rank order direction 107. After insertion, in the descending rank order direction 105, the first entity points to the new entity, which points to the second entity. Similarly, in the ascending rank order direction 107, the second entity points to the new entity, which points to the first entity. Where the new entity has a rank greater than the rank of every other entity, and is added to the horizontally linked list at the front, the new entity points to the old front entity in the descending rank order direction 105. The old front entity points to the new entity in the ascending rank order direction 107. Where the new entity has a rank less than the rank of every other entity, and is appended to the horizontally linked list at the end, the new entity points to the old back entity in the ascending rank order direction 107. The old back entity points to the new entity in the descending rank order direction 105.
As an example of adding entities to vertically and horizontally linked lists,
With respect to the new entity 517, the new entity 517 points to the first entity in the list 109″, which is the entity 108, in the vertical direction 113. The new entity 517 points to the former last entity, which is the entity 112, in the vertical direction 115. The entity 108 now points to the new entity 517 in the vertical direction 115. The entity 112 now points to the new entity 517 in the vertical direction 113. With respect to the new entity 515, the new entity 515 points to the first entry in the list 519, which is the entity 114, in both the vertical directions 113 and 115. Similarly, the entity 114 points to the new entity 515 in both the vertical directions 113 and 115. With respect to the new entity 513, the entity 108 now points to the new entity 513 in the descending rank order direction 105, and the new entity 513 points to the entity 114 in the descending rank order direction 105. The entity 114 now points to the new entity 513 in the ascending rank order direction 107, and the new entity 513 points to the entity 108 in the ascending rank order direction 107.
Example Computerized Device
The invention can be implemented within a computerized environment having one or more computerized devices. The diagram of
The device 600 includes one or more of the following components: processor(s) 602, memory 604, storage 606, a communications component 608, input device(s) 610, a display 612, and output device(s) 614. For a particular instantiation of the device 600, one or more of these components may not be present. For example, a PDA may not have any output device(s) 614. The description of the device 600 is to be used as an overview of the types of components that typically reside within such a device, and is not meant as a limiting or exhaustive description.
The processor(s) 602 may include a single central-processing unit (CPU), or a plurality of processing units, commonly referred to as a parallel processing environment. The memory 604 may include read-only memory (ROM) and/or random-access memory (RAM). The storage 606 may be any type of storage, such as fixed-media storage devices and removable-media storage devices. Examples of the former include hard disk drives, and flash or other non-volatile memory. Examples of the latter include tape drives, optical drives like CD-ROM drives, and floppy disk drives. The storage devices and their associated machine-readable media provide non-volatile storage of machine-readable instructions, data structures, program modules, and other data. Any type of machine-readable media that can store data and that is accessible by a computer can be used.
The device 600 may operate in a network environment. Examples of networks include the Internet, intranets, extranets, local-area networks (LAN's), and wide-area networks (WAN's). The device 600 may include a communications component 608, which can be present in or attached to the device 600. The component 608 may be one or more of a network card, an Ethernet card, an analog modem, a cable modem, a digital subscriber loop (DSL) modem, and an Integrated Services Digital Network (ISDN) adapter. The input device(s) 610 are the mechanisms by which a user provides input to the device 600. Such device(s) 610 can include keyboards, pointing devices, microphones, joysticks, game pads, and scanners. The display 612 is how the device 600 typically shows output to the user. The display 612 can include cathode-ray tube (CRT) display devices and flat-panel display (FPD) display devices. The device 600 may provide output to the user via other output device(s) 614. The output device(s) 614 can include speakers, printers, and other types of devices.
The methods that have been described can be computer-implemented on the device 600. A computer-implemented method is desirably realized at least in part as one or more programs running on a computer. The programs can be executed from a machine-readable medium such as a memory by a processor of a computer. The programs are desirably storable on a machine-readable medium, such as a floppy disk or a CD-ROM, for distribution and installation and execution on another computer. The program or programs can be a part of a computer system, a computer, or a computerized device. Furthermore, data structures as have been described can be stored on a machine-readable medium.
It is noted that, although specific embodiments have been illustrated and described herein, it will be appreciated by those of ordinary skill in the art that any arrangement that is calculated to achieve the same purpose may be substituted for the specific embodiments shown. This application is intended to cover any adaptations or variations of the present invention. Therefore, it is manifestly intended that this invention be limited only by the claims and equivalents thereof.
This application claims priority to and the benefit of the provisional patent application entitled “A Method to Enqueue and Dequeue from a Priority Queue Efficiently,” filed on May 15, 2000, and assigned Ser. No. 60/204,221.
Number | Name | Date | Kind |
---|---|---|---|
4896261 | Nolan | Jan 1990 | A |
5185861 | Valencia | Feb 1993 | A |
5379297 | Glover et al. | Jan 1995 | A |
5452452 | Gaetner et al. | Sep 1995 | A |
5819286 | Yang et al. | Oct 1998 | A |
5872938 | Williams | Feb 1999 | A |
6003101 | Williams | Dec 1999 | A |
6044393 | Donaldson et al. | Mar 2000 | A |
6317872 | Gee et al. | Nov 2001 | B1 |
6463484 | Moss | Oct 2002 | B1 |
6609161 | Young | Aug 2003 | B1 |
6964046 | Ogus et al. | Nov 2005 | B1 |
Number | Date | Country | |
---|---|---|---|
60204221 | May 2000 | US |