Changeset 6cff9f3 for src


Ignore:
Timestamp:
Jun 5, 2017, 10:05:49 AM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
ac032b5
Parents:
7985fa5
Message:

Implementation of a priority queue for alarms

Location:
src/libcfa/concurrency
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/alarm.c

    r7985fa5 r6cff9f3  
     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
     20static void register_self( alarm_node_t * this ) {
     21        lock( &systemProcessor->alarm_lock );
     22        insert( &systemProcessor->alarms, this );
     23        unlock( &systemProcessor->alarm_lock );
     24}
     25
     26void ?{}( 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
     35void ?{}( 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
     44static 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
     55void 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
     64void 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 TracChangeset for help on using the changeset viewer.