source: src/libcfa/concurrency/kernel @ 8fc45b7

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 8fc45b7 was 8fc45b7, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Internal helper functions now use arrays and references instead of pointers

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