Changeset 29185fc


Ignore:
Timestamp:
Sep 30, 2020, 4:44:22 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
4e39f51
Parents:
d035cf7
Message:

Working towards allowing different thread frameworks to be picked from the command line

Location:
doc/theses/thierry_delisle_PhD/code/readQ_example
Files:
3 added
1 deleted
1 edited
2 moved

Legend:

Unmodified
Added
Removed
  • doc/theses/thierry_delisle_PhD/code/readQ_example/proto-gui/main.cpp

    rd035cf7 r29185fc  
    1 #include "thrdlib/thread.h"
     1#include "thrdlib/thread.hpp"
    22
    33#include <cassert>
     
    1010
    1111#include <getopt.h>
     12using thrdlib::thread_t;
     13
    1214
    1315//--------------------
     
    3739                        assert( expected == reset );
    3840                        if( std::atomic_compare_exchange_strong( &state, &expected, self) ) {
    39                                 thrdlib_park( self );
     41                                thrdlib::park( self );
    4042                                ret = true;
    4143                                goto END;
     
    5557                if( got == reset ) return false;
    5658
    57                 thrdlib_unpark( got );
     59                thrdlib::unpark( got );
    5860                return true;
    5961        }
     
    110112        the_stats_thread = self;
    111113        fence();
    112         thrdlib_park( self );
     114        thrdlib::park( self );
    113115
    114116        std::vector<bool> seen;
     
    116118
    117119        while(last_produced < nproduce) {
    118                 thrdlib_yield();
     120                thrdlib::yield();
    119121                thrd_stats.stats.ran++;
    120122                if( last_produced > 0 ) seen.at(last_produced - 1) = true;
     
    148150
    149151void Renderer( thread_t self ) {
    150         thrdlib_unpark( the_stats_thread );
     152        thrdlib::unpark( the_stats_thread );
    151153        for(unsigned i = 0; i < nproduce; i++) {
    152154                auto & frame = frames[i % nframes];
     
    247249        std::cout << "(Buffering " << nframes << ")" << std::endl;
    248250
    249         thrdlib_init( 2 );
    250 
    251         thread_t stats     = thrdlib_create( Stats    );
     251        thrdlib::init( "fibre", 2 );
     252
     253        thread_t stats     = thrdlib::create( Stats );
    252254        std::cout << "Created Stats Thread" << std::endl;
    253         while( the_stats_thread == nullptr ) thrdlib_yield();
     255        while( the_stats_thread == nullptr ) thrdlib::yield();
     256
    254257        std::cout << "Creating Main Threads" << std::endl;
    255         thread_t renderer  = thrdlib_create( Renderer  );
    256         // while(true);
    257         thread_t simulator = thrdlib_create( Simulator );
     258        thread_t renderer  = thrdlib::create( Renderer  );
     259        thread_t simulator = thrdlib::create( Simulator );
    258260
    259261        std::cout << "Running" << std::endl;
    260262
    261         thrdlib_join( simulator );
    262         thrdlib_join( renderer  );
    263         thrdlib_join( stats     );
    264 
    265         thrdlib_clean();
     263        thrdlib::join( simulator );
     264        thrdlib::join( renderer  );
     265        thrdlib::join( stats     );
     266
     267        thrdlib::clean();
    266268
    267269        std::cout << "----------" << std::endl;
  • doc/theses/thierry_delisle_PhD/code/readQ_example/thrdlib/fibre.cpp

    rd035cf7 r29185fc  
    1 #pragma once
    2 
    31#include <cassert>
    42#include <libfibre/cfibre.h>
    53
    6 #if defined(__cforall) || defined(__cpluplus)
     4typedef cfibre_t thread_t;
     5static_assert(sizeof(thread_t) == sizeof(void*), "thread_t musst be of same size as void*");
     6
     7void * fibre_runner(void * arg) {
     8        auto the_main = (void (*)( thread_t ))arg;
     9        the_main( cfibre_self() );
     10        return nullptr;
     11}
     12
    713extern "C" {
    8 #endif
    9         //--------------------
    10         // Basic types
    11         typedef cfibre_t thread_t;
    12 
    13         void * fibre_runner(void * arg) {
    14                 auto the_main = (void (*)( thread_t ))arg;
    15                 the_main( cfibre_self() );
    16                 return nullptr;
    17         }
    18 
    1914        //--------------------
    2015        // Basic thread support
     
    5146
    5247        }
    53 
    54 
    55 #if defined(__cforall) || defined(__cpluplus)
    5648}
    57 #endif
  • doc/theses/thierry_delisle_PhD/code/readQ_example/thrdlib/pthread.cpp

    rd035cf7 r29185fc  
    1 #pragma once
    2 
    31#include <pthread.h>
    42#include <errno.h>
     
    5654#undef CHECKED
    5755
    58 #if defined(__cforall) || defined(__cpluplus)
     56//--------------------
     57// Basic types
     58struct pthread_runner_t {
     59        pthread_t handle;
     60        __bin_sem_t sem;
     61};
     62typedef pthread_runner_t * thread_t;
     63
     64static_assert(sizeof(thread_t) == sizeof(void*), "thread_t musst be of same size as void*");
     65
    5966extern "C" {
    60 #endif
    61         //--------------------
    62         // Basic types
    63         struct pthread_runner_t {
    64                 pthread_t handle;
    65                 __bin_sem_t sem;
    66         };
    67         typedef pthread_runner_t * thread_t;
    68 
    6967        //--------------------
    7068        // Basic thread support
     
    9997        // Basic kernel features
    10098        void thrdlib_init( int ) {}
    101         void thrdlib_clean( void ) {}
    102 
    103 
    104 #if defined(__cforall) || defined(__cpluplus)
    10599}
    106 #endif
Note: See TracChangeset for help on using the changeset viewer.