source: src/libcfa/concurrency/kernel @ a2ea829

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 a2ea829 was 025278e, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Changed comments to be above fields, to help source control diff readability

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[8118303]1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[75a17f1]7// kernel --
[8118303]8//
9// Author           : Thierry Delisle
[75f3522]10// Created On       : Tue Jan 17 12:27:26 2017
[6b0b624]11// Last Modified By : Peter A. Buhr
12// Last Modified On : Sat Jul 22 09:58:39 2017
13// Update Count     : 2
[8118303]14//
15
[6b0b624]16#pragma once
[8118303]17
[c84e80a]18#include <stdbool.h>
[8118303]19
[bd98b58]20#include "invoke.h"
21
[8def349]22extern "C" {
23#include <pthread.h>
24}
25
[db6f06a]26//-----------------------------------------------------------------------------
27// Locks
[025278e]28// Lock the spinlock, spin if already acquired
29void lock      ( spinlock * DEBUG_CTX_PARAM2 );
30
31// Lock the spinlock, yield repeatedly if already acquired
32void lock_yield( spinlock * DEBUG_CTX_PARAM2 );
33
34// Lock the spinlock, return false if already acquired
35bool try_lock  ( spinlock * DEBUG_CTX_PARAM2 );
36
37// Unlock the spinlock
38void unlock    ( spinlock * );
[db6f06a]39
[bdeba0b]40struct semaphore {
41        spinlock lock;
42        int count;
43        __thread_queue_t waiting;
[9c31349]44};
45
[242a902]46void  ?{}(semaphore & this, int count = 1);
47void ^?{}(semaphore & this);
[4cedd9f]48void   P (semaphore & this);
49void   V (semaphore & this);
[9c31349]50
[db6f06a]51
[bd98b58]52//-----------------------------------------------------------------------------
53// Cluster
54struct cluster {
[025278e]55        // Ready queue locks
56        spinlock ready_queue_lock;
57
58        // Ready queue for threads
59        __thread_queue_t ready_queue;
60
61        // Preemption rate on this cluster
62        unsigned long long int preemption;
[bd98b58]63};
64
[4cedd9f]65void ?{} (cluster & this);
[242a902]66void ^?{}(cluster & this);
[bd98b58]67
68//-----------------------------------------------------------------------------
69// Processor
[0c78741]70enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule };
71
72//TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI)
[db6f06a]73struct FinishAction {
74        FinishOpCode action_code;
[348006f]75        thread_desc * thrd;
[db6f06a]76        spinlock * lock;
[0c78741]77        spinlock ** locks;
78        unsigned short lock_count;
79        thread_desc ** thrds;
80        unsigned short thrd_count;
[8fcbb4c]81};
[242a902]82static inline void ?{}(FinishAction & this) {
83        this.action_code = No_Action;
84        this.thrd = NULL;
85        this.lock = NULL;
[db6f06a]86}
[242a902]87static inline void ^?{}(FinishAction & this) {}
[8fcbb4c]88
[e60e0dc]89// Processor
90// Wrapper around kernel threads
[c84e80a]91struct processor {
[e60e0dc]92        // Main state
[025278e]93        // Coroutine ctx who does keeps the state of the processor
94        struct processorCtx_t * runner;
95
96        // Cluster from which to get threads
97        cluster * cltr;
98
99        // Handle to pthreads
100        pthread_t kernel_thread;
[2ac095d]101
[e60e0dc]102        // Termination
[025278e]103        // Set to true to notify the processor should terminate
104        volatile bool do_terminate;
105
106        // Termination synchronisation
107        semaphore terminated;
[db6f06a]108
[e60e0dc]109        // RunThread data
[025278e]110        // Action to do after a thread is ran
111        struct FinishAction finish;
[c81ebf9]112
[e60e0dc]113        // Preemption data
[025278e]114        // Node which is added in the discrete event simulaiton
115        struct alarm_node_t * preemption_alarm;
116
117        // If true, a preemption was triggered in an unsafe region, the processor must preempt as soon as possible
118        bool pending_preemption;
[c81ebf9]119
[e60e0dc]120#ifdef __CFA_DEBUG__
[025278e]121        // Last function to enable preemption on this processor
122        char * last_enable;
[e60e0dc]123#endif
[c84e80a]124};
125
[8fc45b7]126void  ?{}(processor & this);
127void  ?{}(processor & this, cluster * cltr);
[242a902]128void ^?{}(processor & this);
[c84e80a]129
[8118303]130// Local Variables: //
[6b0b624]131// mode: c //
132// tab-width: 4 //
[8118303]133// End: //
Note: See TracBrowser for help on using the repository browser.