ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change
on this file since 6cff9f3 was
6cff9f3,
checked in by Thierry Delisle <tdelisle@…>, 8 years ago
|
Implementation of a priority queue for alarms
|
-
Property mode set to
100644
|
File size:
1.6 KB
|
Line | |
---|
1 | // -*- Mode: CFA -*- |
---|
2 | // |
---|
3 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo |
---|
4 | // |
---|
5 | // The contents of this file are covered under the licence agreement in the |
---|
6 | // file "LICENCE" distributed with Cforall. |
---|
7 | // |
---|
8 | // alarm.c -- |
---|
9 | // |
---|
10 | // Author : Thierry Delisle |
---|
11 | // Created On : Fri Jun 2 11:31:25 2017 |
---|
12 | // Last Modified By : Thierry Delisle |
---|
13 | // Last Modified On : -- |
---|
14 | // Update Count : 0 |
---|
15 | // |
---|
16 | |
---|
17 | #include "alarm.h" |
---|
18 | #include "kernel_private.h" |
---|
19 | |
---|
20 | static void register_self( alarm_node_t * this ) { |
---|
21 | lock( &systemProcessor->alarm_lock ); |
---|
22 | insert( &systemProcessor->alarms, this ); |
---|
23 | unlock( &systemProcessor->alarm_lock ); |
---|
24 | } |
---|
25 | |
---|
26 | void ?{}( alarm_node_t * this, thread_desc * thrd, cfa_time_t alarm, cfa_time_t period = 0 ) { |
---|
27 | this->thrd = thrd; |
---|
28 | this->alarm = alarm; |
---|
29 | this->period = period; |
---|
30 | this->next = 0; |
---|
31 | |
---|
32 | register_self( this ); |
---|
33 | } |
---|
34 | |
---|
35 | void ?{}( alarm_node_t * this, processor * proc, cfa_time_t alarm, cfa_time_t period = 0 ) { |
---|
36 | this->proc = proc; |
---|
37 | this->alarm = alarm; |
---|
38 | this->period = period; |
---|
39 | this->next = 0; |
---|
40 | |
---|
41 | register_self( this ); |
---|
42 | } |
---|
43 | |
---|
44 | static inline void insert_at( alarm_list_t * this, alarm_node_t * n, __alarm_it_t p ) { |
---|
45 | assert( !n->next ); |
---|
46 | if( p == this->tail ) { |
---|
47 | this->tail = &n->next; |
---|
48 | } |
---|
49 | else { |
---|
50 | n->next = *p; |
---|
51 | } |
---|
52 | *p = n; |
---|
53 | } |
---|
54 | |
---|
55 | void insert( alarm_list_t * this, alarm_node_t * n ) { |
---|
56 | alarm_node_t ** it = &this->head; |
---|
57 | while( (*it) && (n->alarm > (*it)->alarm) ) { |
---|
58 | it = &(*it)->next; |
---|
59 | } |
---|
60 | |
---|
61 | insert_at( this, n, it ); |
---|
62 | } |
---|
63 | |
---|
64 | void pop( alarm_list_t * this ) { |
---|
65 | alarm_node_t * head = this->head; |
---|
66 | if( head ) { |
---|
67 | this->head = head->next; |
---|
68 | if( !head->next ) { |
---|
69 | this->tail = &this->head; |
---|
70 | } |
---|
71 | head->next = NULL; |
---|
72 | } |
---|
73 | return head; |
---|
74 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.