Ignore:
Timestamp:
Dec 2, 2016, 5:10:22 PM (8 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:
d7bcbf5
Parents:
4cb935e
Message:

Ugly but working coroutines

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/threads

    r4cb935e r78b3f52  
     1//                              -*- Mode: CFA -*-
    12//
    2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
    34//
    45// The contents of this file are covered under the licence agreement in the
    56// file "LICENCE" distributed with Cforall.
    67//
    7 // fstream --
     8// threads --
    89//
    9 // Author           : Peter A. Buhr
    10 // Created On       : Wed May 27 17:56:53 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Apr 28 08:08:04 2016
    13 // Update Count     : 88
     10// Author           : Thierry Delisle
     11// Created On       : Mon Nov 28 12:27:26 2016
     12// Last Modified By : Thierry Delisle
     13// Last Modified On : Mon Nov 28 12:27:26 2016
     14// Update Count     : 0
    1415//
    1516
     
    1920#include <stdbool.h>
    2021
    21 struct coroutine {
    22       coroutine* last;
    23       const char* name;
    24       bool notHalted;
    25 };
     22extern "C" {
     23      struct coVtable {
     24            void (*main)(void*);
     25            struct coroutine* (*this_coroutine)(void*);
     26      };
     27
     28      struct coStack_t {
     29            unsigned int size;          // size of stack
     30            void *storage;                      // pointer to stack
     31            void *limit;                        // stack grows towards stack limit
     32            void *base;                         // base of stack
     33            void *context;                      // address of cfa_context_t
     34            void *top;                          // address of top of storage
     35            bool userStack;     
     36      };
     37
     38
     39      enum coroutine_state { Start, Inactive, Active, Halt };
     40
     41      struct coroutine {
     42            coStack_t stack;
     43            const char *name;                   // textual name for coroutine/task, initialized by uC++ generated code
     44            int errno_;                         // copy of global UNIX variable errno
     45            coroutine_state state;            // current execution status for coroutine
     46            bool notHalted;                     // indicate if execuation state is not halted
     47
     48            coroutine *starter;         // first coroutine to resume this one
     49            coroutine *last;                    // last coroutine to resume this one
     50      };
     51}
     52
     53void ?{}(coStack_t* this);
    2654
    2755void ?{}(coroutine* this);
     
    2957trait coroutine_t(dtype T) {
    3058      coroutine* this_coroutine(T* this);
     59      void co_main(T* this);
     60      coVtable* vtable(T* this);
    3161};
     62
     63forall(dtype T | coroutine_t(T))
     64void start(T* cor);
    3265
    3366void suspend(void);
     
    3770
    3871#endif //__THREADS_H__
     72
     73// Local Variables: //
     74// mode: c //
     75// tab-width: 4 //
     76// End: //
Note: See TracChangeset for help on using the changeset viewer.