Changeset 90152a4 for libcfa


Ignore:
Timestamp:
Aug 27, 2018, 4:40:34 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b7c89aa
Parents:
f9feab8 (diff), 305581d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into cleanup-dtors

Location:
libcfa
Files:
50 added
85 moved

Legend:

Unmodified
Added
Removed
  • libcfa/prelude/Makefile.in

    rf9feab8 r90152a4  
    9090PRE_UNINSTALL = :
    9191POST_UNINSTALL = :
    92 build_triplet = @build@
    93 host_triplet = @host@
    94 subdir = src/prelude
     92subdir = prelude
    9593ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
    96 am__aclocal_m4_deps = $(top_srcdir)/configure.ac
     94am__aclocal_m4_deps = $(top_srcdir)/../automake/cfa.m4 \
     95        $(top_srcdir)/configure.ac
    9796am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
    9897        $(ACLOCAL_M4)
    9998DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
    10099mkinstalldirs = $(install_sh) -d
    101 CONFIG_HEADER = $(top_builddir)/config.h
    102100CONFIG_CLEAN_FILES =
    103101CONFIG_CLEAN_VPATH_FILES =
     
    154152DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
    155153ACLOCAL = @ACLOCAL@
    156 ALLOCA = @ALLOCA@
    157154AMTAR = @AMTAR@
    158155AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
     156ARCHITECTURE = @ARCHITECTURE@
     157ARCH_FLAGS = @ARCH_FLAGS@
    159158AUTOCONF = @AUTOCONF@
    160159AUTOHEADER = @AUTOHEADER@
    161160AUTOMAKE = @AUTOMAKE@
    162161AWK = @AWK@
    163 BACKEND_CC = @BACKEND_CC@
    164 CC = ${abs_top_srcdir}/src/driver/cfa
     162CC = @CFACC@
    165163CCAS = @CCAS@
    166164CCASDEPMODE = @CCASDEPMODE@
    167165CCASFLAGS = @CCASFLAGS@
    168166CCDEPMODE = @CCDEPMODE@
    169 CFA_BACKEND_CC = @CFA_BACKEND_CC@
     167CFACC = @CFACC@
     168CFACPP = @CFACPP@
    170169CFA_BINDIR = @CFA_BINDIR@
    171 CFA_FLAGS = @CFA_FLAGS@
    172170CFA_INCDIR = @CFA_INCDIR@
    173171CFA_LIBDIR = @CFA_LIBDIR@
     
    175173CFA_PREFIX = @CFA_PREFIX@
    176174CFLAGS = @CFLAGS@
    177 CPP = @CPP@
     175CONFIGURATION = @CONFIGURATION@
     176CONFIG_CFAFLAGS = @CONFIG_CFAFLAGS@
     177CONFIG_CFLAGS = @CONFIG_CFLAGS@
    178178CPPFLAGS = @CPPFLAGS@
    179179CXX = @CXX@
     
    183183DEFS = @DEFS@
    184184DEPDIR = @DEPDIR@
     185DRIVER_DIR = @DRIVER_DIR@
    185186ECHO_C = @ECHO_C@
    186187ECHO_N = @ECHO_N@
    187188ECHO_T = @ECHO_T@
    188 EGREP = @EGREP@
    189189EXEEXT = @EXEEXT@
    190 GREP = @GREP@
    191190INSTALL = @INSTALL@
    192191INSTALL_DATA = @INSTALL_DATA@
     
    195194INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
    196195LDFLAGS = @LDFLAGS@
    197 LEX = @LEX@
    198 LEXLIB = @LEXLIB@
    199 LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
    200196LIBOBJS = @LIBOBJS@
    201197LIBS = @LIBS@
    202198LTLIBOBJS = @LTLIBOBJS@
    203 MACHINE_TYPE = @MACHINE_TYPE@
    204 MAINT = @MAINT@
    205199MAKEINFO = @MAKEINFO@
    206200MKDIR_P = @MKDIR_P@
     
    219213STRIP = @STRIP@
    220214VERSION = @VERSION@
    221 YACC = @YACC@
    222 YFLAGS = @YFLAGS@
    223215abs_builddir = @abs_builddir@
    224216abs_srcdir = @abs_srcdir@
     
    233225am__untar = @am__untar@
    234226bindir = @bindir@
    235 build = @build@
    236227build_alias = @build_alias@
    237 build_cpu = @build_cpu@
    238 build_os = @build_os@
    239 build_vendor = @build_vendor@
    240228builddir = @builddir@
    241229datadir = @datadir@
     
    244232dvidir = @dvidir@
    245233exec_prefix = @exec_prefix@
    246 host = @host@
    247234host_alias = @host_alias@
    248 host_cpu = @host_cpu@
    249 host_os = @host_os@
    250 host_vendor = @host_vendor@
    251235htmldir = @htmldir@
    252236includedir = @includedir@
     
    275259
    276260# create object files in directory with source files
    277 AUTOMAKE_OPTIONS = subdir-objects
     261AUTOMAKE_OPTIONS = foreign subdir-objects
    278262
    279263# put into lib for now
    280264cfalibdir = ${CFA_LIBDIR}
    281265cfalib_DATA = gcc-builtins.cf builtins.cf extras.cf prelude.cf bootloader.c
    282 noinst_DATA = ../libcfa/libcfa-prelude.c
    283 MAINTAINERCLEANFILES = gcc-builtins.c gcc-builtins.cf builtins.cf extras.cf bootloader.c ${addprefix ${libdir}/,${cfalib_DATA}} ${addprefix ${libdir}/,${lib_LIBRARIES}}
     266noinst_DATA = ../src/prelude.c
     267AM_CFLAGS = -g -Wall -Wno-unused-function @ARCH_FLAGS@ @CONFIG_CFLAGS@
     268AM_CFAFLAGS = @CONFIG_CFAFLAGS@
     269MOSTLYCLEANFILES = bootloader.c builtins.cf extras.cf gcc-builtins.c gcc-builtins.cf prelude.cf
     270MAINTAINERCLEANFILES = ${addprefix ${libdir}/,${cfalib_DATA}} ${addprefix ${libdir}/,${lib_LIBRARIES}}
    284271all: all-am
    285272
    286273.SUFFIXES:
    287 $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
     274$(srcdir)/Makefile.in: $(srcdir)/Makefile.am  $(am__configure_deps)
    288275        @for dep in $?; do \
    289276          case '$(am__configure_deps)' in \
     
    294281          esac; \
    295282        done; \
    296         echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/prelude/Makefile'; \
     283        echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign prelude/Makefile'; \
    297284        $(am__cd) $(top_srcdir) && \
    298           $(AUTOMAKE) --foreign src/prelude/Makefile
     285          $(AUTOMAKE) --foreign prelude/Makefile
    299286Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
    300287        @case '$?' in \
     
    309296        cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
    310297
    311 $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
     298$(top_srcdir)/configure: $(am__configure_deps)
    312299        cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
    313 $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
     300$(ACLOCAL_M4): $(am__aclocal_m4_deps)
    314301        cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
    315302$(am__aclocal_m4_deps):
     
    399386        fi
    400387mostlyclean-generic:
     388        -test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES)
    401389
    402390clean-generic:
     
    501489
    502490# create extra forward types/declarations to reduce inclusion of library files
    503 extras.cf : extras.regx extras.c
    504         ${AM_V_GEN}@BACKEND_CC@ @CFA_FLAGS@ -E ${srcdir}/extras.c | grep -f extras.regx > ${srcdir}/extras.cf
     491extras.cf : ${srcdir}/extras.regx ${srcdir}/extras.c
     492        ${AM_V_GEN}gcc ${AM_CFLAGS} -E ${srcdir}/extras.c | grep -f ${srcdir}/extras.regx > extras.cf
    505493
    506494# create forward declarations for gcc builtins
    507 gcc-builtins.cf : gcc-builtins.c prototypes.sed
    508         ${AM_V_GEN}@BACKEND_CC@ -E -P $< | sed -f prototypes.sed > $@
    509 
    510 gcc-builtins.c : builtins.def prototypes.awk
    511         ${AM_V_GEN}@BACKEND_CC@ -E prototypes.c | awk -f prototypes.awk > $@
     495gcc-builtins.cf : gcc-builtins.c ${srcdir}/prototypes.sed
     496        ${AM_V_GEN}gcc -I${srcdir} -E -P $< | sed -r -f ${srcdir}/prototypes.sed > $@
     497
     498gcc-builtins.c : ${srcdir}/builtins.def ${srcdir}/prototypes.awk ${srcdir}/sync-builtins.cf ${srcdir}/prototypes.c
     499        ${AM_V_GEN}gcc -I${srcdir} -E ${srcdir}/prototypes.c | awk -f ${srcdir}/prototypes.awk > $@
     500
     501prelude.cf : prelude-gen.cc
     502        ${AM_V_GEN}${CXX} ${AM_CXXFLAGS} ${CXXFLAGS} ${AM_CFLAGS} ${<} -o prelude-gen -Wall -Wextra -O2 -g -std=c++14
     503        @./prelude-gen > $@
     504        @rm ./prelude-gen
    512505
    513506builtins.def :
     
    517510# create forward declarations for cfa builtins
    518511builtins.cf : builtins.c ${CC}
    519         ${AM_V_GEN}${CC} -E -P ${<} -o ${@} -MD -MP -MF $(DEPDIR)/builtins.Po
     512        ${AM_V_GEN}gcc ${AM_CFLAGS} -E -P ${<} -o ${@} -MD -MP -MF $(DEPDIR)/builtins.Po
    520513        ${AM_V_at}sed -i 's/builtins.o/builtins.cf/g' $(DEPDIR)/builtins.Po
    521514
    522515include $(DEPDIR)/builtins.Po
    523516
    524 ../libcfa/libcfa-prelude.c : prelude.cf extras.cf gcc-builtins.cf builtins.cf ${abs_top_srcdir}/src/driver/cfa-cpp
    525         ${AM_V_GEN}${abs_top_srcdir}/src/driver/cfa-cpp -l prelude.cf $@  # use src/cfa-cpp as not in lib until after install
    526 
    527 bootloader.c : bootloader.cf prelude.cf extras.cf gcc-builtins.cf builtins.cf ${abs_top_srcdir}/src/driver/cfa-cpp
    528         ${AM_V_GEN}${abs_top_srcdir}/src/driver/cfa-cpp -tpm bootloader.cf $@  # use src/cfa-cpp as not in lib until after install
     517../src/prelude.c : prelude.cf extras.cf gcc-builtins.cf builtins.cf @CFACPP@
     518        ${AM_V_GEN}@CFACPP@ --prelude-dir=${builddir} -l prelude.cf $@  # use src/cfa-cpp as not in lib until after install
     519
     520bootloader.c : ${srcdir}/bootloader.cf prelude.cf extras.cf gcc-builtins.cf builtins.cf @CFACPP@
     521        ${AM_V_GEN}@CFACPP@ --prelude-dir=${builddir} -tpm ${srcdir}/bootloader.cf $@  # use src/cfa-cpp as not in lib until after install
    529522
    530523maintainer-clean-local :
  • libcfa/prelude/builtins.c

    rf9feab8 r90152a4  
    99// Author           : Peter A. Buhr
    1010// Created On       : Fri Jul 21 16:21:03 2017
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Jul 25 15:33:00 2017
    13 // Update Count     : 14
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Aug  5 21:40:38 2018
     13// Update Count     : 20
    1414//
    1515
     
    1818typedef unsigned long long __cfaabi_abi_exception_type_t;
    1919
    20 #include "../libcfa/virtual.h"
    21 #include "../libcfa/exception.h"
     20#include "../src/virtual.h"
     21#include "../src/exception.h"
     22
     23void exit( int status, const char fmt[], ... ) __attribute__ (( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ ));
     24void abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
     25
     26// increment/decrement unification
     27
     28static inline forall( dtype T | { T& ?+=?( T&, one_t ); } )
     29T& ++? ( T& x ) { return x += 1; }
     30
     31static inline forall( dtype T | sized(T) | { void ?{}( T&, T ); void ^?{}( T& ); T& ?+=?( T&, one_t ); } )
     32T& ?++ ( T& x ) { T tmp = x; x += 1; return tmp; }
     33
     34static inline forall( dtype T | { T& ?-=?( T&, one_t ); } )
     35T& --? ( T& x ) { return x -= 1; }
     36
     37static inline forall( dtype T | sized(T) | { void ?{}( T&, T ); void ^?{}( T& ); T& ?-=?( T&, one_t ); } )
     38T& ?-- ( T& x ) { T tmp = x; x -= 1; return tmp; }
    2239
    2340// exponentiation operator implementation
     
    4158static inline long int ?\?( long int ep, unsigned long int y ) { // disallow negative exponent
    4259        if ( y == 0 ) return 1;                                                         // base case
    43     if ( ep == 2 ) return ep << (y - 1);                                // special case, positive shifting only
    44     typeof( ep ) op = 1;                                                                // accumulate odd product
    45     for ( ; y > 1; y >>= 1 ) {                                                  // squaring exponentiation, O(log2 y)
     60        if ( ep == 2 ) return ep << (y - 1);                            // special case, positive shifting only
     61        typeof( ep ) op = 1;                                                            // accumulate odd product
     62        for ( ; y > 1; y >>= 1 ) {                                                      // squaring exponentiation, O(log2 y)
    4663                if ( (y & 1) == 1 ) op *= ep;                                   // odd ?
    4764                ep *= ep;
    4865        } // for
    49     return ep * op;
     66        return ep * op;
    5067} // ?\?
    5168
    52 // FIX ME, cannot resolve the "T op = 1".
    53 
    54 // static inline forall( otype T | { void ?{}( T * this, one_t ); T ?*?( T, T ); } )
    55 // T ?\?( T ep, unsigned long int y ) {
    56 //     if ( y == 0 ) return 1;
    57 //     T op = 1;
    58 //     for ( ; y > 1; y >>= 1 ) {                                                       // squaring exponentiation, O(log2 y)
    59 //              if ( (y & 1) == 1 ) op = op * ep;                               // odd ?
    60 //              ep = ep * ep;
    61 //     } // for
    62 //     return ep * op;
    63 // } // ?\?
     69static inline forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); } )
     70T ?\?( T ep, unsigned long int y ) {
     71        if ( y == 0 ) return 1;
     72        T op = 1;
     73        for ( ; y > 1; y >>= 1 ) {                                                      // squaring exponentiation, O(log2 y)
     74                if ( (y & 1) == 1 ) op = op * ep;                               // odd ?
     75                ep = ep * ep;
     76        } // for
     77        return ep * op;
     78} // ?\?
    6479
    6580// unsigned computation may be faster and larger
    6681static inline unsigned long int ?\?( unsigned long int ep, unsigned long int y ) { // disallow negative exponent
    6782        if ( y == 0 ) return 1;                                                         // base case
    68     if ( ep == 2 ) return ep << (y - 1);                                // special case, positive shifting only
    69     typeof( ep ) op = 1;                                                                // accumulate odd product
    70     for ( ; y > 1; y >>= 1 ) {                                                  // squaring exponentiation, O(log2 y)
     83        if ( ep == 2 ) return ep << (y - 1);                            // special case, positive shifting only
     84        typeof( ep ) op = 1;                                                            // accumulate odd product
     85        for ( ; y > 1; y >>= 1 ) {                                                      // squaring exponentiation, O(log2 y)
    7186                if ( (y & 1) == 1 ) op *= ep;                                   // odd ?
    7287                ep *= ep;
    7388        } // for
    74     return ep * op;
     89        return ep * op;
    7590} // ?\?
    7691
    7792static inline double ?\?( long int x, signed long int y ) {     // allow negative exponent
    78     if ( y >=  0 ) return (double)(x \ (unsigned long int)y);
    79     else return 1.0 / x \ (unsigned int)(-y);
     93        if ( y >=  0 ) return (double)(x \ (unsigned long int)y);
     94        else return 1.0 / x \ (unsigned int)(-y);
    8095} // ?\?
    8196
  • libcfa/prelude/builtins.def

    rf9feab8 r90152a4  
    190190
    191191/* Builtin used by implementation of Cilk Plus.  Most of these are decomposed
    192    by the compiler but a few are implemented in libcilkrts.  */ 
     192   by the compiler but a few are implemented in libcilkrts.  */
    193193#undef DEF_CILK_BUILTIN_STUB
    194194#define DEF_CILK_BUILTIN_STUB(ENUM, NAME) \
     
    204204
    205205/* Builtin used by the implementation of libsanitizer. These
    206    functions are mapped to the actual implementation of the 
     206   functions are mapped to the actual implementation of the
    207207   libtsan library. */
    208208#undef DEF_SANITIZER_BUILTIN
     
    217217#define DEF_CILKPLUS_BUILTIN(ENUM, NAME, TYPE, ATTRS)  \
    218218  DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, BT_FN_INT_VAR, BT_LAST, \
    219                false, false, false, ATTRS, false, flag_cilkplus) 
     219               false, false, false, ATTRS, false, flag_cilkplus)
    220220
    221221/* Builtin used by the implementation of Pointer Bounds Checker.  */
     
    927927DEF_GCC_BUILTIN (BUILT_IN_LINE, "LINE", BT_FN_INT, ATTR_NOTHROW_LEAF_LIST)
    928928
     929#if 0 //Ifdefed out because we hard-coded the proper overloadings of the atomic built-ins
    929930/* Synchronization Primitives.  */
    930931#include "sync-builtins.def"
    931932
    932 #if 0
    933933/* Offloading and Multi Processing builtins.  */
    934934#include "omp-builtins.def"
  • libcfa/prelude/extras.regx

    rf9feab8 r90152a4  
    11typedef.* size_t;
    22typedef.* ptrdiff_t;
     3typedef.* __int8_t;
     4typedef.* __int16_t;
     5typedef.* __int32_t;
     6typedef.* __int64_t;
     7typedef.* __uint8_t;
     8typedef.* __uint16_t;
     9typedef.* __uint32_t;
     10typedef.* __uint64_t;
    311typedef.* int8_t;
    412typedef.* int16_t;
  • libcfa/prelude/prelude.old.cf

    rf9feab8 r90152a4  
    77// Created On       : Sat Nov 29 07:23:41 2014
    88// Last Modified By : Peter A. Buhr
    9 // Last Modified On : Sat Oct 28 16:33:09 2017
    10 // Update Count     : 102
     9// Last Modified On : Sun Apr 22 13:21:47 2018
     10// Update Count     : 103
    1111//
    1212
     
    3939// ------------------------------------------------------------
    4040
    41 _Bool                   ?++( _Bool & ),                         ?++( volatile _Bool & );
    42 _Bool                   ?--( _Bool & ),                         ?--( volatile _Bool & );
    4341signed short            ?++( signed short & ),                  ?++( volatile signed short & );
    4442signed short            ?--( signed short & ),                  ?--( volatile signed short & );
     
    9492// ------------------------------------------------------------
    9593
    96 _Bool                   ++?( _Bool & ),                         --?( _Bool & );
    9794signed short    ++?( signed short & ),                  --?( signed short & );
    9895signed int              ++?( signed int & ),                    --?( signed int & );
     
    125122forall( ftype FT ) FT &          *?( FT * );
    126123
    127 _Bool                   +?( _Bool ),                    -?( _Bool ),                    ~?( _Bool );
     124_Bool                   +?( _Bool ),                    -?( _Bool );
    128125signed int              +?( signed int ),               -?( signed int ),               ~?( signed int );
    129126unsigned int            +?( unsigned int ),             -?( unsigned int ),             ~?( unsigned int );
     
    145142                !?( float _Complex ),           !?( double _Complex ),          !?( long double _Complex );
    146143
    147 forall ( dtype DT ) int !?(                DT * );
    148 forall ( dtype DT ) int !?( const          DT * );
    149 forall ( dtype DT ) int !?(       volatile DT * );
    150 forall ( dtype DT ) int !?( const volatile DT * );
    151 forall ( ftype FT ) int !?( FT * );
     144forall( dtype DT ) int !?(                DT * );
     145forall( dtype DT ) int !?( const          DT * );
     146forall( dtype DT ) int !?(       volatile DT * );
     147forall( dtype DT ) int !?( const volatile DT * );
     148forall( ftype FT ) int !?( FT * );
    152149
    153150// ------------------------------------------------------------
     
    157154// ------------------------------------------------------------
    158155
    159 _Bool                   ?*?( _Bool, _Bool ),                                    ?/?( _Bool, _Bool ),                            ?%?( _Bool, _Bool );
    160156signed int              ?*?( signed int, signed int ),                          ?/?( signed int, signed int ),                  ?%?( signed int, signed int );
    161157unsigned int            ?*?( unsigned int, unsigned int ),                      ?/?( unsigned int, unsigned int ),              ?%?( unsigned int, unsigned int );
     
    215211// ------------------------------------------------------------
    216212
    217 _Bool                   ?<<?( _Bool, _Bool ),                                   ?>>?( _Bool, _Bool );
    218213signed int              ?<<?( signed int, signed int ),                         ?>>?( signed int, signed int );
    219214unsigned int            ?<<?( unsigned int, unsigned int ),                     ?>>?( unsigned int, unsigned int );
     
    467462
    468463
    469 _Bool                   ?*=?( _Bool &, _Bool ),                                 ?*=?( volatile _Bool &, _Bool );
    470464char                    ?*=?( char &, char ),                                   ?*=?( volatile char &, char );
    471465char signed             ?*=?( char signed &, char signed ),                     ?*=?( volatile char signed &, char signed );
     
    534528unsigned long long int  ?-=?( unsigned long long int &, unsigned long long int ), ?-=?( volatile unsigned long long int &, unsigned long long int );
    535529
    536 _Bool                   ?<<=?( _Bool &, _Bool ),                                ?<<=?( volatile _Bool &, _Bool );
    537530char                    ?<<=?( char &, char ),                                  ?<<=?( volatile char &, char );
    538531char signed             ?<<=?( char signed &, char signed ),                    ?<<=?( volatile char signed &, char signed );
     
    547540unsigned long long int  ?<<=?( unsigned long long int &, unsigned long long int ), ?<<=?( volatile unsigned long long int &, unsigned long long int );
    548541
    549 _Bool                   ?>>=?( _Bool &, _Bool ),                                ?>>=?( volatile _Bool &, _Bool );
    550542char                    ?>>=?( char &, char ),                                  ?>>=?( volatile char &, char );
    551543char signed             ?>>=?( char signed &, char signed ),                    ?>>=?( volatile char signed &, char signed );
     
    736728forall( dtype DT ) void ?{}(       volatile  DT *          &,                   DT * );
    737729forall( dtype DT ) void ?{}(       volatile  DT *          &,       volatile    DT * );
    738 
    739730forall( dtype DT ) void ?{}( const volatile  DT *          &,                   DT * );
    740731forall( dtype DT ) void ?{}( const volatile  DT *          &, const             DT * );
  • libcfa/prelude/prototypes.awk

    rf9feab8 r90152a4  
    55# file "LICENCE" distributed with Cforall.
    66#
    7 # prototypes.awk -- 
     7# prototypes.awk --
    88#
    99# Author           : Peter A. Buhr
     
    1212# Last Modified On : Tue Jul  5 14:32:52 2016
    1313# Update Count     : 32
    14 # 
     14#
    1515
    1616# http://llvm.org/svn/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def
     
    8383} # BEGIN
    8484
    85 /BT_FN/ { 
     85/BT_FN/ {
    8686    for (i = 1; i <= NF; i++) {
    8787      if( match($i, "BT_FN") != 0 ) {
     
    116116
    117117      # generate function return type as macro
    118       for ( t = 0; t < N; t += 1 ) {                                    # find longest match 
     118      for ( t = 0; t < N; t += 1 ) {                                    # find longest match
    119119        type = types[t];
    120120        if ( index( prototype, type ) == 1 ) {          # found match
     
    150150        # extras
    151151        printf( "\n#include \"builtins.def\"\n\n" );
     152        printf( "\n#include \"sync-builtins.cf\"\n\n" );
    152153        printf( "extern const char *__PRETTY_FUNCTION__;\n" );
    153154} # END
  • libcfa/src/assert.cfa

    rf9feab8 r90152a4  
    1717#include <stdarg.h>                                                             // varargs
    1818#include <stdio.h>                                                              // fprintf
    19 #include "bits/debug.h"
     19#include "bits/debug.hfa"
    2020
    2121extern "C" {
    2222        extern const char * __progname;                                         // global name of running executable (argv[0])
    2323
    24         #define CFA_ASSERT_FMT "Cforall Assertion error from program \"%s\" in \"%s\" at line %d in file \"%s\""
     24        #define CFA_ASSERT_FMT "Cforall Assertion error \"%s\" from program \"%s\" in \"%s\" at line %d in file \"%s\""
    2525
    2626        // called by macro assert in assert.h
    2727        void __assert_fail( const char *assertion, const char *file, unsigned int line, const char *function ) {
    28                 __cfaabi_dbg_bits_print_safe( CFA_ASSERT_FMT ".\n", __progname, function, line, file );
     28                __cfaabi_dbg_bits_print_safe( CFA_ASSERT_FMT ".\n", assertion, __progname, function, line, file );
    2929                abort();
    3030        }
     
    3333        void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) {
    3434                __cfaabi_dbg_bits_acquire();
    35                 __cfaabi_dbg_bits_print_nolock( CFA_ASSERT_FMT ": ", __progname, function, line, file );
     35                __cfaabi_dbg_bits_print_nolock( CFA_ASSERT_FMT ": ", assertion, __progname, function, line, file );
    3636
    3737                va_list args;
  • libcfa/src/bits/algorithm.hfa

    rf9feab8 r90152a4  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // bits/algorithms.h -- Builtins for exception handling.
     7// bits/algorithms.hfa -- Builtins for exception handling.
    88//
    99// Author           : Thierry Delisle
  • libcfa/src/bits/align.hfa

    rf9feab8 r90152a4  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // align.h --
     7// align.hfa --
    88//
    99// Author           : Thierry Delisle
  • libcfa/src/bits/containers.hfa

    rf9feab8 r90152a4  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // bits/containers.h -- Intrusive generic containers.h
     7// bits/containers.hfa -- Intrusive generic containers.hfa
    88//
    99// Author           : Thierry Delisle
     
    1515#pragma once
    1616
    17 #include "bits/align.h"
    18 #include "bits/defs.h"
     17#include "bits/align.hfa"
     18#include "bits/defs.hfa"
    1919
    2020//-----------------------------------------------------------------------------
     
    140140
    141141#ifdef __cforall
     142
    142143        forall(dtype T | is_node(T))
    143         static inline void ?{}( __queue(T) & this ) {
    144                 (this.head){ NULL };
    145                 (this.tail){ &this.head };
    146         }
    147 
    148         forall(dtype T | is_node(T) | sized(T))
    149         static inline void append( __queue(T) & this, T * val ) {
    150                 verify(this.tail != NULL);
    151                 *this.tail = val;
    152                 this.tail = &get_next( *val );
     144        static inline void ?{}( __queue(T) & this ) with( this ) {
     145                head{ NULL };
     146                tail{ &head };
     147        }
     148
     149        forall(dtype T | is_node(T) | sized(T))
     150        static inline void append( __queue(T) & this, T * val ) with( this ) {
     151                verify(tail != NULL);
     152                *tail = val;
     153                tail = &get_next( *val );
    153154        }
    154155
     
    167168
    168169        forall(dtype T | is_node(T) | sized(T))
    169         static inline T * remove( __queue(T) & this, T ** it ) {
     170        static inline T * remove( __queue(T) & this, T ** it ) with( this ) {
    170171                T * val = *it;
    171172                verify( val );
     
    173174                (*it) = get_next( *val );
    174175
    175                 if( this.tail == &get_next( *val ) ) {
    176                         this.tail = it;
     176                if( tail == &get_next( *val ) ) {
     177                        tail = it;
    177178                }
    178179
    179180                get_next( *val ) = NULL;
    180181
    181                 verify( (this.head == NULL) == (&this.head == this.tail) );
    182                 verify( *this.tail == NULL );
     182                verify( (head == NULL) == (&head == tail) );
     183                verify( *tail == NULL );
    183184                return val;
    184185        }
    185 #endif
     186
     187        forall(dtype T | is_node(T))
     188        static inline bool ?!=?( __queue(T) & this, zero_t zero ) {
     189                return this.head != 0;
     190        }
     191#endif
     192
     193
     194//-----------------------------------------------------------------------------
     195// Doubly Linked List
     196//-----------------------------------------------------------------------------
     197#ifdef __cforall
     198        forall(dtype TYPE | sized(TYPE))
     199        #define T TYPE
     200        #define __getter_t * [T * & next, T * & prev] ( T & )
     201#else
     202        typedef void (*__generit_c_getter_t)();
     203        #define T void
     204        #define __getter_t __generit_c_getter_t
     205#endif
     206struct __dllist {
     207        T * head;
     208        __getter_t __get;
     209};
     210#undef T
     211#undef __getter_t
     212
     213#ifdef __cforall
     214#define __dllist_t(T) __dllist(T)
     215#else
     216#define __dllist_t(T) struct __dllist
     217#endif
     218
     219#ifdef __cforall
     220
     221        forall(dtype T | sized(T))
     222        static inline [void] ?{}( __dllist(T) & this, * [T * & next, T * & prev] ( T & ) __get ) {
     223                this.head{ NULL };
     224                this.__get = __get;
     225        }
     226
     227        #define next 0
     228        #define prev 1
     229        forall(dtype T | sized(T))
     230        static inline void push_front( __dllist(T) & this, T & node ) with( this ) {
     231                verify(__get);
     232                if ( head ) {
     233                        __get( node ).next = head;
     234                        __get( node ).prev = __get( *head ).prev;
     235                        // inserted node must be consistent before it is seen
     236                        // prevent code movement across barrier
     237                        asm( "" : : : "memory" );
     238                        __get( *head ).prev = &node;
     239                        T & _prev = *__get( node ).prev;
     240                        __get( _prev ).next = &node;
     241                }
     242                else {
     243                        __get( node ).next = &node;
     244                        __get( node ).prev = &node;
     245                }
     246
     247                // prevent code movement across barrier
     248                asm( "" : : : "memory" );
     249                head = &node;
     250        }
     251
     252        forall(dtype T | sized(T))
     253        static inline void remove( __dllist(T) & this, T & node ) with( this ) {
     254                verify(__get);
     255                if ( &node == head ) {
     256                        if ( __get( *head ).next == head ) {
     257                                head = NULL;
     258                        }
     259                        else {
     260                                head = __get( *head ).next;
     261                        }
     262                }
     263                __get( *__get( node ).next ).prev = __get( node ).prev;
     264                __get( *__get( node ).prev ).next = __get( node ).next;
     265                __get( node ).next = NULL;
     266                __get( node ).prev = NULL;
     267        }
     268
     269        forall(dtype T | sized(T))
     270        static inline bool ?!=?( __dllist(T) & this, zero_t zero ) {
     271                return this.head != 0;
     272        }
     273        #undef next
     274        #undef prev
     275#endif
     276
     277//-----------------------------------------------------------------------------
     278// Tools
     279//-----------------------------------------------------------------------------
     280#ifdef __cforall
     281
     282#endif
  • libcfa/src/bits/debug.cfa

    rf9feab8 r90152a4  
    1111// Last Modified By :
    1212// Last Modified On :
    13 // Update Count     : 0
     13// Update Count     : 1
    1414//
    1515
     
    4747        void __cfaabi_dbg_bits_release() __attribute__((__weak__)) {}
    4848
    49         void __cfaabi_dbg_bits_print_safe  ( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) )) {
     49        void __cfaabi_dbg_bits_print_safe  ( const char fmt[], ... ) __attribute__(( format(printf, 1, 2) )) {
    5050                va_list args;
    5151
     
    6060        }
    6161
    62         void __cfaabi_dbg_bits_print_nolock( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) )) {
     62        void __cfaabi_dbg_bits_print_nolock( const char fmt[], ... ) __attribute__(( format(printf, 1, 2) )) {
    6363                va_list args;
    6464
     
    7676        }
    7777
    78         void __cfaabi_dbg_bits_print_buffer( char in_buffer[], int in_buffer_size, const char fmt[], ... ) __attribute__(( format (printf, 3, 4) )) {
     78        void __cfaabi_dbg_bits_print_buffer( char in_buffer[], int in_buffer_size, const char fmt[], ... ) __attribute__(( format(printf, 3, 4) )) {
    7979                va_list args;
    8080
  • libcfa/src/bits/debug.hfa

    rf9feab8 r90152a4  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // debug.h --
     7// debug.hfa --
    88//
    99// Author           : Thierry Delisle
    1010// Created On       : Mon Nov 28 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 10:02:24 2017
    13 // Update Count     : 1
     12// Last Modified On : Thu Feb  8 12:35:19 2018
     13// Update Count     : 2
    1414//
    1515
     
    4141      extern void __cfaabi_dbg_bits_acquire();
    4242      extern void __cfaabi_dbg_bits_release();
    43       extern void __cfaabi_dbg_bits_print_safe  ( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) ));
    44       extern void __cfaabi_dbg_bits_print_nolock( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) ));
     43      extern void __cfaabi_dbg_bits_print_safe  ( const char fmt[], ... ) __attribute__(( format(printf, 1, 2) ));
     44      extern void __cfaabi_dbg_bits_print_nolock( const char fmt[], ... ) __attribute__(( format(printf, 1, 2) ));
    4545      extern void __cfaabi_dbg_bits_print_vararg( const char fmt[], va_list arg );
    46       extern void __cfaabi_dbg_bits_print_buffer( char buffer[], int buffer_size, const char fmt[], ... ) __attribute__(( format (printf, 3, 4) ));
     46      extern void __cfaabi_dbg_bits_print_buffer( char buffer[], int buffer_size, const char fmt[], ... ) __attribute__(( format(printf, 3, 4) ));
    4747#ifdef __cforall
    4848}
  • libcfa/src/concurrency/alarm.cfa

    rf9feab8 r90152a4  
    1010// Created On       : Fri Jun 2 11:31:25 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:35:18 2017
    13 // Update Count     : 1
     12// Last Modified On : Fri May 25 06:25:47 2018
     13// Update Count     : 67
    1414//
    1515
     
    1818#include <stdio.h>
    1919#include <string.h>
    20 #include <time.h>
    2120#include <unistd.h>
    2221#include <sys/time.h>
    2322}
    2423
    25 #include "alarm.h"
    26 #include "kernel_private.h"
    27 #include "preemption.h"
    28 
    29 //=============================================================================================
    30 // time type
    31 //=============================================================================================
    32 
    33 #define one_second         1_000_000_000ul
    34 #define one_milisecond         1_000_000ul
    35 #define one_microsecond            1_000ul
    36 #define one_nanosecond                 1ul
    37 
    38 __cfa_time_t zero_time = { 0 };
    39 
    40 void ?{}( __cfa_time_t & this ) { this.val = 0; }
    41 void ?{}( __cfa_time_t & this, zero_t zero ) { this.val = 0; }
    42 
    43 void ?{}( itimerval & this, __cfa_time_t * alarm ) {
    44         this.it_value.tv_sec = alarm->val / one_second;                 // seconds
    45         this.it_value.tv_usec = max( (alarm->val % one_second) / one_microsecond, 1000 ); // microseconds
    46         this.it_interval.tv_sec = 0;
    47         this.it_interval.tv_usec = 0;
    48 }
    49 
    50 
    51 void ?{}( __cfa_time_t & this, timespec * curr ) {
    52         uint64_t secs  = curr->tv_sec;
    53         uint64_t nsecs = curr->tv_nsec;
    54         this.val = (secs * one_second) + nsecs;
    55 }
    56 
    57 __cfa_time_t ?=?( __cfa_time_t & this, zero_t rhs ) {
    58         this.val = 0;
    59         return this;
    60 }
    61 
    62 __cfa_time_t from_s ( uint64_t val ) { __cfa_time_t ret; ret.val = val * 1_000_000_000ul; return ret; }
    63 __cfa_time_t from_ms( uint64_t val ) { __cfa_time_t ret; ret.val = val *     1_000_000ul; return ret; }
    64 __cfa_time_t from_us( uint64_t val ) { __cfa_time_t ret; ret.val = val *         1_000ul; return ret; }
    65 __cfa_time_t from_ns( uint64_t val ) { __cfa_time_t ret; ret.val = val *             1ul; return ret; }
     24#include "alarm.hfa"
     25#include "kernel_private.hfa"
     26#include "preemption.hfa"
    6627
    6728//=============================================================================================
     
    6930//=============================================================================================
    7031
    71 __cfa_time_t __kernel_get_time() {
     32Time __kernel_get_time() {
    7233        timespec curr;
    73         clock_gettime( CLOCK_REALTIME, &curr );
    74         return (__cfa_time_t){ &curr };
     34        clock_gettime( CLOCK_MONOTONIC_RAW, &curr );            // CLOCK_REALTIME
     35        return (Time){ curr };
    7536}
    7637
    77 void __kernel_set_timer( __cfa_time_t alarm ) {
    78         itimerval val = { &alarm };
    79         setitimer( ITIMER_REAL, &val, NULL );
     38void __kernel_set_timer( Duration alarm ) {
     39        verifyf(alarm >= 1`us || alarm == 0, "Setting timer to < 1us (%jins)", alarm.tv);
     40        setitimer( ITIMER_REAL, &(itimerval){ alarm }, NULL );
    8041}
    8142
     
    8445//=============================================================================================
    8546
    86 void ?{}( alarm_node_t & this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) {
     47void ?{}( alarm_node_t & this, thread_desc * thrd, Time alarm, Duration period ) with( this ) {
    8748        this.thrd = thrd;
    8849        this.alarm = alarm;
    8950        this.period = period;
    90         this.next = 0;
    91         this.set = false;
    92         this.kernel_alarm = false;
     51        next = 0;
     52        set = false;
     53        kernel_alarm = false;
    9354}
    9455
    95 void ?{}( alarm_node_t & this, processor   * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) {
     56void ?{}( alarm_node_t & this, processor   * proc, Time alarm, Duration period ) with( this ) {
    9657        this.proc = proc;
    9758        this.alarm = alarm;
    9859        this.period = period;
    99         this.next = 0;
    100         this.set = false;
    101         this.kernel_alarm = true;
     60        next = 0;
     61        set = false;
     62        kernel_alarm = true;
    10263}
    10364
     
    10869}
    10970
    110 __cfaabi_dbg_debug_do( bool validate( alarm_list_t * this ) {
     71#if !defined(NDEBUG) && (defined(__CFA_DEBUG__) || defined(__CFA_VERIFY__))
     72bool validate( alarm_list_t * this ) {
    11173        alarm_node_t ** it = &this->head;
    11274        while( (*it) ) {
     
    11577
    11678        return it == this->tail;
    117 })
     79}
     80#endif
    11881
    11982static inline void insert_at( alarm_list_t * this, alarm_node_t * n, __alarm_it_t p ) {
  • libcfa/src/concurrency/coroutine.hfa

    rf9feab8 r90152a4  
    1010// Created On       : Mon Nov 28 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 30 07:58:29 2017
    13 // Update Count     : 3
     12// Last Modified On : Fri Mar 30 18:23:45 2018
     13// Update Count     : 8
    1414//
    1515
     
    3232//-----------------------------------------------------------------------------
    3333// Ctors and dtors
    34 void ?{}(coStack_t & this);
    35 void ?{}(coroutine_desc & this);
    36 void ?{}(coroutine_desc & this, const char * name);
    37 void ^?{}(coStack_t & this);
    38 void ^?{}(coroutine_desc & this);
     34// void ?{}( coStack_t & this );
     35// void ^?{}( coStack_t & this );
     36
     37void ?{}( coroutine_desc & this, const char * name, void * storage, size_t storageSize );
     38void ^?{}( coroutine_desc & this );
     39
     40static inline void ?{}( coroutine_desc & this)                                       { this{ "Anonymous Coroutine", NULL, 0 }; }
     41static inline void ?{}( coroutine_desc & this, size_t stackSize)                     { this{ "Anonymous Coroutine", NULL, stackSize }; }
     42static inline void ?{}( coroutine_desc & this, void * storage, size_t storageSize )  { this{ "Anonymous Coroutine", storage, storageSize }; }
     43static inline void ?{}( coroutine_desc & this, const char * name)                    { this{ name, NULL, 0 }; }
     44static inline void ?{}( coroutine_desc & this, const char * name, size_t stackSize ) { this{ name, NULL, stackSize }; }
    3945
    4046//-----------------------------------------------------------------------------
     
    6066}
    6167
    62 // Get current coroutine
    63 extern thread_local coroutine_desc * volatile this_coroutine;
    64 
    6568// Private wrappers for context switch and stack creation
    6669extern void CoroutineCtxSwitch(coroutine_desc * src, coroutine_desc * dst);
     
    6972// Suspend implementation inlined for performance
    7073static inline void suspend() {
    71         coroutine_desc * src = this_coroutine;          // optimization
     74        // optimization : read TLS once and reuse it
     75        // Safety note: this is preemption safe since if
     76        // preemption occurs after this line, the pointer
     77        // will also migrate which means this value will
     78        // stay in syn with the TLS
     79        coroutine_desc * src = TL_GET( this_coroutine );
    7280
    7381        assertf( src->last != 0,
     
    8694forall(dtype T | is_coroutine(T))
    8795static inline void resume(T & cor) {
    88         coroutine_desc * src = this_coroutine;          // optimization
     96        // optimization : read TLS once and reuse it
     97        // Safety note: this is preemption safe since if
     98        // preemption occurs after this line, the pointer
     99        // will also migrate which means this value will
     100        // stay in syn with the TLS
     101        coroutine_desc * src = TL_GET( this_coroutine );
    89102        coroutine_desc * dst = get_coroutine(cor);
    90103
     
    104117                dst->last = src;
    105118                dst->starter = dst->starter ? dst->starter : src;
    106         } // if
     119        }
    107120
    108121        // always done for performance testing
     
    111124
    112125static inline void resume(coroutine_desc * dst) {
    113         coroutine_desc * src = this_coroutine;          // optimization
     126        // optimization : read TLS once and reuse it
     127        // Safety note: this is preemption safe since if
     128        // preemption occurs after this line, the pointer
     129        // will also migrate which means this value will
     130        // stay in syn with the TLS
     131        coroutine_desc * src = TL_GET( this_coroutine );
    114132
    115133        // not resuming self ?
     
    122140                // set last resumer
    123141                dst->last = src;
    124         } // if
     142        }
    125143
    126144        // always done for performance testing
  • libcfa/src/concurrency/invoke.c

    rf9feab8 r90152a4  
    1010// Created On       : Tue Jan 17 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:28:33 2017
    13 // Update Count     : 1
     12// Last Modified On : Fri Feb  9 16:37:42 2018
     13// Update Count     : 5
    1414//
    1515
     
    2828extern void __suspend_internal(void);
    2929extern void __leave_coroutine(void);
     30extern void __finish_creation(void);
    3031extern void __leave_thread_monitor( struct thread_desc * this );
    3132extern void disable_interrupts();
     
    4546        cor->state = Active;
    4647
     48        enable_interrupts( __cfaabi_dbg_ctx );
     49
    4750        main( this );
    4851
     
    5154        //Final suspend, should never return
    5255        __leave_coroutine();
    53         abortf("Resumed dead coroutine");
     56        __cabi_abort( "Resumed dead coroutine" );
    5457}
    5558
     
    6265        // First suspend, once the thread arrives here,
    6366        // the function pointer to main can be invalidated without risk
    64         __suspend_internal();
     67        __finish_creation();
    6568
    6669        // Fetch the thread handle from the user defined thread structure
    6770        struct thread_desc* thrd = get_thread( this );
     71        thrd->self_cor.last = NULL;
    6872
    6973        // Officially start the thread by enabling preemption
     
    8185        //Final suspend, should never return
    8286        __leave_thread_monitor( thrd );
    83         abortf("Resumed dead thread");
     87        __cabi_abort( "Resumed dead thread" );
    8488}
    8589
     
    9397        struct coStack_t* stack = &get_coroutine( this )->stack;
    9498
    95 #if defined( __i386__ )
     99#if defined( __i386 )
    96100
    97101        struct FakeStack {
     
    114118        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7
    115119
    116 #elif defined( __x86_64__ )
     120#elif defined( __x86_64 )
    117121
    118122        struct FakeStack {
     
    133137        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520
    134138        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7
     139
     140#elif defined( __ARM_ARCH )
     141
     142        struct FakeStack {
     143                float fpRegs[16];                       // floating point registers
     144                void *intRegs[9];                       // integer/pointer registers
     145                void *arg[2];                           // placeholder for this pointer
     146        };
     147
     148        ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );
     149        ((struct machine_context_t *)stack->context)->FP = NULL;
     150
     151        struct FakeStack *fs = (struct FakeStack *)((struct machine_context_t *)stack->context)->SP;
     152
     153        fs->intRegs[8] = CtxInvokeStub;
     154        fs->arg[0] = this;
     155        fs->arg[1] = invoke;
     156
    135157#else
    136         #error Only __i386__ and __x86_64__ is supported for threads in cfa
     158        #error uknown hardware architecture
    137159#endif
    138160}
  • libcfa/src/concurrency/invoke.h

    rf9feab8 r90152a4  
    1010// Created On       : Tue Jan 17 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:28:56 2017
    13 // Update Count     : 1
    14 //
    15 
    16 #include "bits/containers.h"
    17 #include "bits/defs.h"
    18 #include "bits/locks.h"
     12// Last Modified On : Sat May 19 08:23:21 2018
     13// Update Count     : 31
     14//
     15
     16#include "bits/containers.hfa"
     17#include "bits/defs.hfa"
     18#include "bits/locks.hfa"
    1919
    2020#ifdef __cforall
     
    2525#ifndef _INVOKE_H_
    2626#define _INVOKE_H_
     27
     28#ifdef __ARM_ARCH
     29        // function prototypes are only really used by these macros on ARM
     30        void disable_global_interrupts();
     31        void enable_global_interrupts();
     32
     33        #define TL_GET( member ) ( { __typeof__( kernelTLS.member ) target; \
     34                disable_global_interrupts(); \
     35                target = kernelTLS.member; \
     36                enable_global_interrupts(); \
     37                target; } )
     38        #define TL_SET( member, value ) disable_global_interrupts(); \
     39                kernelTLS.member = value; \
     40                enable_global_interrupts();
     41#else
     42        #define TL_GET( member ) kernelTLS.member
     43        #define TL_SET( member, value ) kernelTLS.member = value;
     44#endif
    2745
    2846        #ifdef __cforall
     
    3048                static inline struct thread_desc             * & get_next( struct thread_desc             & this );
    3149                static inline struct __condition_criterion_t * & get_next( struct __condition_criterion_t & this );
     50
     51                extern thread_local struct KernelThreadData {
     52                        struct coroutine_desc * volatile this_coroutine;
     53                        struct thread_desc    * volatile this_thread;
     54                        struct processor      * volatile this_processor;
     55
     56                        struct {
     57                                volatile unsigned short disable_count;
     58                                volatile bool enabled;
     59                                volatile bool in_progress;
     60                        } preemption_state;
     61                } kernelTLS;
    3262        }
     63
     64        static inline struct coroutine_desc * volatile active_coroutine() { return TL_GET( this_coroutine ); }
     65        static inline struct thread_desc    * volatile active_thread   () { return TL_GET( this_thread    ); }
     66        static inline struct processor      * volatile active_processor() { return TL_GET( this_processor ); } // UNSAFE
    3367        #endif
    3468
    3569        struct coStack_t {
    36                 // size of stack
    37                 size_t size;
    38 
    39                 // pointer to stack
    40                 void *storage;
    41 
    42                 // stack grows towards stack limit
    43                 void *limit;
    44 
    45                 // base of stack
    46                 void *base;
    47 
    48                 // address of cfa_context_t
    49                 void *context;
    50 
    51                 // address of top of storage
    52                 void *top;
    53 
    54                 // whether or not the user allocated the stack
    55                 bool userStack;
     70                size_t size;                                                                    // size of stack
     71                void * storage;                                                                 // pointer to stack
     72                void * limit;                                                                   // stack grows towards stack limit
     73                void * base;                                                                    // base of stack
     74                void * context;                                                                 // address of cfa_context_t
     75                void * top;                                                                             // address of top of storage
     76                bool userStack;                                                                 // whether or not the user allocated the stack
    5677        };
    5778
     
    5980
    6081        struct coroutine_desc {
    61                 // stack information of the coroutine
    62                 struct coStack_t stack;
    63 
    64                 // textual name for coroutine/task, initialized by uC++ generated code
    65                 const char *name;
    66 
    67                 // copy of global UNIX variable errno
    68                 int errno_;
    69 
    70                 // current execution status for coroutine
    71                 enum coroutine_state state;
    72 
    73                 // first coroutine to resume this one
    74                 struct coroutine_desc * starter;
    75 
    76                 // last coroutine to resume this one
    77                 struct coroutine_desc * last;
     82                struct coStack_t stack;                                                 // stack information of the coroutine
     83                const char * name;                                                              // textual name for coroutine/task, initialized by uC++ generated code
     84                int errno_;                                                                             // copy of global UNIX variable errno
     85                enum coroutine_state state;                                             // current execution status for coroutine
     86                struct coroutine_desc * starter;                                // first coroutine to resume this one
     87                struct coroutine_desc * last;                                   // last coroutine to resume this one
    7888        };
    7989
     
    8393
    8494                // list of acceptable functions, null if any
    85                 __small_array_t(struct __acceptable_t) __cfa_anonymous_object;
     95                __cfa_anonymous_object( __small_array_t(struct __acceptable_t) );
    8696        };
    8797
     
    111121        struct __monitor_group_t {
    112122                // currently held monitors
    113                 __small_array_t(monitor_desc*) __cfa_anonymous_object;
     123                __cfa_anonymous_object( __small_array_t(monitor_desc*) );
    114124
    115125                // last function that acquired monitors
     
    122132                struct coroutine_desc  self_cor;
    123133
     134                // current active context
     135                struct coroutine_desc * curr_cor;
     136
    124137                // monitor body used for mutual exclusion
    125138                struct monitor_desc    self_mon;
     
    127140                // pointer to monitor with sufficient lifetime for current monitors
    128141                struct monitor_desc *  self_mon_p;
     142
     143                // pointer to the cluster on which the thread is running
     144                struct cluster * curr_cluster;
    129145
    130146                // monitors currently held by this thread
     
    134150                // instrusive link field for threads
    135151                struct thread_desc * next;
     152
     153                struct {
     154                        struct thread_desc * next;
     155                        struct thread_desc * prev;
     156                } node;
    136157     };
    137158
     
    140161                static inline thread_desc * & get_next( thread_desc & this ) {
    141162                        return this.next;
     163                }
     164
     165                static inline [thread_desc *&, thread_desc *& ] __get( thread_desc & this ) {
     166                        return this.node.[next, prev];
    142167                }
    143168
     
    193218        void CtxSwitch( void * from, void * to ) asm ("CtxSwitch");
    194219
    195         #if   defined( __x86_64__ )
     220        #if   defined( __i386 )
     221        #define CtxGet( ctx ) __asm__ ( \
     222                        "movl %%esp,%0\n"   \
     223                        "movl %%ebp,%1\n"   \
     224                : "=rm" (ctx.SP), "=rm" (ctx.FP) )
     225        #elif defined( __x86_64 )
    196226        #define CtxGet( ctx ) __asm__ ( \
    197227                        "movq %%rsp,%0\n"   \
    198228                        "movq %%rbp,%1\n"   \
    199229                : "=rm" (ctx.SP), "=rm" (ctx.FP) )
    200         #elif defined( __i386__ )
     230        #elif defined( __ARM_ARCH )
    201231        #define CtxGet( ctx ) __asm__ ( \
    202                         "movl %%esp,%0\n"   \
    203                         "movl %%ebp,%1\n"   \
     232                        "mov %0,%%sp\n"   \
     233                        "mov %1,%%r11\n"   \
    204234                : "=rm" (ctx.SP), "=rm" (ctx.FP) )
     235        #else
     236                #error unknown hardware architecture
    205237        #endif
    206238
  • libcfa/src/concurrency/kernel.hfa

    rf9feab8 r90152a4  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:58:39 2017
    13 // Update Count     : 2
     12// Last Modified On : Tue Apr 10 14:46:49 2018
     13// Update Count     : 10
    1414//
    1515
     
    1919
    2020#include "invoke.h"
     21#include "time_t.hfa"
    2122
    2223extern "C" {
    2324#include <pthread.h>
     25#include <semaphore.h>
    2426}
    2527
     
    3941
    4042//-----------------------------------------------------------------------------
     43// Processor
     44extern struct cluster * mainCluster;
     45
     46enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule, Callback };
     47
     48typedef void (*__finish_callback_fptr_t)(void);
     49
     50//TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI)
     51struct FinishAction {
     52        FinishOpCode action_code;
     53        /*
     54        // Union of possible actions
     55        union {
     56                // Option 1 : locks and threads
     57                struct {
     58                        // 1 thread or N thread
     59                        union {
     60                                thread_desc * thrd;
     61                                struct {
     62                                        thread_desc ** thrds;
     63                                        unsigned short thrd_count;
     64                                };
     65                        };
     66                        // 1 lock or N lock
     67                        union {
     68                                __spinlock_t * lock;
     69                                struct {
     70                                        __spinlock_t ** locks;
     71                                        unsigned short lock_count;
     72                                };
     73                        };
     74                };
     75                // Option 2 : action pointer
     76                __finish_callback_fptr_t callback;
     77        };
     78        /*/
     79        thread_desc * thrd;
     80        thread_desc ** thrds;
     81        unsigned short thrd_count;
     82        __spinlock_t * lock;
     83        __spinlock_t ** locks;
     84        unsigned short lock_count;
     85        __finish_callback_fptr_t callback;
     86        //*/
     87};
     88static inline void ?{}(FinishAction & this) {
     89        this.action_code = No_Action;
     90        this.thrd = NULL;
     91        this.lock = NULL;
     92}
     93static inline void ^?{}(FinishAction & this) {}
     94
     95// Processor
     96coroutine processorCtx_t {
     97        struct processor * proc;
     98};
     99
     100// Wrapper around kernel threads
     101struct processor {
     102        // Main state
     103        // Coroutine ctx who does keeps the state of the processor
     104        struct processorCtx_t runner;
     105
     106        // Cluster from which to get threads
     107        struct cluster * cltr;
     108
     109        // Name of the processor
     110        const char * name;
     111
     112        // Handle to pthreads
     113        pthread_t kernel_thread;
     114
     115        // RunThread data
     116        // Action to do after a thread is ran
     117        struct FinishAction finish;
     118
     119        // Preemption data
     120        // Node which is added in the discrete event simulaiton
     121        struct alarm_node_t * preemption_alarm;
     122
     123        // If true, a preemption was triggered in an unsafe region, the processor must preempt as soon as possible
     124        bool pending_preemption;
     125
     126        // Idle lock
     127        __bin_sem_t idleLock;
     128
     129        // Termination
     130        // Set to true to notify the processor should terminate
     131        volatile bool do_terminate;
     132
     133        // Termination synchronisation
     134        semaphore terminated;
     135
     136        // Link lists fields
     137        struct __dbg_node_proc {
     138                struct processor * next;
     139                struct processor * prev;
     140        } node;
     141
     142#ifdef __CFA_DEBUG__
     143        // Last function to enable preemption on this processor
     144        const char * last_enable;
     145#endif
     146};
     147
     148void  ?{}(processor & this, const char * name, struct cluster & cltr);
     149void ^?{}(processor & this);
     150
     151static inline void  ?{}(processor & this)                    { this{ "Anonymous Processor", *mainCluster}; }
     152static inline void  ?{}(processor & this, struct cluster & cltr)    { this{ "Anonymous Processor", cltr}; }
     153static inline void  ?{}(processor & this, const char * name) { this{name, *mainCluster }; }
     154
     155static inline [processor *&, processor *& ] __get( processor & this ) {
     156        return this.node.[next, prev];
     157}
     158
     159//-----------------------------------------------------------------------------
    41160// Cluster
    42161struct cluster {
     
    47166        __queue_t(thread_desc) ready_queue;
    48167
     168        // Name of the cluster
     169        const char * name;
     170
    49171        // Preemption rate on this cluster
    50         unsigned long long int preemption;
    51 };
    52 
    53 void ?{} (cluster & this);
     172        Duration preemption_rate;
     173
     174        // List of processors
     175        __spinlock_t proc_list_lock;
     176        __dllist_t(struct processor) procs;
     177        __dllist_t(struct processor) idles;
     178
     179        // List of processors
     180        __spinlock_t thread_list_lock;
     181        __dllist_t(struct thread_desc) threads;
     182
     183        // Link lists fields
     184        struct __dbg_node_cltr {
     185                cluster * next;
     186                cluster * prev;
     187        } node;
     188};
     189extern Duration default_preemption();
     190
     191void ?{} (cluster & this, const char * name, Duration preemption_rate);
    54192void ^?{}(cluster & this);
    55193
    56 //-----------------------------------------------------------------------------
    57 // Processor
    58 enum 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)
    61 struct FinishAction {
    62         FinishOpCode action_code;
    63         thread_desc * thrd;
    64         __spinlock_t * lock;
    65         __spinlock_t ** locks;
    66         unsigned short lock_count;
    67         thread_desc ** thrds;
    68         unsigned short thrd_count;
    69 };
    70 static inline void ?{}(FinishAction & this) {
    71         this.action_code = No_Action;
    72         this.thrd = NULL;
    73         this.lock = NULL;
    74 }
    75 static inline void ^?{}(FinishAction & this) {}
    76 
    77 // Processor
    78 // Wrapper around kernel threads
    79 struct processor {
    80         // Main state
    81         // Coroutine ctx who does keeps the state of the processor
    82         struct processorCtx_t * runner;
    83 
    84         // Cluster from which to get threads
    85         cluster * cltr;
    86 
    87         // Handle to pthreads
    88         pthread_t kernel_thread;
    89 
    90         // Termination
    91         // Set to true to notify the processor should terminate
    92         volatile bool do_terminate;
    93 
    94         // Termination synchronisation
    95         semaphore terminated;
    96 
    97         // RunThread data
    98         // Action to do after a thread is ran
    99         struct FinishAction finish;
    100 
    101         // Preemption data
    102         // Node which is added in the discrete event simulaiton
    103         struct alarm_node_t * preemption_alarm;
    104 
    105         // If true, a preemption was triggered in an unsafe region, the processor must preempt as soon as possible
    106         bool pending_preemption;
    107 
    108 #ifdef __CFA_DEBUG__
    109         // Last function to enable preemption on this processor
    110         const char * last_enable;
    111 #endif
    112 };
    113 
    114 void  ?{}(processor & this);
    115 void  ?{}(processor & this, cluster * cltr);
    116 void ^?{}(processor & this);
     194static inline void ?{} (cluster & this)                           { this{"Anonymous Cluster", default_preemption()}; }
     195static inline void ?{} (cluster & this, Duration preemption_rate) { this{"Anonymous Cluster", preemption_rate}; }
     196static inline void ?{} (cluster & this, const char * name)        { this{name, default_preemption()}; }
     197
     198static inline [cluster *&, cluster *& ] __get( cluster & this ) {
     199        return this.node.[next, prev];
     200}
    117201
    118202// Local Variables: //
  • libcfa/src/concurrency/kernel_private.hfa

    rf9feab8 r90152a4  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // kernel_private.h --
     7// kernel_private.hfa --
    88//
    99// Author           : Thierry Delisle
    1010// Created On       : Mon Feb 13 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:58:09 2017
    13 // Update Count     : 2
     12// Last Modified On : Thu Mar 29 14:06:40 2018
     13// Update Count     : 3
    1414//
    1515
    1616#pragma once
    1717
    18 #include "kernel"
    19 #include "thread"
     18#include "kernel.hfa"
     19#include "thread.hfa"
    2020
    21 #include "alarm.h"
     21#include "alarm.hfa"
    2222
    2323
     
    4848void BlockInternal(__spinlock_t * locks [], unsigned short count);
    4949void BlockInternal(__spinlock_t * locks [], unsigned short count, thread_desc * thrds [], unsigned short thrd_count);
     50void BlockInternal(__finish_callback_fptr_t callback);
    5051void LeaveThread(__spinlock_t * lock, thread_desc * thrd);
    5152
    5253//-----------------------------------------------------------------------------
    5354// Processor
    54 coroutine processorCtx_t {
    55         processor * proc;
    56 };
     55void main(processorCtx_t *);
    5756
    58 void main(processorCtx_t *);
    59 void start(processor * this);
    60 void runThread(processor * this, thread_desc * dst);
    61 void finishRunning(processor * this);
    62 void spin(processor * this, unsigned int * spin_count);
     57static inline void wake_fast(processor * this) {
     58        __cfaabi_dbg_print_safe("Kernel : Waking up processor %p\n", this);
     59        post( this->idleLock );
     60}
     61
     62static inline void wake(processor * this) {
     63        disable_interrupts();
     64        wake_fast(this);
     65        enable_interrupts( __cfaabi_dbg_ctx );
     66}
    6367
    6468struct event_kernel_t {
     
    6973extern event_kernel_t * event_kernel;
    7074
    71 extern thread_local coroutine_desc * volatile this_coroutine;
    72 extern thread_local thread_desc *    volatile this_thread;
    73 extern thread_local processor *      volatile this_processor;
     75struct __cfa_kernel_preemption_state_t {
     76        bool enabled;
     77        bool in_progress;
     78        unsigned short disable_count;
     79};
    7480
    75 extern volatile thread_local bool preemption_in_progress;
    76 extern volatile thread_local unsigned short disable_preempt_count;
     81extern volatile thread_local __cfa_kernel_preemption_state_t preemption_state;
    7782
    7883//-----------------------------------------------------------------------------
     
    8590extern void ThreadCtxSwitch(coroutine_desc * src, coroutine_desc * dst);
    8691
     92__cfaabi_dbg_debug_do(
     93        extern void __cfaabi_dbg_thread_register  ( thread_desc * thrd );
     94        extern void __cfaabi_dbg_thread_unregister( thread_desc * thrd );
     95)
     96
    8797//-----------------------------------------------------------------------------
    8898// Utils
    8999#define KERNEL_STORAGE(T,X) static char storage_##X[sizeof(T)]
     100
     101
     102void doregister( struct cluster & cltr );
     103void unregister( struct cluster & cltr );
     104
     105void doregister( struct cluster * cltr, struct thread_desc & thrd );
     106void unregister( struct cluster * cltr, struct thread_desc & thrd );
     107
     108void doregister( struct cluster * cltr, struct processor * proc );
     109void unregister( struct cluster * cltr, struct processor * proc );
    90110
    91111// Local Variables: //
  • libcfa/src/concurrency/monitor.cfa

    rf9feab8 r90152a4  
    1010// Created On       : Thd Feb 23 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jul 31 14:59:05 2017
    13 // Update Count     : 3
     12// Last Modified On : Fri Mar 30 14:30:26 2018
     13// Update Count     : 9
    1414//
    1515
    16 #include "monitor"
    17 
    18 #include <stdlib>
     16#include "monitor.hfa"
     17
     18#include <stdlib.hfa>
    1919#include <inttypes.h>
    2020
    21 #include "kernel_private.h"
    22 
    23 #include "bits/algorithms.h"
     21#include "kernel_private.hfa"
     22
     23#include "bits/algorithm.hfa"
    2424
    2525//-----------------------------------------------------------------------------
     
    5353static inline __lock_size_t aggregate    ( monitor_desc * storage [], const __waitfor_mask_t & mask );
    5454
    55 #ifndef __CFA_LOCK_NO_YIELD
    56 #define DO_LOCK lock_yield
    57 #else
    58 #define DO_LOCK lock
    59 #endif
    60 
    6155//-----------------------------------------------------------------------------
    6256// Useful defines
     
    9084        static void __enter_monitor_desc( monitor_desc * this, const __monitor_group_t & group ) {
    9185                // Lock the monitor spinlock
    92                 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
    93                 thread_desc * thrd = this_thread;
    94 
    95                 __cfaabi_dbg_print_safe("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
     86                lock( this->lock __cfaabi_dbg_ctx2 );
     87                // Interrupts disable inside critical section
     88                thread_desc * thrd = kernelTLS.this_thread;
     89
     90                __cfaabi_dbg_print_safe( "Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
    9691
    9792                if( !this->owner ) {
     
    9994                        set_owner( this, thrd );
    10095
    101                         __cfaabi_dbg_print_safe("Kernel :  mon is free \n");
     96                        __cfaabi_dbg_print_safe( "Kernel :  mon is free \n" );
    10297                }
    10398                else if( this->owner == thrd) {
     
    105100                        this->recursion += 1;
    106101
    107                         __cfaabi_dbg_print_safe("Kernel :  mon already owned \n");
     102                        __cfaabi_dbg_print_safe( "Kernel :  mon already owned \n" );
    108103                }
    109104                else if( is_accepted( this, group) ) {
     
    114109                        reset_mask( this );
    115110
    116                         __cfaabi_dbg_print_safe("Kernel :  mon accepts \n");
     111                        __cfaabi_dbg_print_safe( "Kernel :  mon accepts \n" );
    117112                }
    118113                else {
    119                         __cfaabi_dbg_print_safe("Kernel :  blocking \n");
     114                        __cfaabi_dbg_print_safe( "Kernel :  blocking \n" );
    120115
    121116                        // Some one else has the monitor, wait in line for it
    122117                        append( this->entry_queue, thrd );
     118
    123119                        BlockInternal( &this->lock );
    124120
    125                         __cfaabi_dbg_print_safe("Kernel : %10p Entered  mon %p\n", thrd, this);
     121                        __cfaabi_dbg_print_safe( "Kernel : %10p Entered  mon %p\n", thrd, this);
    126122
    127123                        // BlockInternal will unlock spinlock, no need to unlock ourselves
     
    129125                }
    130126
    131                 __cfaabi_dbg_print_safe("Kernel : %10p Entered  mon %p\n", thrd, this);
     127                __cfaabi_dbg_print_safe( "Kernel : %10p Entered  mon %p\n", thrd, this);
    132128
    133129                // Release the lock and leave
     
    138134        static void __enter_monitor_dtor( monitor_desc * this, fptr_t func ) {
    139135                // Lock the monitor spinlock
    140                 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
    141                 thread_desc * thrd = this_thread;
    142 
    143                 __cfaabi_dbg_print_safe("Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner);
     136                lock( this->lock __cfaabi_dbg_ctx2 );
     137                // Interrupts disable inside critical section
     138                thread_desc * thrd = kernelTLS.this_thread;
     139
     140                __cfaabi_dbg_print_safe( "Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner);
    144141
    145142
    146143                if( !this->owner ) {
    147                         __cfaabi_dbg_print_safe("Kernel : Destroying free mon %p\n", this);
     144                        __cfaabi_dbg_print_safe( "Kernel : Destroying free mon %p\n", this);
    148145
    149146                        // No one has the monitor, just take it
     
    156153                        // We already have the monitor... but where about to destroy it so the nesting will fail
    157154                        // Abort!
    158                         abortf("Attempt to destroy monitor %p by thread \"%.256s\" (%p) in nested mutex.");
     155                        abort( "Attempt to destroy monitor %p by thread \"%.256s\" (%p) in nested mutex.", this, thrd->self_cor.name, thrd );
    159156                }
    160157
     
    163160                __monitor_group_t group = { &this, 1, func };
    164161                if( is_accepted( this, group) ) {
    165                         __cfaabi_dbg_print_safe("Kernel :  mon accepts dtor, block and signal it \n");
     162                        __cfaabi_dbg_print_safe( "Kernel :  mon accepts dtor, block and signal it \n" );
    166163
    167164                        // Wake the thread that is waiting for this
     
    173170
    174171                        // Create the node specific to this wait operation
    175                         wait_ctx_primed( this_thread, 0 )
     172                        wait_ctx_primed( thrd, 0 )
    176173
    177174                        // Some one else has the monitor, wait for him to finish and then run
     
    182179                }
    183180                else {
    184                         __cfaabi_dbg_print_safe("Kernel :  blocking \n");
    185 
    186                         wait_ctx( this_thread, 0 )
     181                        __cfaabi_dbg_print_safe( "Kernel :  blocking \n" );
     182
     183                        wait_ctx( thrd, 0 )
    187184                        this->dtor_node = &waiter;
    188185
     
    195192                }
    196193
    197                 __cfaabi_dbg_print_safe("Kernel : Destroying %p\n", this);
     194                __cfaabi_dbg_print_safe( "Kernel : Destroying %p\n", this);
    198195
    199196        }
     
    201198        // Leave single monitor
    202199        void __leave_monitor_desc( monitor_desc * this ) {
    203                 // Lock the monitor spinlock, DO_LOCK to reduce contention
    204                 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
    205 
    206                 __cfaabi_dbg_print_safe("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner);
    207 
    208                 verifyf( this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", this_thread, this->owner, this->recursion, this );
     200                // Lock the monitor spinlock
     201                lock( this->lock __cfaabi_dbg_ctx2 );
     202
     203                __cfaabi_dbg_print_safe( "Kernel : %10p Leaving mon %p (%p)\n", kernelTLS.this_thread, this, this->owner);
     204
     205                verifyf( kernelTLS.this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", kernelTLS.this_thread, this->owner, this->recursion, this );
    209206
    210207                // Leaving a recursion level, decrement the counter
     
    214211                // it means we don't need to do anything
    215212                if( this->recursion != 0) {
    216                         __cfaabi_dbg_print_safe("Kernel :  recursion still %d\n", this->recursion);
     213                        __cfaabi_dbg_print_safe( "Kernel :  recursion still %d\n", this->recursion);
    217214                        unlock( this->lock );
    218215                        return;
     
    232229        void __leave_dtor_monitor_desc( monitor_desc * this ) {
    233230                __cfaabi_dbg_debug_do(
    234                         if( this_thread != this->owner ) {
    235                                 abortf("Destroyed monitor %p has inconsistent owner, expected %p got %p.\n", this, this_thread, this->owner);
     231                        if( TL_GET( this_thread ) != this->owner ) {
     232                                abort( "Destroyed monitor %p has inconsistent owner, expected %p got %p.\n", this, TL_GET( this_thread ), this->owner);
    236233                        }
    237234                        if( this->recursion != 1 ) {
    238                                 abortf("Destroyed monitor %p has %d outstanding nested calls.\n", this, this->recursion - 1);
     235                                abort( "Destroyed monitor %p has %d outstanding nested calls.\n", this, this->recursion - 1);
    239236                        }
    240237                )
     
    248245
    249246                // Lock the monitor now
    250                 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
     247                lock( this->lock __cfaabi_dbg_ctx2 );
    251248
    252249                disable_interrupts();
     
    261258                // If we haven't left the last level of recursion
    262259                // it must mean there is an error
    263                 if( this->recursion != 0) { abortf("Thread internal monitor has unbalanced recursion"); }
     260                if( this->recursion != 0) { abort( "Thread internal monitor has unbalanced recursion" ); }
    264261
    265262                // Fetch the next thread, can be null
     
    294291// Sorts monitors before entering
    295292void ?{}( monitor_guard_t & this, monitor_desc * m [], __lock_size_t count, fptr_t func ) {
     293        thread_desc * thrd = TL_GET( this_thread );
     294
    296295        // Store current array
    297296        this.m = m;
    298297        this.count = count;
    299298
    300         // Sort monitors based on address -> TODO use a sort specialized for small numbers
     299        // Sort monitors based on address
    301300        __libcfa_small_sort(this.m, count);
    302301
    303302        // Save previous thread context
    304         this.prev = this_thread->monitors;
     303        this.prev = thrd->monitors;
    305304
    306305        // Update thread context (needed for conditions)
    307         (this_thread->monitors){m, count, func};
    308 
    309         // __cfaabi_dbg_print_safe("MGUARD : enter %d\n", count);
     306        (thrd->monitors){m, count, func};
     307
     308        // __cfaabi_dbg_print_safe( "MGUARD : enter %d\n", count);
    310309
    311310        // Enter the monitors in order
     
    313312        enter( group );
    314313
    315         // __cfaabi_dbg_print_safe("MGUARD : entered\n");
     314        // __cfaabi_dbg_print_safe( "MGUARD : entered\n" );
    316315}
    317316
     
    319318// Dtor for monitor guard
    320319void ^?{}( monitor_guard_t & this ) {
    321         // __cfaabi_dbg_print_safe("MGUARD : leaving %d\n", this.count);
     320        // __cfaabi_dbg_print_safe( "MGUARD : leaving %d\n", this.count);
    322321
    323322        // Leave the monitors in order
    324323        leave( this.m, this.count );
    325324
    326         // __cfaabi_dbg_print_safe("MGUARD : left\n");
     325        // __cfaabi_dbg_print_safe( "MGUARD : left\n" );
    327326
    328327        // Restore thread context
    329         this_thread->monitors = this.prev;
     328        TL_GET( this_thread )->monitors = this.prev;
    330329}
    331330
     
    333332// Sorts monitors before entering
    334333void ?{}( monitor_dtor_guard_t & this, monitor_desc * m [], fptr_t func ) {
     334        // optimization
     335        thread_desc * thrd = TL_GET( this_thread );
     336
    335337        // Store current array
    336338        this.m = *m;
    337339
    338340        // Save previous thread context
    339         this.prev = this_thread->monitors;
     341        this.prev = thrd->monitors;
    340342
    341343        // Update thread context (needed for conditions)
    342         (this_thread->monitors){m, 1, func};
     344        (thrd->monitors){m, 1, func};
    343345
    344346        __enter_monitor_dtor( this.m, func );
     
    351353
    352354        // Restore thread context
    353         this_thread->monitors = this.prev;
     355        TL_GET( this_thread )->monitors = this.prev;
    354356}
    355357
     
    363365}
    364366
    365 void ?{}(__condition_criterion_t & this ) {
    366         this.ready  = false;
    367         this.target = NULL;
    368         this.owner  = NULL;
    369         this.next   = NULL;
     367void ?{}(__condition_criterion_t & this ) with( this ) {
     368        ready  = false;
     369        target = NULL;
     370        owner  = NULL;
     371        next   = NULL;
    370372}
    371373
     
    391393
    392394        // Create the node specific to this wait operation
    393         wait_ctx( this_thread, user_info );
     395        wait_ctx( TL_GET( this_thread ), user_info );
    394396
    395397        // Append the current wait operation to the ones already queued on the condition
     
    430432        //Some more checking in debug
    431433        __cfaabi_dbg_debug_do(
    432                 thread_desc * this_thrd = this_thread;
     434                thread_desc * this_thrd = TL_GET( this_thread );
    433435                if ( this.monitor_count != this_thrd->monitors.size ) {
    434                         abortf( "Signal on condition %p made with different number of monitor(s), expected %i got %i", &this, this.monitor_count, this_thrd->monitors.size );
     436                        abort( "Signal on condition %p made with different number of monitor(s), expected %zi got %zi", &this, this.monitor_count, this_thrd->monitors.size );
    435437                }
    436438
    437439                for(int i = 0; i < this.monitor_count; i++) {
    438440                        if ( this.monitors[i] != this_thrd->monitors[i] ) {
    439                                 abortf( "Signal on condition %p made with different monitor, expected %p got %i", &this, this.monitors[i], this_thrd->monitors[i] );
     441                                abort( "Signal on condition %p made with different monitor, expected %p got %p", &this, this.monitors[i], this_thrd->monitors[i] );
    440442                        }
    441443                }
     
    476478        lock_all( monitors, locks, count );
    477479
     480
    478481        // Create the node specific to this wait operation
    479         wait_ctx_primed( this_thread, 0 )
     482        wait_ctx_primed( kernelTLS.this_thread, 0 )
    480483
    481484        //save contexts
     
    534537        __lock_size_t actual_count = aggregate( mon_storage, mask );
    535538
    536         __cfaabi_dbg_print_buffer_decl( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (__lock_size_t)max);
     539        __cfaabi_dbg_print_buffer_decl( "Kernel : waitfor %"PRIdFAST16" (s: %"PRIdFAST16", m: %"PRIdFAST16")\n", actual_count, mask.size, (__lock_size_t)max);
    537540
    538541        if(actual_count == 0) return;
    539542
    540         __cfaabi_dbg_print_buffer_local( "Kernel : waitfor internal proceeding\n");
     543        __cfaabi_dbg_print_buffer_local( "Kernel : waitfor internal proceeding\n" );
    541544
    542545        // Create storage for monitor context
     
    555558                        __acceptable_t& accepted = mask[index];
    556559                        if( accepted.is_dtor ) {
    557                                 __cfaabi_dbg_print_buffer_local( "Kernel : dtor already there\n");
     560                                __cfaabi_dbg_print_buffer_local( "Kernel : dtor already there\n" );
    558561                                verifyf( accepted.size == 1,  "ERROR: Accepted dtor has more than 1 mutex parameter." );
    559562
     
    567570                        }
    568571                        else {
    569                                 __cfaabi_dbg_print_buffer_local( "Kernel : thread present, baton-passing\n");
     572                                __cfaabi_dbg_print_buffer_local( "Kernel : thread present, baton-passing\n" );
    570573
    571574                                // Create the node specific to this wait operation
    572                                 wait_ctx_primed( this_thread, 0 );
     575                                wait_ctx_primed( kernelTLS.this_thread, 0 );
    573576
    574577                                // Save monitor states
    575578                                monitor_save;
    576579
    577                                 __cfaabi_dbg_print_buffer_local( "Kernel :  baton of %d monitors : ", count );
     580                                __cfaabi_dbg_print_buffer_local( "Kernel :  baton of %"PRIdFAST16" monitors : ", count );
    578581                                #ifdef __CFA_DEBUG_PRINT__
    579582                                        for( int i = 0; i < count; i++) {
     
    581584                                        }
    582585                                #endif
    583                                 __cfaabi_dbg_print_buffer_local( "\n");
     586                                __cfaabi_dbg_print_buffer_local( "\n" );
    584587
    585588                                // Set the owners to be the next thread
     
    592595                                monitor_restore;
    593596
    594                                 __cfaabi_dbg_print_buffer_local( "Kernel : thread present, returned\n");
     597                                __cfaabi_dbg_print_buffer_local( "Kernel : thread present, returned\n" );
    595598                        }
    596599
     
    602605
    603606        if( duration == 0 ) {
    604                 __cfaabi_dbg_print_buffer_local( "Kernel : non-blocking, exiting\n");
     607                __cfaabi_dbg_print_buffer_local( "Kernel : non-blocking, exiting\n" );
    605608
    606609                unlock_all( locks, count );
     
    611614
    612615
    613         verifyf( duration < 0, "Timeout on waitfor statments not supported yet.");
    614 
    615         __cfaabi_dbg_print_buffer_local( "Kernel : blocking waitfor\n");
     616        verifyf( duration < 0, "Timeout on waitfor statments not supported yet." );
     617
     618        __cfaabi_dbg_print_buffer_local( "Kernel : blocking waitfor\n" );
    616619
    617620        // Create the node specific to this wait operation
    618         wait_ctx_primed( this_thread, 0 );
     621        wait_ctx_primed( kernelTLS.this_thread, 0 );
    619622
    620623        monitor_save;
     
    622625
    623626        for( __lock_size_t i = 0; i < count; i++) {
    624                 verify( monitors[i]->owner == this_thread );
     627                verify( monitors[i]->owner == kernelTLS.this_thread );
    625628        }
    626629
     
    635638        monitor_restore;
    636639
    637         __cfaabi_dbg_print_buffer_local( "Kernel : exiting\n");
     640        __cfaabi_dbg_print_buffer_local( "Kernel : exiting\n" );
    638641
    639642        __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted);
     
    644647
    645648static inline void set_owner( monitor_desc * this, thread_desc * owner ) {
    646         // __cfaabi_dbg_print_safe("Kernal :   Setting owner of %p to %p ( was %p)\n", this, owner, this->owner );
     649        // __cfaabi_dbg_print_safe( "Kernal :   Setting owner of %p to %p ( was %p)\n", this, owner, this->owner );
    647650
    648651        //Pass the monitor appropriately
     
    676679static inline thread_desc * next_thread( monitor_desc * this ) {
    677680        //Check the signaller stack
    678         __cfaabi_dbg_print_safe("Kernel :  mon %p AS-stack top %p\n", this, this->signal_stack.top);
     681        __cfaabi_dbg_print_safe( "Kernel :  mon %p AS-stack top %p\n", this, this->signal_stack.top);
    679682        __condition_criterion_t * urgent = pop( this->signal_stack );
    680683        if( urgent ) {
     
    737740static inline void lock_all( __spinlock_t * locks [], __lock_size_t count ) {
    738741        for( __lock_size_t i = 0; i < count; i++ ) {
    739                 DO_LOCK( *locks[i] __cfaabi_dbg_ctx2 );
     742                lock( *locks[i] __cfaabi_dbg_ctx2 );
    740743        }
    741744}
     
    744747        for( __lock_size_t i = 0; i < count; i++ ) {
    745748                __spinlock_t * l = &source[i]->lock;
    746                 DO_LOCK( *l __cfaabi_dbg_ctx2 );
     749                lock( *l __cfaabi_dbg_ctx2 );
    747750                if(locks) locks[i] = l;
    748751        }
     
    816819
    817820static inline void brand_condition( condition & this ) {
    818         thread_desc * thrd = this_thread;
     821        thread_desc * thrd = TL_GET( this_thread );
    819822        if( !this.monitors ) {
    820                 // __cfaabi_dbg_print_safe("Branding\n");
     823                // __cfaabi_dbg_print_safe( "Branding\n" );
    821824                assertf( thrd->monitors.data != NULL, "No current monitor to brand condition %p", thrd->monitors.data );
    822825                this.monitor_count = thrd->monitors.size;
  • libcfa/src/concurrency/monitor.hfa

    rf9feab8 r90152a4  
    2020#include <assert.h>
    2121#include "invoke.h"
    22 #include "stdlib"
     22#include "stdlib.hfa"
    2323
    2424trait is_monitor(dtype T) {
     
    2727};
    2828
    29 static inline void ?{}(monitor_desc & this) {
    30         (this.lock){};
    31         (this.entry_queue){};
    32         (this.signal_stack){};
    33         this.owner         = NULL;
    34         this.recursion     = 0;
    35         this.mask.accepted = NULL;
    36         this.mask.data     = NULL;
    37         this.mask.size     = 0;
    38         this.dtor_node     = NULL;
     29static inline void ?{}(monitor_desc & this) with( this ) {
     30        lock{};
     31        entry_queue{};
     32        signal_stack{};
     33        owner         = NULL;
     34        recursion     = 0;
     35        mask.accepted = NULL;
     36        mask.data     = NULL;
     37        mask.size     = 0;
     38        dtor_node     = NULL;
    3939}
    4040
     
    138138
    139139struct __acceptable_t {
    140         __monitor_group_t;
     140        inline struct __monitor_group_t;
    141141        bool is_dtor;
    142142};
  • libcfa/src/concurrency/preemption.hfa

    rf9feab8 r90152a4  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // preemption.h --
     7// preemption.hfa --
    88//
    99// Author           : Thierry Delisle
    1010// Created On       : Mon Jun 5 14:20:42 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:34:25 2017
    13 // Update Count     : 1
     12// Last Modified On : Fri Mar 23 17:18:53 2018
     13// Update Count     : 2
    1414//
    1515
    1616#pragma once
    1717
    18 #include "alarm.h"
    19 #include "kernel_private.h"
     18#include "alarm.hfa"
     19#include "kernel_private.hfa"
    2020
    21 __attribute__((weak)) unsigned int default_preemption();
    2221void kernel_start_preemption();
    2322void kernel_stop_preemption();
    24 void update_preemption( processor * this, __cfa_time_t duration );
    25 void tick_preemption();
     23void update_preemption( processor * this, Duration duration );
    2624
    2725struct preemption_scope {
  • libcfa/src/concurrency/thread.cfa

    rf9feab8 r90152a4  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:34:46 2017
    13 // Update Count     : 1
     12// Last Modified On : Fri Mar 30 17:19:52 2018
     13// Update Count     : 8
    1414//
    1515
    16 #include "thread"
     16#include "thread.hfa"
    1717
    18 #include "kernel_private.h"
     18#include "kernel_private.hfa"
    1919
    2020#define __CFA_INVOKE_PRIVATE__
     
    2626}
    2727
    28 extern volatile thread_local processor * this_processor;
     28//extern volatile thread_local processor * this_processor;
    2929
    3030//-----------------------------------------------------------------------------
    3131// Thread ctors and dtors
     32void ?{}(thread_desc & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) {
     33        self_cor{ name, storage, storageSize };
     34        verify(&self_cor);
     35        curr_cor = &self_cor;
     36        self_mon.owner = &this;
     37        self_mon.recursion = 1;
     38        self_mon_p = &self_mon;
     39        curr_cluster = &cl;
     40        next = NULL;
    3241
    33 void ?{}(thread_desc& this) {
    34         (this.self_cor){};
    35         this.self_cor.name = "Anonymous Coroutine";
    36         this.self_mon.owner = &this;
    37         this.self_mon.recursion = 1;
    38         this.self_mon_p = &this.self_mon;
    39         this.next = NULL;
     42        node.next = NULL;
     43        node.prev = NULL;
     44        doregister(curr_cluster, this);
    4045
    41         (this.monitors){ &this.self_mon_p, 1, (fptr_t)0 };
     46        monitors{ &self_mon_p, 1, (fptr_t)0 };
    4247}
    4348
    44 void ^?{}(thread_desc& this) {
    45         ^(this.self_cor){};
     49void ^?{}(thread_desc& this) with( this ) {
     50        unregister(curr_cluster, this);
     51        ^self_cor{};
    4652}
    4753
    4854forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
    49 void ?{}( scoped(T)& this ) {
    50         (this.handle){};
    51         __thrd_start(this.handle);
     55void ?{}( scoped(T)& this ) with( this ) {
     56        handle{};
     57        __thrd_start(handle);
    5258}
    5359
    5460forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
    55 void ?{}( scoped(T)& this, P params ) {
    56         (this.handle){ params };
    57         __thrd_start(this.handle);
     61void ?{}( scoped(T)& this, P params ) with( this ) {
     62        handle{ params };
     63        __thrd_start(handle);
    5864}
    5965
    6066forall( dtype T | sized(T) | is_thread(T) )
    61 void ^?{}( scoped(T)& this ) {
    62         ^(this.handle){};
     67void ^?{}( scoped(T)& this ) with( this ) {
     68        ^handle{};
    6369}
    6470
     
    6874void __thrd_start( T& this ) {
    6975        coroutine_desc* thrd_c = get_coroutine(this);
    70         thread_desc* thrd_h = get_thread   (this);
    71         thrd_c->last = this_coroutine;
     76        thread_desc   * thrd_h = get_thread   (this);
     77        thrd_c->last = TL_GET( this_coroutine );
    7278
    7379        // __cfaabi_dbg_print_safe("Thread start : %p (t %p, c %p)\n", this, thrd_c, thrd_h);
     
    7581        disable_interrupts();
    7682        create_stack(&thrd_c->stack, thrd_c->stack.size);
    77         this_coroutine = thrd_c;
     83        kernelTLS.this_coroutine = thrd_c;
    7884        CtxStart(&this, CtxInvokeThread);
    7985        assert( thrd_c->last->stack.context );
     
    8490}
    8591
     92extern "C" {
     93        // KERNEL ONLY
     94        void __finish_creation(void) {
     95                coroutine_desc* thrd_c = kernelTLS.this_coroutine;
     96                ThreadCtxSwitch( thrd_c, thrd_c->last );
     97        }
     98}
     99
    86100void yield( void ) {
    87         BlockInternal( this_thread );
     101        // Safety note : This could cause some false positives due to preemption
     102      verify( TL_GET( preemption_state.enabled ) );
     103        BlockInternal( TL_GET( this_thread ) );
     104        // Safety note : This could cause some false positives due to preemption
     105      verify( TL_GET( preemption_state.enabled ) );
    88106}
    89107
     
    94112}
    95113
     114// KERNEL ONLY
    96115void ThreadCtxSwitch(coroutine_desc* src, coroutine_desc* dst) {
    97116        // set state of current coroutine to inactive
     
    99118        dst->state = Active;
    100119
    101         //update the last resumer
    102         dst->last = src;
    103 
    104120        // set new coroutine that the processor is executing
    105121        // and context switch to it
    106         this_coroutine = dst;
     122        kernelTLS.this_coroutine = dst;
    107123        assert( src->stack.context );
    108124        CtxSwitch( src->stack.context, dst->stack.context );
    109         this_coroutine = src;
     125        kernelTLS.this_coroutine = src;
    110126
    111127        // set state of new coroutine to active
  • libcfa/src/concurrency/thread.hfa

    rf9feab8 r90152a4  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:59:40 2017
    13 // Update Count     : 3
     12// Last Modified On : Thu Mar 29 14:07:11 2018
     13// Update Count     : 4
    1414//
    1515
     
    1919#include "invoke.h"
    2020
    21 #include "coroutine"
    22 #include "monitor"
     21#include "coroutine.hfa"
     22#include "kernel.hfa"
     23#include "monitor.hfa"
    2324
    2425//-----------------------------------------------------------------------------
    25 // Coroutine trait
    26 // Anything that implements this trait can be resumed.
    27 // Anything that is resumed is a coroutine.
     26// thread trait
    2827trait is_thread(dtype T) {
    2928      void ^?{}(T& mutex this);
     
    5251}
    5352
    54 extern thread_local thread_desc * volatile this_thread;
     53extern struct cluster * mainCluster;
    5554
    5655forall( dtype T | is_thread(T) )
     
    5958//-----------------------------------------------------------------------------
    6059// Ctors and dtors
    61 void ?{}(thread_desc& this);
    62 void ^?{}(thread_desc& this);
     60void ?{}(thread_desc & this, const char * const name, struct cluster & cl, void * storage, size_t storageSize );
     61void ^?{}(thread_desc & this);
     62
     63static inline void ?{}(thread_desc & this)                                                                  { this{ "Anonymous Thread", *mainCluster, NULL, 0 }; }
     64static inline void ?{}(thread_desc & this, size_t stackSize )                                               { this{ "Anonymous Thread", *mainCluster, NULL, stackSize }; }
     65static inline void ?{}(thread_desc & this, void * storage, size_t storageSize )                             { this{ "Anonymous Thread", *mainCluster, storage, storageSize }; }
     66static inline void ?{}(thread_desc & this, struct cluster & cl )                                            { this{ "Anonymous Thread", cl, NULL, 0 }; }
     67static inline void ?{}(thread_desc & this, struct cluster & cl, size_t stackSize )                          { this{ "Anonymous Thread", cl, 0, stackSize }; }
     68static inline void ?{}(thread_desc & this, struct cluster & cl, void * storage, size_t storageSize )        { this{ "Anonymous Thread", cl, storage, storageSize }; }
     69static inline void ?{}(thread_desc & this, const char * const name)                                         { this{ name, *mainCluster, NULL, 0 }; }
     70static inline void ?{}(thread_desc & this, const char * const name, struct cluster & cl )                   { this{ name, cl, NULL, 0 }; }
     71static inline void ?{}(thread_desc & this, const char * const name, struct cluster & cl, size_t stackSize ) { this{ name, cl, NULL, stackSize }; }
    6372
    6473//-----------------------------------------------------------------------------
  • libcfa/src/containers/maybe.cfa

    rf9feab8 r90152a4  
    1414//
    1515
    16 #include <containers/maybe>
     16#include <containers/maybe.hfa>
    1717#include <assert.h>
    1818
  • libcfa/src/containers/pair.cfa

    rf9feab8 r90152a4  
    1111//
    1212
    13 #include <containers/pair>
     13#include <containers/pair.hfa>
    1414
    15 forall(otype R, otype S 
     15forall(otype R, otype S
    1616        | { int ?==?(R, R); int ?<?(R, R); int ?<?(S, S); })
    1717int ?<?(pair(R, S) p, pair(R, S) q) {
     
    1919}
    2020
    21 forall(otype R, otype S 
     21forall(otype R, otype S
    2222        | { int ?==?(R, R); int ?<?(R, R); int ?<=?(S, S); })
    2323int ?<=?(pair(R, S) p, pair(R, S) q) {
     
    3535}
    3636
    37 forall(otype R, otype S 
     37forall(otype R, otype S
    3838        | { int ?==?(R, R); int ?>?(R, R); int ?>?(S, S); })
    3939int ?>?(pair(R, S) p, pair(R, S) q) {
     
    4141}
    4242
    43 forall(otype R, otype S 
     43forall(otype R, otype S
    4444        | { int ?==?(R, R); int ?>?(R, R); int ?>=?(S, S); })
    4545int ?>=?(pair(R, S) p, pair(R, S) q) {
  • libcfa/src/containers/result.cfa

    rf9feab8 r90152a4  
    1414//
    1515
    16 #include <containers/result>
     16#include <containers/result.hfa>
    1717#include <assert.h>
    1818
  • libcfa/src/containers/result.hfa

    rf9feab8 r90152a4  
    2828struct result {
    2929        bool has_value;
    30         inner_result(T, E);
     30        inline union inner_result(T, E);
    3131};
    3232
  • libcfa/src/containers/vector.cfa

    rf9feab8 r90152a4  
    1414//
    1515
    16 #include <containers/vector>
     16#include <containers/vector.hfa>
    1717
    18 #include <stdlib>
     18#include <stdlib.hfa>
    1919
    2020forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
  • libcfa/src/exception.c

    rf9feab8 r90152a4  
    99// Author           : Andrew Beach
    1010// Created On       : Mon Jun 26 15:13:00 2017
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Aug 17 15:45:00 2017
    13 // Update Count     : 7
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Feb 22 18:17:34 2018
     13// Update Count     : 11
    1414//
    1515
     
    2323#include <stdio.h>
    2424#include <unwind.h>
    25 #include <bits/debug.h>
     25#include <bits/debug.hfa>
    2626
    2727// FIX ME: temporary hack to keep ARM build working
     
    5252    struct __cfaabi_ehm__try_resume_node * current_resume;
    5353
    54     exception * current_exception;
     54    exception_t * current_exception;
    5555    int current_handler_index;
    5656} shared_stack = {NULL, NULL, 0, 0};
     
    7171// This macro should be the only thing that needs to change across machines.  Used in the personality function, way down
    7272// in termination.
    73 // struct _Unwind_Context * -> _Unwind_Reason_Code(*)(exception *)
     73// struct _Unwind_Context * -> _Unwind_Reason_Code(*)(exception_t *)
    7474#define MATCHER_FROM_CONTEXT(ptr_to_context) \
    75         (*(_Unwind_Reason_Code(**)(exception*))(_Unwind_GetCFA(ptr_to_context) + 8))
     75        (*(_Unwind_Reason_Code(**)(exception_t *))(_Unwind_GetCFA(ptr_to_context) + 8))
    7676
    7777
    7878// RESUMPTION ================================================================
    7979
    80 void __cfaabi_ehm__throw_resume(exception * except) {
     80void __cfaabi_ehm__throw_resume(exception_t * except) {
    8181
    8282        __cfaabi_dbg_print_safe("Throwing resumption exception\n");
     
    106106
    107107void __cfaabi_ehm__try_resume_setup(struct __cfaabi_ehm__try_resume_node * node,
    108                         _Bool (*handler)(exception * except)) {
     108                        _Bool (*handler)(exception_t * except)) {
    109109        node->next = shared_stack.top_resume;
    110110        node->handler = handler;
     
    126126};
    127127
    128 #define NODE_TO_EXCEPT(node) ((exception *)(1 + (node)))
     128#define NODE_TO_EXCEPT(node) ((exception_t *)(1 + (node)))
    129129#define EXCEPT_TO_NODE(except) ((struct __cfaabi_ehm__node *)(except) - 1)
    130130
    131131// Creates a copy of the indicated exception and sets current_exception to it.
    132 static void __cfaabi_ehm__allocate_exception( exception * except ) {
     132static void __cfaabi_ehm__allocate_exception( exception_t * except ) {
    133133        struct exception_context_t * context = this_exception_context();
    134134
     
    151151
    152152// Delete the provided exception, unsetting current_exception if relivant.
    153 static void __cfaabi_ehm__delete_exception( exception * except ) {
     153static void __cfaabi_ehm__delete_exception( exception_t * except ) {
    154154        struct exception_context_t * context = this_exception_context();
    155155
     
    179179// If this isn't a rethrow (*except==0), delete the provided exception.
    180180void __cfaabi_ehm__cleanup_terminate( void * except ) {
    181         if ( *(void**)except ) __cfaabi_ehm__delete_exception( *(exception**)except );
     181        if ( *(void**)except ) __cfaabi_ehm__delete_exception( *(exception_t **)except );
    182182}
    183183
     
    233233}
    234234
    235 void __cfaabi_ehm__throw_terminate( exception * val ) {
     235void __cfaabi_ehm__throw_terminate( exception_t * val ) {
    236236        __cfaabi_dbg_print_safe("Throwing termination exception\n");
    237237
     
    348348                                        // _Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher;
    349349
    350                                         _Unwind_Reason_Code (*matcher)(exception *) =
     350                                        _Unwind_Reason_Code (*matcher)(exception_t *) =
    351351                                                MATCHER_FROM_CONTEXT(context);
    352352                                        int index = matcher(shared_stack.current_exception);
     
    409409__attribute__((noinline))
    410410void __cfaabi_ehm__try_terminate(void (*try_block)(),
    411                 void (*catch_block)(int index, exception * except),
    412                 __attribute__((unused)) int (*match_block)(exception * except)) {
     411                void (*catch_block)(int index, exception_t * except),
     412                __attribute__((unused)) int (*match_block)(exception_t * except)) {
    413413        //! volatile int xy = 0;
    414414        //! printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy);
     
    453453// match, which is no way generic.  Some more works need to be done if we want to have a single call to the try routine.
    454454
    455 #if defined( __x86_64__ ) || defined( __i386__ )
     455#if defined( __i386 ) || defined( __x86_64 )
    456456asm (
    457457        //HEADER
     
    476476//      "       .section        .note.GNU-stack,\"x\",@progbits\n"
    477477);
    478 #endif // __x86_64__ || __i386__
     478#endif // __i386 || __x86_64
  • libcfa/src/exception.h

    rf9feab8 r90152a4  
    99// Author           : Andrew Beach
    1010// Created On       : Mon Jun 26 15:11:00 2017
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Aug 17 15:44:00 2017
    13 // Update Count     : 6
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Feb 22 18:11:15 2018
     13// Update Count     : 8
    1414//
    1515
     
    2222
    2323struct __cfaabi_ehm__base_exception_t;
    24 typedef struct __cfaabi_ehm__base_exception_t exception;
     24typedef struct __cfaabi_ehm__base_exception_t exception_t;
    2525struct __cfaabi_ehm__base_exception_t_vtable {
    2626        const struct __cfaabi_ehm__base_exception_t_vtable * parent;
     
    3939
    4040// Used in throw statement translation.
    41 void __cfaabi_ehm__throw_terminate(exception * except) __attribute__((noreturn));
     41void __cfaabi_ehm__throw_terminate(exception_t * except) __attribute__((noreturn));
    4242void __cfaabi_ehm__rethrow_terminate() __attribute__((noreturn));
    43 void __cfaabi_ehm__throw_resume(exception * except);
     43void __cfaabi_ehm__throw_resume(exception_t * except);
    4444
    4545// Function catches termination exceptions.
    4646void __cfaabi_ehm__try_terminate(
    4747    void (*try_block)(),
    48     void (*catch_block)(int index, exception * except),
    49     int (*match_block)(exception * except));
     48    void (*catch_block)(int index, exception_t * except),
     49    int (*match_block)(exception_t * except));
    5050
    5151// Clean-up the exception in catch blocks.
     
    5555struct __cfaabi_ehm__try_resume_node {
    5656    struct __cfaabi_ehm__try_resume_node * next;
    57     _Bool (*handler)(exception * except);
     57    _Bool (*handler)(exception_t * except);
    5858};
    5959
     
    6161void __cfaabi_ehm__try_resume_setup(
    6262    struct __cfaabi_ehm__try_resume_node * node,
    63     _Bool (*handler)(exception * except));
     63    _Bool (*handler)(exception_t * except));
    6464void __cfaabi_ehm__try_resume_cleanup(
    6565    struct __cfaabi_ehm__try_resume_node * node);
  • libcfa/src/gmp.hfa

    rf9feab8 r90152a4  
    1010// Created On       : Tue Apr 19 08:43:43 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Sep  4 09:54:33 2017
    13 // Update Count     : 20
     12// Last Modified On : Thu Dec  7 09:10:41 2017
     13// Update Count     : 21
    1414//
    1515
     
    1919
    2020#include <gmp.h>                                                                                // GNU multi-precise integers
    21 #include <fstream>                                                                              // sout
     21#include <fstream.hfa>                                                                          // sout
    2222
    2323struct Int { mpz_t mpz; };                                                              // wrap GMP implementation
     
    257257// I/O
    258258static inline forall( dtype istype | istream( istype ) )
    259 istype * ?|?( istype * is, Int & mp ) {
     259istype & ?|?( istype & is, Int & mp ) {
    260260        gmp_scanf( "%Zd", &mp );
    261261        return is;
     
    263263
    264264static inline forall( dtype ostype | ostream( ostype ) )
    265 ostype * ?|?( ostype * os, Int mp ) {
     265ostype & ?|?( ostype & os, Int mp ) {
    266266        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    267267        gmp_printf( "%Zd", mp.mpz );
  • libcfa/src/iterator.cfa

    rf9feab8 r90152a4  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // iterator.c -- 
     7// iterator.c --
    88//
    99// Author           : Richard C. Bilson
     
    1414//
    1515
    16 #include "iterator"
     16#include "iterator.hfa"
    1717
    1818forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) )
  • libcfa/src/math.hfa

    rf9feab8 r90152a4  
    1010// Created On       : Mon Apr 18 23:37:04 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug  7 07:51:15 2017
    13 // Update Count     : 108
     12// Last Modified On : Fri Jul 13 11:02:15 2018
     13// Update Count     : 116
    1414//
    1515
     
    348348static inline long double scalbln( long double x, long int exp ) { return scalblnl( x, exp ); }
    349349
     350//---------------------------------------
     351
     352#include "common.hfa"
     353
     354//---------------------------------------
     355
     356forall( otype T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T );T ?*?( T, T ); } )
     357T lerp( T x, T y, T a ) { return x * ((T){1} - a) + y * a; }
     358
     359forall( otype T | { void ?{}( T &, zero_t ); void ?{}( T &, one_t ); int ?<?( T, T ); } )
     360T step( T edge, T x ) { return x < edge ? (T){0} : (T){1}; }
     361
     362forall( otype T | { void ?{}( T &, int ); T clamp( T, T, T ); T ?-?( T, T ); T ?*?( T, T ); T ?/?( T, T ); } )
     363T smoothstep( T edge0, T edge1, T x ) { T t = clamp( (x - edge0) / (edge1 - edge0), (T){0}, (T){1} ); return t * t * ((T){3} - (T){2} * t); }
     364
    350365// Local Variables: //
    351366// mode: c //
  • libcfa/src/startup.hfa

    rf9feab8 r90152a4  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // startup.h --
     7// startup.hfa --
    88//
    99// Author           : Thierry Delisle
    1010// Created On       : Wed Mar 29 15:56:41 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 20 21:37:11 2017
    13 // Update Count     : 2
     12// Last Modified On : Tue Jul 24 16:16:37 2018
     13// Update Count     : 4
    1414//
    1515
     
    1919extern "C" {
    2020        enum {
    21                 STARTUP_PRIORITY_CORE       = 101,
    22                 STARTUP_PRIORITY_KERNEL     = 102,
    23                 STARTUP_PRIORITY_MEMORY     = 103,
     21                STARTUP_PRIORITY_MEMORY     = 101,
     22                STARTUP_PRIORITY_CORE       = 102,
     23                STARTUP_PRIORITY_KERNEL     = 103,
    2424                STARTUP_PRIORITY_IOSTREAM   = 104,
     25                STARTUP_PRIORITY_APPREADY   = 105,
    2526        };
    2627}
    2728#else
    28 #define STARTUP_PRIORITY_CORE       101
    29 #define STARTUP_PRIORITY_KERNEL     102
    30 #define STARTUP_PRIORITY_MEMORY     103
     29#define STARTUP_PRIORITY_MEMORY     101
     30#define STARTUP_PRIORITY_CORE       102
     31#define STARTUP_PRIORITY_KERNEL     103
    3132#define STARTUP_PRIORITY_IOSTREAM   104
     33#define STARTUP_PRIORITY_APPREADY   105
    3234#endif
    3335
  • libcfa/src/stdhdr/assert.h

    rf9feab8 r90152a4  
    3333        #define verify(x) assert(x)
    3434        #define verifyf(x, ...) assertf(x, __VA_ARGS__)
     35        #define __CFA_WITH_VERIFY__
    3536#else
    3637        #define verify(x)
  • libcfa/src/stdhdr/bfdlink.h

    rf9feab8 r90152a4  
    1010// Created On       : Tue Jul 18 07:26:04 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 18 07:46:50 2017
    13 // Update Count     : 3
     12// Last Modified On : Sun Jul 22 13:49:30 2018
     13// Update Count     : 4
    1414//
    1515
     
    2020#endif
    2121
    22 #include_next <bfdlink.h>                                                               // must have internal check for multiple expansion
     22#include_next <bfdlink.h>                                                               // has internal check for multiple expansion
    2323
    2424#if defined( with ) && defined( __CFA_BFDLINK_H__ )             // reset only if set
  • libcfa/src/stdhdr/hwloc.h

    rf9feab8 r90152a4  
    1010// Created On       : Tue Jul 18 07:45:00 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 18 07:56:33 2017
    13 // Update Count     : 3
     12// Last Modified On : Sun Jul 22 13:49:58 2018
     13// Update Count     : 4
    1414//
    1515
     
    2020#endif
    2121
    22 #include_next <hwloc.h>                                                                 // must have internal check for multiple expansion
     22#include_next <hwloc.h>                                                                 // has internal check for multiple expansion
    2323
    2424#if defined( thread ) && defined( __CFA_HWLOC_H__ )             // reset only if set
  • libcfa/src/stdhdr/krb5.h

    rf9feab8 r90152a4  
    1010// Created On       : Tue Jul 18 07:55:44 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 18 07:58:01 2017
    13 // Update Count     : 3
     12// Last Modified On : Sun Jul 22 13:50:24 2018
     13// Update Count     : 4
    1414//
    1515
     
    2020#endif
    2121
    22 #include_next <krb5.h>                                                                  // must have internal check for multiple expansion
     22#include_next <krb5.h>                                                                  // has internal check for multiple expansion
    2323
    2424#if defined( enable ) && defined( __CFA_KRB5_H__ )              // reset only if set
  • libcfa/src/stdhdr/malloc.h

    rf9feab8 r90152a4  
    1010// Created On       : Thu Jul 20 15:58:16 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 20 16:00:12 2017
    13 // Update Count     : 4
     12// Last Modified On : Sat Aug 11 09:06:31 2018
     13// Update Count     : 10
    1414//
     15
     16
     17size_t default_mmap_start();                                                    // CFA extras
     18size_t default_heap_expansion();
     19
     20bool traceHeap();
     21bool traceHeapOn();
     22bool traceHeapOff();
     23
     24bool traceHeapTerm();
     25bool traceHeapTermOn();
     26bool traceHeapTermOff();
     27
     28bool checkFree();
     29bool checkFreeOn();
     30bool checkFreeOff();
     31
     32extern "C" {
     33size_t malloc_alignment( void * );
     34bool malloc_zero_fill( void * );
     35int malloc_stats_fd( int fd );
     36void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize );
     37} // extern "C"
    1538
    1639extern "C" {
  • libcfa/src/stdhdr/math.h

    rf9feab8 r90152a4  
    1010// Created On       : Mon Jul  4 23:25:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul  5 20:38:18 2016
    13 // Update Count     : 12
     12// Last Modified On : Thu Feb 22 18:16:07 2018
     13// Update Count     : 13
    1414//
    1515
    1616extern "C" {
     17#if ! defined( exception )                                                              // nesting ?
     18#define exception `exception`                                                   // make keyword an identifier
     19#define __CFA_MATH_H__
     20#endif
     21
    1722#include_next <math.h>                                                                  // has internal check for multiple expansion
     23
     24#if defined( exception ) && defined( __CFA_MATH_H__ )   // reset only if set
     25#undef exception
     26#undef __CFA_MATH_H__
     27#endif
    1828} // extern "C"
    1929
Note: See TracChangeset for help on using the changeset viewer.