- Timestamp:
- Aug 27, 2018, 4:40:34 PM (7 years ago)
- 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. - Location:
- libcfa
- Files:
-
- 50 added
- 85 moved
Legend:
- Unmodified
- Added
- Removed
-
libcfa/prelude/Makefile.in
rf9feab8 r90152a4 90 90 PRE_UNINSTALL = : 91 91 POST_UNINSTALL = : 92 build_triplet = @build@ 93 host_triplet = @host@ 94 subdir = src/prelude 92 subdir = prelude 95 93 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 96 am__aclocal_m4_deps = $(top_srcdir)/configure.ac 94 am__aclocal_m4_deps = $(top_srcdir)/../automake/cfa.m4 \ 95 $(top_srcdir)/configure.ac 97 96 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ 98 97 $(ACLOCAL_M4) 99 98 DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) 100 99 mkinstalldirs = $(install_sh) -d 101 CONFIG_HEADER = $(top_builddir)/config.h102 100 CONFIG_CLEAN_FILES = 103 101 CONFIG_CLEAN_VPATH_FILES = … … 154 152 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) 155 153 ACLOCAL = @ACLOCAL@ 156 ALLOCA = @ALLOCA@157 154 AMTAR = @AMTAR@ 158 155 AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ 156 ARCHITECTURE = @ARCHITECTURE@ 157 ARCH_FLAGS = @ARCH_FLAGS@ 159 158 AUTOCONF = @AUTOCONF@ 160 159 AUTOHEADER = @AUTOHEADER@ 161 160 AUTOMAKE = @AUTOMAKE@ 162 161 AWK = @AWK@ 163 BACKEND_CC = @BACKEND_CC@ 164 CC = ${abs_top_srcdir}/src/driver/cfa 162 CC = @CFACC@ 165 163 CCAS = @CCAS@ 166 164 CCASDEPMODE = @CCASDEPMODE@ 167 165 CCASFLAGS = @CCASFLAGS@ 168 166 CCDEPMODE = @CCDEPMODE@ 169 CFA_BACKEND_CC = @CFA_BACKEND_CC@ 167 CFACC = @CFACC@ 168 CFACPP = @CFACPP@ 170 169 CFA_BINDIR = @CFA_BINDIR@ 171 CFA_FLAGS = @CFA_FLAGS@172 170 CFA_INCDIR = @CFA_INCDIR@ 173 171 CFA_LIBDIR = @CFA_LIBDIR@ … … 175 173 CFA_PREFIX = @CFA_PREFIX@ 176 174 CFLAGS = @CFLAGS@ 177 CPP = @CPP@ 175 CONFIGURATION = @CONFIGURATION@ 176 CONFIG_CFAFLAGS = @CONFIG_CFAFLAGS@ 177 CONFIG_CFLAGS = @CONFIG_CFLAGS@ 178 178 CPPFLAGS = @CPPFLAGS@ 179 179 CXX = @CXX@ … … 183 183 DEFS = @DEFS@ 184 184 DEPDIR = @DEPDIR@ 185 DRIVER_DIR = @DRIVER_DIR@ 185 186 ECHO_C = @ECHO_C@ 186 187 ECHO_N = @ECHO_N@ 187 188 ECHO_T = @ECHO_T@ 188 EGREP = @EGREP@189 189 EXEEXT = @EXEEXT@ 190 GREP = @GREP@191 190 INSTALL = @INSTALL@ 192 191 INSTALL_DATA = @INSTALL_DATA@ … … 195 194 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ 196 195 LDFLAGS = @LDFLAGS@ 197 LEX = @LEX@198 LEXLIB = @LEXLIB@199 LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@200 196 LIBOBJS = @LIBOBJS@ 201 197 LIBS = @LIBS@ 202 198 LTLIBOBJS = @LTLIBOBJS@ 203 MACHINE_TYPE = @MACHINE_TYPE@204 MAINT = @MAINT@205 199 MAKEINFO = @MAKEINFO@ 206 200 MKDIR_P = @MKDIR_P@ … … 219 213 STRIP = @STRIP@ 220 214 VERSION = @VERSION@ 221 YACC = @YACC@222 YFLAGS = @YFLAGS@223 215 abs_builddir = @abs_builddir@ 224 216 abs_srcdir = @abs_srcdir@ … … 233 225 am__untar = @am__untar@ 234 226 bindir = @bindir@ 235 build = @build@236 227 build_alias = @build_alias@ 237 build_cpu = @build_cpu@238 build_os = @build_os@239 build_vendor = @build_vendor@240 228 builddir = @builddir@ 241 229 datadir = @datadir@ … … 244 232 dvidir = @dvidir@ 245 233 exec_prefix = @exec_prefix@ 246 host = @host@247 234 host_alias = @host_alias@ 248 host_cpu = @host_cpu@249 host_os = @host_os@250 host_vendor = @host_vendor@251 235 htmldir = @htmldir@ 252 236 includedir = @includedir@ … … 275 259 276 260 # create object files in directory with source files 277 AUTOMAKE_OPTIONS = subdir-objects261 AUTOMAKE_OPTIONS = foreign subdir-objects 278 262 279 263 # put into lib for now 280 264 cfalibdir = ${CFA_LIBDIR} 281 265 cfalib_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}} 266 noinst_DATA = ../src/prelude.c 267 AM_CFLAGS = -g -Wall -Wno-unused-function @ARCH_FLAGS@ @CONFIG_CFLAGS@ 268 AM_CFAFLAGS = @CONFIG_CFAFLAGS@ 269 MOSTLYCLEANFILES = bootloader.c builtins.cf extras.cf gcc-builtins.c gcc-builtins.cf prelude.cf 270 MAINTAINERCLEANFILES = ${addprefix ${libdir}/,${cfalib_DATA}} ${addprefix ${libdir}/,${lib_LIBRARIES}} 284 271 all: all-am 285 272 286 273 .SUFFIXES: 287 $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@$(srcdir)/Makefile.am $(am__configure_deps)274 $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) 288 275 @for dep in $?; do \ 289 276 case '$(am__configure_deps)' in \ … … 294 281 esac; \ 295 282 done; \ 296 echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/prelude/Makefile'; \283 echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign prelude/Makefile'; \ 297 284 $(am__cd) $(top_srcdir) && \ 298 $(AUTOMAKE) --foreign src/prelude/Makefile285 $(AUTOMAKE) --foreign prelude/Makefile 299 286 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status 300 287 @case '$?' in \ … … 309 296 cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh 310 297 311 $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@$(am__configure_deps)298 $(top_srcdir)/configure: $(am__configure_deps) 312 299 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) 314 301 cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh 315 302 $(am__aclocal_m4_deps): … … 399 386 fi 400 387 mostlyclean-generic: 388 -test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES) 401 389 402 390 clean-generic: … … 501 489 502 490 # create extra forward types/declarations to reduce inclusion of library files 503 extras.cf : extras.regxextras.c504 ${AM_V_GEN} @BACKEND_CC@ @CFA_FLAGS@ -E ${srcdir}/extras.c | grep -f extras.regx > ${srcdir}/extras.cf491 extras.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 505 493 506 494 # 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 > $@ 495 gcc-builtins.cf : gcc-builtins.c ${srcdir}/prototypes.sed 496 ${AM_V_GEN}gcc -I${srcdir} -E -P $< | sed -r -f ${srcdir}/prototypes.sed > $@ 497 498 gcc-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 501 prelude.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 512 505 513 506 builtins.def : … … 517 510 # create forward declarations for cfa builtins 518 511 builtins.cf : builtins.c ${CC} 519 ${AM_V_GEN} ${CC} -E -P ${<} -o ${@} -MD -MP -MF $(DEPDIR)/builtins.Po512 ${AM_V_GEN}gcc ${AM_CFLAGS} -E -P ${<} -o ${@} -MD -MP -MF $(DEPDIR)/builtins.Po 520 513 ${AM_V_at}sed -i 's/builtins.o/builtins.cf/g' $(DEPDIR)/builtins.Po 521 514 522 515 include $(DEPDIR)/builtins.Po 523 516 524 ../ libcfa/libcfa-prelude.c : prelude.cf extras.cf gcc-builtins.cf builtins.cf ${abs_top_srcdir}/src/driver/cfa-cpp525 ${AM_V_GEN} ${abs_top_srcdir}/src/driver/cfa-cpp-l prelude.cf $@ # use src/cfa-cpp as not in lib until after install526 527 bootloader.c : bootloader.cf prelude.cf extras.cf gcc-builtins.cf builtins.cf ${abs_top_srcdir}/src/driver/cfa-cpp528 ${AM_V_GEN} ${abs_top_srcdir}/src/driver/cfa-cpp -tpmbootloader.cf $@ # use src/cfa-cpp as not in lib until after install517 ../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 520 bootloader.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 529 522 530 523 maintainer-clean-local : -
libcfa/prelude/builtins.c
rf9feab8 r90152a4 9 9 // Author : Peter A. Buhr 10 10 // Created On : Fri Jul 21 16:21:03 2017 11 // Last Modified By : Andrew Beach12 // Last Modified On : Tus Jul 25 15:33:00 201713 // Update Count : 1411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 5 21:40:38 2018 13 // Update Count : 20 14 14 // 15 15 … … 18 18 typedef unsigned long long __cfaabi_abi_exception_type_t; 19 19 20 #include "../libcfa/virtual.h" 21 #include "../libcfa/exception.h" 20 #include "../src/virtual.h" 21 #include "../src/exception.h" 22 23 void exit( int status, const char fmt[], ... ) __attribute__ (( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ )); 24 void abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )); 25 26 // increment/decrement unification 27 28 static inline forall( dtype T | { T& ?+=?( T&, one_t ); } ) 29 T& ++? ( T& x ) { return x += 1; } 30 31 static inline forall( dtype T | sized(T) | { void ?{}( T&, T ); void ^?{}( T& ); T& ?+=?( T&, one_t ); } ) 32 T& ?++ ( T& x ) { T tmp = x; x += 1; return tmp; } 33 34 static inline forall( dtype T | { T& ?-=?( T&, one_t ); } ) 35 T& --? ( T& x ) { return x -= 1; } 36 37 static inline forall( dtype T | sized(T) | { void ?{}( T&, T ); void ^?{}( T& ); T& ?-=?( T&, one_t ); } ) 38 T& ?-- ( T& x ) { T tmp = x; x -= 1; return tmp; } 22 39 23 40 // exponentiation operator implementation … … 41 58 static inline long int ?\?( long int ep, unsigned long int y ) { // disallow negative exponent 42 59 if ( y == 0 ) return 1; // base case 43 44 45 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) 46 63 if ( (y & 1) == 1 ) op *= ep; // odd ? 47 64 ep *= ep; 48 65 } // for 49 66 return ep * op; 50 67 } // ?\? 51 68 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 // } // ?\? 69 static inline forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); } ) 70 T ?\?( 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 } // ?\? 64 79 65 80 // unsigned computation may be faster and larger 66 81 static inline unsigned long int ?\?( unsigned long int ep, unsigned long int y ) { // disallow negative exponent 67 82 if ( y == 0 ) return 1; // base case 68 69 70 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) 71 86 if ( (y & 1) == 1 ) op *= ep; // odd ? 72 87 ep *= ep; 73 88 } // for 74 89 return ep * op; 75 90 } // ?\? 76 91 77 92 static inline double ?\?( long int x, signed long int y ) { // allow negative exponent 78 79 93 if ( y >= 0 ) return (double)(x \ (unsigned long int)y); 94 else return 1.0 / x \ (unsigned int)(-y); 80 95 } // ?\? 81 96 -
libcfa/prelude/builtins.def
rf9feab8 r90152a4 190 190 191 191 /* 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. */ 193 193 #undef DEF_CILK_BUILTIN_STUB 194 194 #define DEF_CILK_BUILTIN_STUB(ENUM, NAME) \ … … 204 204 205 205 /* 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 207 207 libtsan library. */ 208 208 #undef DEF_SANITIZER_BUILTIN … … 217 217 #define DEF_CILKPLUS_BUILTIN(ENUM, NAME, TYPE, ATTRS) \ 218 218 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) 220 220 221 221 /* Builtin used by the implementation of Pointer Bounds Checker. */ … … 927 927 DEF_GCC_BUILTIN (BUILT_IN_LINE, "LINE", BT_FN_INT, ATTR_NOTHROW_LEAF_LIST) 928 928 929 #if 0 //Ifdefed out because we hard-coded the proper overloadings of the atomic built-ins 929 930 /* Synchronization Primitives. */ 930 931 #include "sync-builtins.def" 931 932 932 #if 0933 933 /* Offloading and Multi Processing builtins. */ 934 934 #include "omp-builtins.def" -
libcfa/prelude/extras.regx
rf9feab8 r90152a4 1 1 typedef.* size_t; 2 2 typedef.* ptrdiff_t; 3 typedef.* __int8_t; 4 typedef.* __int16_t; 5 typedef.* __int32_t; 6 typedef.* __int64_t; 7 typedef.* __uint8_t; 8 typedef.* __uint16_t; 9 typedef.* __uint32_t; 10 typedef.* __uint64_t; 3 11 typedef.* int8_t; 4 12 typedef.* int16_t; -
libcfa/prelude/prelude.old.cf
rf9feab8 r90152a4 7 7 // Created On : Sat Nov 29 07:23:41 2014 8 8 // Last Modified By : Peter A. Buhr 9 // Last Modified On : S at Oct 28 16:33:09 201710 // Update Count : 10 29 // Last Modified On : Sun Apr 22 13:21:47 2018 10 // Update Count : 103 11 11 // 12 12 … … 39 39 // ------------------------------------------------------------ 40 40 41 _Bool ?++( _Bool & ), ?++( volatile _Bool & );42 _Bool ?--( _Bool & ), ?--( volatile _Bool & );43 41 signed short ?++( signed short & ), ?++( volatile signed short & ); 44 42 signed short ?--( signed short & ), ?--( volatile signed short & ); … … 94 92 // ------------------------------------------------------------ 95 93 96 _Bool ++?( _Bool & ), --?( _Bool & );97 94 signed short ++?( signed short & ), --?( signed short & ); 98 95 signed int ++?( signed int & ), --?( signed int & ); … … 125 122 forall( ftype FT ) FT & *?( FT * ); 126 123 127 _Bool +?( _Bool ), -?( _Bool ) , ~?( _Bool );124 _Bool +?( _Bool ), -?( _Bool ); 128 125 signed int +?( signed int ), -?( signed int ), ~?( signed int ); 129 126 unsigned int +?( unsigned int ), -?( unsigned int ), ~?( unsigned int ); … … 145 142 !?( float _Complex ), !?( double _Complex ), !?( long double _Complex ); 146 143 147 forall 148 forall 149 forall 150 forall 151 forall 144 forall( dtype DT ) int !?( DT * ); 145 forall( dtype DT ) int !?( const DT * ); 146 forall( dtype DT ) int !?( volatile DT * ); 147 forall( dtype DT ) int !?( const volatile DT * ); 148 forall( ftype FT ) int !?( FT * ); 152 149 153 150 // ------------------------------------------------------------ … … 157 154 // ------------------------------------------------------------ 158 155 159 _Bool ?*?( _Bool, _Bool ), ?/?( _Bool, _Bool ), ?%?( _Bool, _Bool );160 156 signed int ?*?( signed int, signed int ), ?/?( signed int, signed int ), ?%?( signed int, signed int ); 161 157 unsigned int ?*?( unsigned int, unsigned int ), ?/?( unsigned int, unsigned int ), ?%?( unsigned int, unsigned int ); … … 215 211 // ------------------------------------------------------------ 216 212 217 _Bool ?<<?( _Bool, _Bool ), ?>>?( _Bool, _Bool );218 213 signed int ?<<?( signed int, signed int ), ?>>?( signed int, signed int ); 219 214 unsigned int ?<<?( unsigned int, unsigned int ), ?>>?( unsigned int, unsigned int ); … … 467 462 468 463 469 _Bool ?*=?( _Bool &, _Bool ), ?*=?( volatile _Bool &, _Bool );470 464 char ?*=?( char &, char ), ?*=?( volatile char &, char ); 471 465 char signed ?*=?( char signed &, char signed ), ?*=?( volatile char signed &, char signed ); … … 534 528 unsigned long long int ?-=?( unsigned long long int &, unsigned long long int ), ?-=?( volatile unsigned long long int &, unsigned long long int ); 535 529 536 _Bool ?<<=?( _Bool &, _Bool ), ?<<=?( volatile _Bool &, _Bool );537 530 char ?<<=?( char &, char ), ?<<=?( volatile char &, char ); 538 531 char signed ?<<=?( char signed &, char signed ), ?<<=?( volatile char signed &, char signed ); … … 547 540 unsigned long long int ?<<=?( unsigned long long int &, unsigned long long int ), ?<<=?( volatile unsigned long long int &, unsigned long long int ); 548 541 549 _Bool ?>>=?( _Bool &, _Bool ), ?>>=?( volatile _Bool &, _Bool );550 542 char ?>>=?( char &, char ), ?>>=?( volatile char &, char ); 551 543 char signed ?>>=?( char signed &, char signed ), ?>>=?( volatile char signed &, char signed ); … … 736 728 forall( dtype DT ) void ?{}( volatile DT * &, DT * ); 737 729 forall( dtype DT ) void ?{}( volatile DT * &, volatile DT * ); 738 739 730 forall( dtype DT ) void ?{}( const volatile DT * &, DT * ); 740 731 forall( dtype DT ) void ?{}( const volatile DT * &, const DT * ); -
libcfa/prelude/prototypes.awk
rf9feab8 r90152a4 5 5 # file "LICENCE" distributed with Cforall. 6 6 # 7 # prototypes.awk -- 7 # prototypes.awk -- 8 8 # 9 9 # Author : Peter A. Buhr … … 12 12 # Last Modified On : Tue Jul 5 14:32:52 2016 13 13 # Update Count : 32 14 # 14 # 15 15 16 16 # http://llvm.org/svn/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def … … 83 83 } # BEGIN 84 84 85 /BT_FN/ { 85 /BT_FN/ { 86 86 for (i = 1; i <= NF; i++) { 87 87 if( match($i, "BT_FN") != 0 ) { … … 116 116 117 117 # 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 119 119 type = types[t]; 120 120 if ( index( prototype, type ) == 1 ) { # found match … … 150 150 # extras 151 151 printf( "\n#include \"builtins.def\"\n\n" ); 152 printf( "\n#include \"sync-builtins.cf\"\n\n" ); 152 153 printf( "extern const char *__PRETTY_FUNCTION__;\n" ); 153 154 } # END -
libcfa/src/assert.cfa
rf9feab8 r90152a4 17 17 #include <stdarg.h> // varargs 18 18 #include <stdio.h> // fprintf 19 #include "bits/debug.h "19 #include "bits/debug.hfa" 20 20 21 21 extern "C" { 22 22 extern const char * __progname; // global name of running executable (argv[0]) 23 23 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\"" 25 25 26 26 // called by macro assert in assert.h 27 27 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 ); 29 29 abort(); 30 30 } … … 33 33 void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) { 34 34 __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 ); 36 36 37 37 va_list args; -
libcfa/src/bits/algorithm.hfa
rf9feab8 r90152a4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // bits/algorithms.h -- Builtins for exception handling.7 // bits/algorithms.hfa -- Builtins for exception handling. 8 8 // 9 9 // Author : Thierry Delisle -
libcfa/src/bits/align.hfa
rf9feab8 r90152a4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // align.h --7 // align.hfa -- 8 8 // 9 9 // Author : Thierry Delisle -
libcfa/src/bits/containers.hfa
rf9feab8 r90152a4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // bits/containers.h -- Intrusive generic containers.h7 // bits/containers.hfa -- Intrusive generic containers.hfa 8 8 // 9 9 // Author : Thierry Delisle … … 15 15 #pragma once 16 16 17 #include "bits/align.h "18 #include "bits/defs.h "17 #include "bits/align.hfa" 18 #include "bits/defs.hfa" 19 19 20 20 //----------------------------------------------------------------------------- … … 140 140 141 141 #ifdef __cforall 142 142 143 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(t his.tail != NULL);151 *t his.tail = val;152 t his.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 ); 153 154 } 154 155 … … 167 168 168 169 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 ) { 170 171 T * val = *it; 171 172 verify( val ); … … 173 174 (*it) = get_next( *val ); 174 175 175 if( t his.tail == &get_next( *val ) ) {176 t his.tail = it;176 if( tail == &get_next( *val ) ) { 177 tail = it; 177 178 } 178 179 179 180 get_next( *val ) = NULL; 180 181 181 verify( ( this.head == NULL) == (&this.head == this.tail) );182 verify( *t his.tail == NULL );182 verify( (head == NULL) == (&head == tail) ); 183 verify( *tail == NULL ); 183 184 return val; 184 185 } 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 206 struct __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 11 11 // Last Modified By : 12 12 // Last Modified On : 13 // Update Count : 013 // Update Count : 1 14 14 // 15 15 … … 47 47 void __cfaabi_dbg_bits_release() __attribute__((__weak__)) {} 48 48 49 void __cfaabi_dbg_bits_print_safe ( const char fmt[], ... ) __attribute__(( format 49 void __cfaabi_dbg_bits_print_safe ( const char fmt[], ... ) __attribute__(( format(printf, 1, 2) )) { 50 50 va_list args; 51 51 … … 60 60 } 61 61 62 void __cfaabi_dbg_bits_print_nolock( const char fmt[], ... ) __attribute__(( format 62 void __cfaabi_dbg_bits_print_nolock( const char fmt[], ... ) __attribute__(( format(printf, 1, 2) )) { 63 63 va_list args; 64 64 … … 76 76 } 77 77 78 void __cfaabi_dbg_bits_print_buffer( char in_buffer[], int in_buffer_size, const char fmt[], ... ) __attribute__(( format 78 void __cfaabi_dbg_bits_print_buffer( char in_buffer[], int in_buffer_size, const char fmt[], ... ) __attribute__(( format(printf, 3, 4) )) { 79 79 va_list args; 80 80 -
libcfa/src/bits/debug.hfa
rf9feab8 r90152a4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // debug.h --7 // debug.hfa -- 8 8 // 9 9 // Author : Thierry Delisle 10 10 // Created On : Mon Nov 28 12:27:26 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 10:02:24 201713 // Update Count : 112 // Last Modified On : Thu Feb 8 12:35:19 2018 13 // Update Count : 2 14 14 // 15 15 … … 41 41 extern void __cfaabi_dbg_bits_acquire(); 42 42 extern void __cfaabi_dbg_bits_release(); 43 extern void __cfaabi_dbg_bits_print_safe ( const char fmt[], ... ) __attribute__(( format 44 extern void __cfaabi_dbg_bits_print_nolock( const char fmt[], ... ) __attribute__(( format 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) )); 45 45 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 46 extern void __cfaabi_dbg_bits_print_buffer( char buffer[], int buffer_size, const char fmt[], ... ) __attribute__(( format(printf, 3, 4) )); 47 47 #ifdef __cforall 48 48 } -
libcfa/src/concurrency/alarm.cfa
rf9feab8 r90152a4 10 10 // Created On : Fri Jun 2 11:31:25 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 21 22:35:18 201713 // Update Count : 112 // Last Modified On : Fri May 25 06:25:47 2018 13 // Update Count : 67 14 14 // 15 15 … … 18 18 #include <stdio.h> 19 19 #include <string.h> 20 #include <time.h>21 20 #include <unistd.h> 22 21 #include <sys/time.h> 23 22 } 24 23 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" 66 27 67 28 //============================================================================================= … … 69 30 //============================================================================================= 70 31 71 __cfa_time_t__kernel_get_time() {32 Time __kernel_get_time() { 72 33 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 }; 75 36 } 76 37 77 void __kernel_set_timer( __cfa_time_talarm ) {78 itimerval val = { &alarm };79 setitimer( ITIMER_REAL, & val, NULL );38 void __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 ); 80 41 } 81 42 … … 84 45 //============================================================================================= 85 46 86 void ?{}( alarm_node_t & this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time) {47 void ?{}( alarm_node_t & this, thread_desc * thrd, Time alarm, Duration period ) with( this ) { 87 48 this.thrd = thrd; 88 49 this.alarm = alarm; 89 50 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; 93 54 } 94 55 95 void ?{}( alarm_node_t & this, processor * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time) {56 void ?{}( alarm_node_t & this, processor * proc, Time alarm, Duration period ) with( this ) { 96 57 this.proc = proc; 97 58 this.alarm = alarm; 98 59 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; 102 63 } 103 64 … … 108 69 } 109 70 110 __cfaabi_dbg_debug_do( bool validate( alarm_list_t * this ) { 71 #if !defined(NDEBUG) && (defined(__CFA_DEBUG__) || defined(__CFA_VERIFY__)) 72 bool validate( alarm_list_t * this ) { 111 73 alarm_node_t ** it = &this->head; 112 74 while( (*it) ) { … … 115 77 116 78 return it == this->tail; 117 }) 79 } 80 #endif 118 81 119 82 static inline void insert_at( alarm_list_t * this, alarm_node_t * n, __alarm_it_t p ) { -
libcfa/src/concurrency/coroutine.hfa
rf9feab8 r90152a4 10 10 // Created On : Mon Nov 28 12:27:26 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 30 07:58:29 201713 // Update Count : 312 // Last Modified On : Fri Mar 30 18:23:45 2018 13 // Update Count : 8 14 14 // 15 15 … … 32 32 //----------------------------------------------------------------------------- 33 33 // 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 37 void ?{}( coroutine_desc & this, const char * name, void * storage, size_t storageSize ); 38 void ^?{}( coroutine_desc & this ); 39 40 static inline void ?{}( coroutine_desc & this) { this{ "Anonymous Coroutine", NULL, 0 }; } 41 static inline void ?{}( coroutine_desc & this, size_t stackSize) { this{ "Anonymous Coroutine", NULL, stackSize }; } 42 static inline void ?{}( coroutine_desc & this, void * storage, size_t storageSize ) { this{ "Anonymous Coroutine", storage, storageSize }; } 43 static inline void ?{}( coroutine_desc & this, const char * name) { this{ name, NULL, 0 }; } 44 static inline void ?{}( coroutine_desc & this, const char * name, size_t stackSize ) { this{ name, NULL, stackSize }; } 39 45 40 46 //----------------------------------------------------------------------------- … … 60 66 } 61 67 62 // Get current coroutine63 extern thread_local coroutine_desc * volatile this_coroutine;64 65 68 // Private wrappers for context switch and stack creation 66 69 extern void CoroutineCtxSwitch(coroutine_desc * src, coroutine_desc * dst); … … 69 72 // Suspend implementation inlined for performance 70 73 static 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 ); 72 80 73 81 assertf( src->last != 0, … … 86 94 forall(dtype T | is_coroutine(T)) 87 95 static 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 ); 89 102 coroutine_desc * dst = get_coroutine(cor); 90 103 … … 104 117 dst->last = src; 105 118 dst->starter = dst->starter ? dst->starter : src; 106 } // if119 } 107 120 108 121 // always done for performance testing … … 111 124 112 125 static 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 ); 114 132 115 133 // not resuming self ? … … 122 140 // set last resumer 123 141 dst->last = src; 124 } // if142 } 125 143 126 144 // always done for performance testing -
libcfa/src/concurrency/invoke.c
rf9feab8 r90152a4 10 10 // Created On : Tue Jan 17 12:27:26 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 21 22:28:33 201713 // Update Count : 112 // Last Modified On : Fri Feb 9 16:37:42 2018 13 // Update Count : 5 14 14 // 15 15 … … 28 28 extern void __suspend_internal(void); 29 29 extern void __leave_coroutine(void); 30 extern void __finish_creation(void); 30 31 extern void __leave_thread_monitor( struct thread_desc * this ); 31 32 extern void disable_interrupts(); … … 45 46 cor->state = Active; 46 47 48 enable_interrupts( __cfaabi_dbg_ctx ); 49 47 50 main( this ); 48 51 … … 51 54 //Final suspend, should never return 52 55 __leave_coroutine(); 53 abortf("Resumed dead coroutine");56 __cabi_abort( "Resumed dead coroutine" ); 54 57 } 55 58 … … 62 65 // First suspend, once the thread arrives here, 63 66 // the function pointer to main can be invalidated without risk 64 __ suspend_internal();67 __finish_creation(); 65 68 66 69 // Fetch the thread handle from the user defined thread structure 67 70 struct thread_desc* thrd = get_thread( this ); 71 thrd->self_cor.last = NULL; 68 72 69 73 // Officially start the thread by enabling preemption … … 81 85 //Final suspend, should never return 82 86 __leave_thread_monitor( thrd ); 83 abortf("Resumed dead thread");87 __cabi_abort( "Resumed dead thread" ); 84 88 } 85 89 … … 93 97 struct coStack_t* stack = &get_coroutine( this )->stack; 94 98 95 #if defined( __i386 __)99 #if defined( __i386 ) 96 100 97 101 struct FakeStack { … … 114 118 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F; //Vol. 1 8-7 115 119 116 #elif defined( __x86_64 __)120 #elif defined( __x86_64 ) 117 121 118 122 struct FakeStack { … … 133 137 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520 134 138 ((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 135 157 #else 136 #error Only __i386__ and __x86_64__ is supported for threads in cfa158 #error uknown hardware architecture 137 159 #endif 138 160 } -
libcfa/src/concurrency/invoke.h
rf9feab8 r90152a4 10 10 // Created On : Tue Jan 17 12:27:26 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 21 22:28:56 201713 // Update Count : 114 // 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" 19 19 20 20 #ifdef __cforall … … 25 25 #ifndef _INVOKE_H_ 26 26 #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 27 45 28 46 #ifdef __cforall … … 30 48 static inline struct thread_desc * & get_next( struct thread_desc & this ); 31 49 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; 32 62 } 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 33 67 #endif 34 68 35 69 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 56 77 }; 57 78 … … 59 80 60 81 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 78 88 }; 79 89 … … 83 93 84 94 // 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) ); 86 96 }; 87 97 … … 111 121 struct __monitor_group_t { 112 122 // currently held monitors 113 __ small_array_t(monitor_desc*) __cfa_anonymous_object;123 __cfa_anonymous_object( __small_array_t(monitor_desc*) ); 114 124 115 125 // last function that acquired monitors … … 122 132 struct coroutine_desc self_cor; 123 133 134 // current active context 135 struct coroutine_desc * curr_cor; 136 124 137 // monitor body used for mutual exclusion 125 138 struct monitor_desc self_mon; … … 127 140 // pointer to monitor with sufficient lifetime for current monitors 128 141 struct monitor_desc * self_mon_p; 142 143 // pointer to the cluster on which the thread is running 144 struct cluster * curr_cluster; 129 145 130 146 // monitors currently held by this thread … … 134 150 // instrusive link field for threads 135 151 struct thread_desc * next; 152 153 struct { 154 struct thread_desc * next; 155 struct thread_desc * prev; 156 } node; 136 157 }; 137 158 … … 140 161 static inline thread_desc * & get_next( thread_desc & this ) { 141 162 return this.next; 163 } 164 165 static inline [thread_desc *&, thread_desc *& ] __get( thread_desc & this ) { 166 return this.node.[next, prev]; 142 167 } 143 168 … … 193 218 void CtxSwitch( void * from, void * to ) asm ("CtxSwitch"); 194 219 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 ) 196 226 #define CtxGet( ctx ) __asm__ ( \ 197 227 "movq %%rsp,%0\n" \ 198 228 "movq %%rbp,%1\n" \ 199 229 : "=rm" (ctx.SP), "=rm" (ctx.FP) ) 200 #elif defined( __ i386__)230 #elif defined( __ARM_ARCH ) 201 231 #define CtxGet( ctx ) __asm__ ( \ 202 "mov l %%esp,%0\n" \203 "mov l %%ebp,%1\n" \232 "mov %0,%%sp\n" \ 233 "mov %1,%%r11\n" \ 204 234 : "=rm" (ctx.SP), "=rm" (ctx.FP) ) 235 #else 236 #error unknown hardware architecture 205 237 #endif 206 238 -
libcfa/src/concurrency/kernel.hfa
rf9feab8 r90152a4 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:58:39 201713 // Update Count : 212 // Last Modified On : Tue Apr 10 14:46:49 2018 13 // Update Count : 10 14 14 // 15 15 … … 19 19 20 20 #include "invoke.h" 21 #include "time_t.hfa" 21 22 22 23 extern "C" { 23 24 #include <pthread.h> 25 #include <semaphore.h> 24 26 } 25 27 … … 39 41 40 42 //----------------------------------------------------------------------------- 43 // Processor 44 extern struct cluster * mainCluster; 45 46 enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule, Callback }; 47 48 typedef void (*__finish_callback_fptr_t)(void); 49 50 //TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI) 51 struct 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 }; 88 static inline void ?{}(FinishAction & this) { 89 this.action_code = No_Action; 90 this.thrd = NULL; 91 this.lock = NULL; 92 } 93 static inline void ^?{}(FinishAction & this) {} 94 95 // Processor 96 coroutine processorCtx_t { 97 struct processor * proc; 98 }; 99 100 // Wrapper around kernel threads 101 struct 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 148 void ?{}(processor & this, const char * name, struct cluster & cltr); 149 void ^?{}(processor & this); 150 151 static inline void ?{}(processor & this) { this{ "Anonymous Processor", *mainCluster}; } 152 static inline void ?{}(processor & this, struct cluster & cltr) { this{ "Anonymous Processor", cltr}; } 153 static inline void ?{}(processor & this, const char * name) { this{name, *mainCluster }; } 154 155 static inline [processor *&, processor *& ] __get( processor & this ) { 156 return this.node.[next, prev]; 157 } 158 159 //----------------------------------------------------------------------------- 41 160 // Cluster 42 161 struct cluster { … … 47 166 __queue_t(thread_desc) ready_queue; 48 167 168 // Name of the cluster 169 const char * name; 170 49 171 // 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 }; 189 extern Duration default_preemption(); 190 191 void ?{} (cluster & this, const char * name, Duration preemption_rate); 54 192 void ^?{}(cluster & this); 55 193 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); 194 static inline void ?{} (cluster & this) { this{"Anonymous Cluster", default_preemption()}; } 195 static inline void ?{} (cluster & this, Duration preemption_rate) { this{"Anonymous Cluster", preemption_rate}; } 196 static inline void ?{} (cluster & this, const char * name) { this{name, default_preemption()}; } 197 198 static inline [cluster *&, cluster *& ] __get( cluster & this ) { 199 return this.node.[next, prev]; 200 } 117 201 118 202 // Local Variables: // -
libcfa/src/concurrency/kernel_private.hfa
rf9feab8 r90152a4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // kernel_private.h --7 // kernel_private.hfa -- 8 8 // 9 9 // Author : Thierry Delisle 10 10 // Created On : Mon Feb 13 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:58:09 201713 // Update Count : 212 // Last Modified On : Thu Mar 29 14:06:40 2018 13 // Update Count : 3 14 14 // 15 15 16 16 #pragma once 17 17 18 #include "kernel "19 #include "thread "18 #include "kernel.hfa" 19 #include "thread.hfa" 20 20 21 #include "alarm.h "21 #include "alarm.hfa" 22 22 23 23 … … 48 48 void BlockInternal(__spinlock_t * locks [], unsigned short count); 49 49 void BlockInternal(__spinlock_t * locks [], unsigned short count, thread_desc * thrds [], unsigned short thrd_count); 50 void BlockInternal(__finish_callback_fptr_t callback); 50 51 void LeaveThread(__spinlock_t * lock, thread_desc * thrd); 51 52 52 53 //----------------------------------------------------------------------------- 53 54 // Processor 54 coroutine processorCtx_t { 55 processor * proc; 56 }; 55 void main(processorCtx_t *); 57 56 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); 57 static inline void wake_fast(processor * this) { 58 __cfaabi_dbg_print_safe("Kernel : Waking up processor %p\n", this); 59 post( this->idleLock ); 60 } 61 62 static inline void wake(processor * this) { 63 disable_interrupts(); 64 wake_fast(this); 65 enable_interrupts( __cfaabi_dbg_ctx ); 66 } 63 67 64 68 struct event_kernel_t { … … 69 73 extern event_kernel_t * event_kernel; 70 74 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; 75 struct __cfa_kernel_preemption_state_t { 76 bool enabled; 77 bool in_progress; 78 unsigned short disable_count; 79 }; 74 80 75 extern volatile thread_local bool preemption_in_progress; 76 extern volatile thread_local unsigned short disable_preempt_count; 81 extern volatile thread_local __cfa_kernel_preemption_state_t preemption_state; 77 82 78 83 //----------------------------------------------------------------------------- … … 85 90 extern void ThreadCtxSwitch(coroutine_desc * src, coroutine_desc * dst); 86 91 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 87 97 //----------------------------------------------------------------------------- 88 98 // Utils 89 99 #define KERNEL_STORAGE(T,X) static char storage_##X[sizeof(T)] 100 101 102 void doregister( struct cluster & cltr ); 103 void unregister( struct cluster & cltr ); 104 105 void doregister( struct cluster * cltr, struct thread_desc & thrd ); 106 void unregister( struct cluster * cltr, struct thread_desc & thrd ); 107 108 void doregister( struct cluster * cltr, struct processor * proc ); 109 void unregister( struct cluster * cltr, struct processor * proc ); 90 110 91 111 // Local Variables: // -
libcfa/src/concurrency/monitor.cfa
rf9feab8 r90152a4 10 10 // Created On : Thd Feb 23 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jul 31 14:59:05 201713 // Update Count : 312 // Last Modified On : Fri Mar 30 14:30:26 2018 13 // Update Count : 9 14 14 // 15 15 16 #include "monitor "17 18 #include <stdlib >16 #include "monitor.hfa" 17 18 #include <stdlib.hfa> 19 19 #include <inttypes.h> 20 20 21 #include "kernel_private.h "22 23 #include "bits/algorithm s.h"21 #include "kernel_private.hfa" 22 23 #include "bits/algorithm.hfa" 24 24 25 25 //----------------------------------------------------------------------------- … … 53 53 static inline __lock_size_t aggregate ( monitor_desc * storage [], const __waitfor_mask_t & mask ); 54 54 55 #ifndef __CFA_LOCK_NO_YIELD56 #define DO_LOCK lock_yield57 #else58 #define DO_LOCK lock59 #endif60 61 55 //----------------------------------------------------------------------------- 62 56 // Useful defines … … 90 84 static void __enter_monitor_desc( monitor_desc * this, const __monitor_group_t & group ) { 91 85 // 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); 96 91 97 92 if( !this->owner ) { … … 99 94 set_owner( this, thrd ); 100 95 101 __cfaabi_dbg_print_safe( "Kernel : mon is free \n");96 __cfaabi_dbg_print_safe( "Kernel : mon is free \n" ); 102 97 } 103 98 else if( this->owner == thrd) { … … 105 100 this->recursion += 1; 106 101 107 __cfaabi_dbg_print_safe( "Kernel : mon already owned \n");102 __cfaabi_dbg_print_safe( "Kernel : mon already owned \n" ); 108 103 } 109 104 else if( is_accepted( this, group) ) { … … 114 109 reset_mask( this ); 115 110 116 __cfaabi_dbg_print_safe( "Kernel : mon accepts \n");111 __cfaabi_dbg_print_safe( "Kernel : mon accepts \n" ); 117 112 } 118 113 else { 119 __cfaabi_dbg_print_safe( "Kernel : blocking \n");114 __cfaabi_dbg_print_safe( "Kernel : blocking \n" ); 120 115 121 116 // Some one else has the monitor, wait in line for it 122 117 append( this->entry_queue, thrd ); 118 123 119 BlockInternal( &this->lock ); 124 120 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); 126 122 127 123 // BlockInternal will unlock spinlock, no need to unlock ourselves … … 129 125 } 130 126 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); 132 128 133 129 // Release the lock and leave … … 138 134 static void __enter_monitor_dtor( monitor_desc * this, fptr_t func ) { 139 135 // 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); 144 141 145 142 146 143 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); 148 145 149 146 // No one has the monitor, just take it … … 156 153 // We already have the monitor... but where about to destroy it so the nesting will fail 157 154 // Abort! 158 abort f("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 ); 159 156 } 160 157 … … 163 160 __monitor_group_t group = { &this, 1, func }; 164 161 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" ); 166 163 167 164 // Wake the thread that is waiting for this … … 173 170 174 171 // Create the node specific to this wait operation 175 wait_ctx_primed( th is_thread, 0 )172 wait_ctx_primed( thrd, 0 ) 176 173 177 174 // Some one else has the monitor, wait for him to finish and then run … … 182 179 } 183 180 else { 184 __cfaabi_dbg_print_safe( "Kernel : blocking \n");185 186 wait_ctx( th is_thread, 0 )181 __cfaabi_dbg_print_safe( "Kernel : blocking \n" ); 182 183 wait_ctx( thrd, 0 ) 187 184 this->dtor_node = &waiter; 188 185 … … 195 192 } 196 193 197 __cfaabi_dbg_print_safe( "Kernel : Destroying %p\n", this);194 __cfaabi_dbg_print_safe( "Kernel : Destroying %p\n", this); 198 195 199 196 } … … 201 198 // Leave single monitor 202 199 void __leave_monitor_desc( monitor_desc * this ) { 203 // Lock the monitor spinlock , DO_LOCK to reduce contention204 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 ); 209 206 210 207 // Leaving a recursion level, decrement the counter … … 214 211 // it means we don't need to do anything 215 212 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); 217 214 unlock( this->lock ); 218 215 return; … … 232 229 void __leave_dtor_monitor_desc( monitor_desc * this ) { 233 230 __cfaabi_dbg_debug_do( 234 if( this_thread!= this->owner ) {235 abort f("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); 236 233 } 237 234 if( this->recursion != 1 ) { 238 abort f("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); 239 236 } 240 237 ) … … 248 245 249 246 // Lock the monitor now 250 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );247 lock( this->lock __cfaabi_dbg_ctx2 ); 251 248 252 249 disable_interrupts(); … … 261 258 // If we haven't left the last level of recursion 262 259 // it must mean there is an error 263 if( this->recursion != 0) { abort f("Thread internal monitor has unbalanced recursion"); }260 if( this->recursion != 0) { abort( "Thread internal monitor has unbalanced recursion" ); } 264 261 265 262 // Fetch the next thread, can be null … … 294 291 // Sorts monitors before entering 295 292 void ?{}( monitor_guard_t & this, monitor_desc * m [], __lock_size_t count, fptr_t func ) { 293 thread_desc * thrd = TL_GET( this_thread ); 294 296 295 // Store current array 297 296 this.m = m; 298 297 this.count = count; 299 298 300 // Sort monitors based on address -> TODO use a sort specialized for small numbers299 // Sort monitors based on address 301 300 __libcfa_small_sort(this.m, count); 302 301 303 302 // Save previous thread context 304 this.prev = th is_thread->monitors;303 this.prev = thrd->monitors; 305 304 306 305 // Update thread context (needed for conditions) 307 (th is_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); 310 309 311 310 // Enter the monitors in order … … 313 312 enter( group ); 314 313 315 // __cfaabi_dbg_print_safe( "MGUARD : entered\n");314 // __cfaabi_dbg_print_safe( "MGUARD : entered\n" ); 316 315 } 317 316 … … 319 318 // Dtor for monitor guard 320 319 void ^?{}( 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); 322 321 323 322 // Leave the monitors in order 324 323 leave( this.m, this.count ); 325 324 326 // __cfaabi_dbg_print_safe( "MGUARD : left\n");325 // __cfaabi_dbg_print_safe( "MGUARD : left\n" ); 327 326 328 327 // Restore thread context 329 this_thread->monitors = this.prev;328 TL_GET( this_thread )->monitors = this.prev; 330 329 } 331 330 … … 333 332 // Sorts monitors before entering 334 333 void ?{}( monitor_dtor_guard_t & this, monitor_desc * m [], fptr_t func ) { 334 // optimization 335 thread_desc * thrd = TL_GET( this_thread ); 336 335 337 // Store current array 336 338 this.m = *m; 337 339 338 340 // Save previous thread context 339 this.prev = th is_thread->monitors;341 this.prev = thrd->monitors; 340 342 341 343 // Update thread context (needed for conditions) 342 (th is_thread->monitors){m, 1, func};344 (thrd->monitors){m, 1, func}; 343 345 344 346 __enter_monitor_dtor( this.m, func ); … … 351 353 352 354 // Restore thread context 353 this_thread->monitors = this.prev;355 TL_GET( this_thread )->monitors = this.prev; 354 356 } 355 357 … … 363 365 } 364 366 365 void ?{}(__condition_criterion_t & this ) {366 this.ready = false;367 t his.target = NULL;368 this.owner = NULL;369 this.next = NULL;367 void ?{}(__condition_criterion_t & this ) with( this ) { 368 ready = false; 369 target = NULL; 370 owner = NULL; 371 next = NULL; 370 372 } 371 373 … … 391 393 392 394 // Create the node specific to this wait operation 393 wait_ctx( this_thread, user_info );395 wait_ctx( TL_GET( this_thread ), user_info ); 394 396 395 397 // Append the current wait operation to the ones already queued on the condition … … 430 432 //Some more checking in debug 431 433 __cfaabi_dbg_debug_do( 432 thread_desc * this_thrd = this_thread;434 thread_desc * this_thrd = TL_GET( this_thread ); 433 435 if ( this.monitor_count != this_thrd->monitors.size ) { 434 abort f( "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 ); 435 437 } 436 438 437 439 for(int i = 0; i < this.monitor_count; i++) { 438 440 if ( this.monitors[i] != this_thrd->monitors[i] ) { 439 abort f( "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] ); 440 442 } 441 443 } … … 476 478 lock_all( monitors, locks, count ); 477 479 480 478 481 // Create the node specific to this wait operation 479 wait_ctx_primed( this_thread, 0 )482 wait_ctx_primed( kernelTLS.this_thread, 0 ) 480 483 481 484 //save contexts … … 534 537 __lock_size_t actual_count = aggregate( mon_storage, mask ); 535 538 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); 537 540 538 541 if(actual_count == 0) return; 539 542 540 __cfaabi_dbg_print_buffer_local( "Kernel : waitfor internal proceeding\n" );543 __cfaabi_dbg_print_buffer_local( "Kernel : waitfor internal proceeding\n" ); 541 544 542 545 // Create storage for monitor context … … 555 558 __acceptable_t& accepted = mask[index]; 556 559 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" ); 558 561 verifyf( accepted.size == 1, "ERROR: Accepted dtor has more than 1 mutex parameter." ); 559 562 … … 567 570 } 568 571 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" ); 570 573 571 574 // Create the node specific to this wait operation 572 wait_ctx_primed( this_thread, 0 );575 wait_ctx_primed( kernelTLS.this_thread, 0 ); 573 576 574 577 // Save monitor states 575 578 monitor_save; 576 579 577 __cfaabi_dbg_print_buffer_local( "Kernel : baton of % dmonitors : ", count );580 __cfaabi_dbg_print_buffer_local( "Kernel : baton of %"PRIdFAST16" monitors : ", count ); 578 581 #ifdef __CFA_DEBUG_PRINT__ 579 582 for( int i = 0; i < count; i++) { … … 581 584 } 582 585 #endif 583 __cfaabi_dbg_print_buffer_local( "\n" );586 __cfaabi_dbg_print_buffer_local( "\n" ); 584 587 585 588 // Set the owners to be the next thread … … 592 595 monitor_restore; 593 596 594 __cfaabi_dbg_print_buffer_local( "Kernel : thread present, returned\n" );597 __cfaabi_dbg_print_buffer_local( "Kernel : thread present, returned\n" ); 595 598 } 596 599 … … 602 605 603 606 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" ); 605 608 606 609 unlock_all( locks, count ); … … 611 614 612 615 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" ); 616 619 617 620 // Create the node specific to this wait operation 618 wait_ctx_primed( this_thread, 0 );621 wait_ctx_primed( kernelTLS.this_thread, 0 ); 619 622 620 623 monitor_save; … … 622 625 623 626 for( __lock_size_t i = 0; i < count; i++) { 624 verify( monitors[i]->owner == this_thread );627 verify( monitors[i]->owner == kernelTLS.this_thread ); 625 628 } 626 629 … … 635 638 monitor_restore; 636 639 637 __cfaabi_dbg_print_buffer_local( "Kernel : exiting\n" );640 __cfaabi_dbg_print_buffer_local( "Kernel : exiting\n" ); 638 641 639 642 __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted); … … 644 647 645 648 static 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 ); 647 650 648 651 //Pass the monitor appropriately … … 676 679 static inline thread_desc * next_thread( monitor_desc * this ) { 677 680 //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); 679 682 __condition_criterion_t * urgent = pop( this->signal_stack ); 680 683 if( urgent ) { … … 737 740 static inline void lock_all( __spinlock_t * locks [], __lock_size_t count ) { 738 741 for( __lock_size_t i = 0; i < count; i++ ) { 739 DO_LOCK( *locks[i] __cfaabi_dbg_ctx2 );742 lock( *locks[i] __cfaabi_dbg_ctx2 ); 740 743 } 741 744 } … … 744 747 for( __lock_size_t i = 0; i < count; i++ ) { 745 748 __spinlock_t * l = &source[i]->lock; 746 DO_LOCK( *l __cfaabi_dbg_ctx2 );749 lock( *l __cfaabi_dbg_ctx2 ); 747 750 if(locks) locks[i] = l; 748 751 } … … 816 819 817 820 static inline void brand_condition( condition & this ) { 818 thread_desc * thrd = this_thread;821 thread_desc * thrd = TL_GET( this_thread ); 819 822 if( !this.monitors ) { 820 // __cfaabi_dbg_print_safe( "Branding\n");823 // __cfaabi_dbg_print_safe( "Branding\n" ); 821 824 assertf( thrd->monitors.data != NULL, "No current monitor to brand condition %p", thrd->monitors.data ); 822 825 this.monitor_count = thrd->monitors.size; -
libcfa/src/concurrency/monitor.hfa
rf9feab8 r90152a4 20 20 #include <assert.h> 21 21 #include "invoke.h" 22 #include "stdlib "22 #include "stdlib.hfa" 23 23 24 24 trait is_monitor(dtype T) { … … 27 27 }; 28 28 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;29 static 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; 39 39 } 40 40 … … 138 138 139 139 struct __acceptable_t { 140 __monitor_group_t;140 inline struct __monitor_group_t; 141 141 bool is_dtor; 142 142 }; -
libcfa/src/concurrency/preemption.hfa
rf9feab8 r90152a4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // preemption.h --7 // preemption.hfa -- 8 8 // 9 9 // Author : Thierry Delisle 10 10 // Created On : Mon Jun 5 14:20:42 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 21 22:34:25 201713 // Update Count : 112 // Last Modified On : Fri Mar 23 17:18:53 2018 13 // Update Count : 2 14 14 // 15 15 16 16 #pragma once 17 17 18 #include "alarm.h "19 #include "kernel_private.h "18 #include "alarm.hfa" 19 #include "kernel_private.hfa" 20 20 21 __attribute__((weak)) unsigned int default_preemption();22 21 void kernel_start_preemption(); 23 22 void kernel_stop_preemption(); 24 void update_preemption( processor * this, __cfa_time_t duration ); 25 void tick_preemption(); 23 void update_preemption( processor * this, Duration duration ); 26 24 27 25 struct preemption_scope { -
libcfa/src/concurrency/thread.cfa
rf9feab8 r90152a4 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 21 22:34:46 201713 // Update Count : 112 // Last Modified On : Fri Mar 30 17:19:52 2018 13 // Update Count : 8 14 14 // 15 15 16 #include "thread "16 #include "thread.hfa" 17 17 18 #include "kernel_private.h "18 #include "kernel_private.hfa" 19 19 20 20 #define __CFA_INVOKE_PRIVATE__ … … 26 26 } 27 27 28 extern volatile thread_local processor * this_processor;28 //extern volatile thread_local processor * this_processor; 29 29 30 30 //----------------------------------------------------------------------------- 31 31 // Thread ctors and dtors 32 void ?{}(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; 32 41 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); 40 45 41 (this.monitors){ &this.self_mon_p, 1, (fptr_t)0 };46 monitors{ &self_mon_p, 1, (fptr_t)0 }; 42 47 } 43 48 44 void ^?{}(thread_desc& this) { 45 ^(this.self_cor){}; 49 void ^?{}(thread_desc& this) with( this ) { 50 unregister(curr_cluster, this); 51 ^self_cor{}; 46 52 } 47 53 48 54 forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } ) 49 void ?{}( scoped(T)& this ) {50 (this.handle){};51 __thrd_start( this.handle);55 void ?{}( scoped(T)& this ) with( this ) { 56 handle{}; 57 __thrd_start(handle); 52 58 } 53 59 54 60 forall( 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);61 void ?{}( scoped(T)& this, P params ) with( this ) { 62 handle{ params }; 63 __thrd_start(handle); 58 64 } 59 65 60 66 forall( dtype T | sized(T) | is_thread(T) ) 61 void ^?{}( scoped(T)& this ) {62 ^ (this.handle){};67 void ^?{}( scoped(T)& this ) with( this ) { 68 ^handle{}; 63 69 } 64 70 … … 68 74 void __thrd_start( T& this ) { 69 75 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 ); 72 78 73 79 // __cfaabi_dbg_print_safe("Thread start : %p (t %p, c %p)\n", this, thrd_c, thrd_h); … … 75 81 disable_interrupts(); 76 82 create_stack(&thrd_c->stack, thrd_c->stack.size); 77 this_coroutine = thrd_c;83 kernelTLS.this_coroutine = thrd_c; 78 84 CtxStart(&this, CtxInvokeThread); 79 85 assert( thrd_c->last->stack.context ); … … 84 90 } 85 91 92 extern "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 86 100 void 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 ) ); 88 106 } 89 107 … … 94 112 } 95 113 114 // KERNEL ONLY 96 115 void ThreadCtxSwitch(coroutine_desc* src, coroutine_desc* dst) { 97 116 // set state of current coroutine to inactive … … 99 118 dst->state = Active; 100 119 101 //update the last resumer102 dst->last = src;103 104 120 // set new coroutine that the processor is executing 105 121 // and context switch to it 106 this_coroutine = dst;122 kernelTLS.this_coroutine = dst; 107 123 assert( src->stack.context ); 108 124 CtxSwitch( src->stack.context, dst->stack.context ); 109 this_coroutine = src;125 kernelTLS.this_coroutine = src; 110 126 111 127 // set state of new coroutine to active -
libcfa/src/concurrency/thread.hfa
rf9feab8 r90152a4 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:59:40 201713 // Update Count : 312 // Last Modified On : Thu Mar 29 14:07:11 2018 13 // Update Count : 4 14 14 // 15 15 … … 19 19 #include "invoke.h" 20 20 21 #include "coroutine" 22 #include "monitor" 21 #include "coroutine.hfa" 22 #include "kernel.hfa" 23 #include "monitor.hfa" 23 24 24 25 //----------------------------------------------------------------------------- 25 // Coroutine trait 26 // Anything that implements this trait can be resumed. 27 // Anything that is resumed is a coroutine. 26 // thread trait 28 27 trait is_thread(dtype T) { 29 28 void ^?{}(T& mutex this); … … 52 51 } 53 52 54 extern thread_local thread_desc * volatile this_thread;53 extern struct cluster * mainCluster; 55 54 56 55 forall( dtype T | is_thread(T) ) … … 59 58 //----------------------------------------------------------------------------- 60 59 // Ctors and dtors 61 void ?{}(thread_desc& this); 62 void ^?{}(thread_desc& this); 60 void ?{}(thread_desc & this, const char * const name, struct cluster & cl, void * storage, size_t storageSize ); 61 void ^?{}(thread_desc & this); 62 63 static inline void ?{}(thread_desc & this) { this{ "Anonymous Thread", *mainCluster, NULL, 0 }; } 64 static inline void ?{}(thread_desc & this, size_t stackSize ) { this{ "Anonymous Thread", *mainCluster, NULL, stackSize }; } 65 static inline void ?{}(thread_desc & this, void * storage, size_t storageSize ) { this{ "Anonymous Thread", *mainCluster, storage, storageSize }; } 66 static inline void ?{}(thread_desc & this, struct cluster & cl ) { this{ "Anonymous Thread", cl, NULL, 0 }; } 67 static inline void ?{}(thread_desc & this, struct cluster & cl, size_t stackSize ) { this{ "Anonymous Thread", cl, 0, stackSize }; } 68 static inline void ?{}(thread_desc & this, struct cluster & cl, void * storage, size_t storageSize ) { this{ "Anonymous Thread", cl, storage, storageSize }; } 69 static inline void ?{}(thread_desc & this, const char * const name) { this{ name, *mainCluster, NULL, 0 }; } 70 static inline void ?{}(thread_desc & this, const char * const name, struct cluster & cl ) { this{ name, cl, NULL, 0 }; } 71 static inline void ?{}(thread_desc & this, const char * const name, struct cluster & cl, size_t stackSize ) { this{ name, cl, NULL, stackSize }; } 63 72 64 73 //----------------------------------------------------------------------------- -
libcfa/src/containers/maybe.cfa
rf9feab8 r90152a4 14 14 // 15 15 16 #include <containers/maybe >16 #include <containers/maybe.hfa> 17 17 #include <assert.h> 18 18 -
libcfa/src/containers/pair.cfa
rf9feab8 r90152a4 11 11 // 12 12 13 #include <containers/pair >13 #include <containers/pair.hfa> 14 14 15 forall(otype R, otype S 15 forall(otype R, otype S 16 16 | { int ?==?(R, R); int ?<?(R, R); int ?<?(S, S); }) 17 17 int ?<?(pair(R, S) p, pair(R, S) q) { … … 19 19 } 20 20 21 forall(otype R, otype S 21 forall(otype R, otype S 22 22 | { int ?==?(R, R); int ?<?(R, R); int ?<=?(S, S); }) 23 23 int ?<=?(pair(R, S) p, pair(R, S) q) { … … 35 35 } 36 36 37 forall(otype R, otype S 37 forall(otype R, otype S 38 38 | { int ?==?(R, R); int ?>?(R, R); int ?>?(S, S); }) 39 39 int ?>?(pair(R, S) p, pair(R, S) q) { … … 41 41 } 42 42 43 forall(otype R, otype S 43 forall(otype R, otype S 44 44 | { int ?==?(R, R); int ?>?(R, R); int ?>=?(S, S); }) 45 45 int ?>=?(pair(R, S) p, pair(R, S) q) { -
libcfa/src/containers/result.cfa
rf9feab8 r90152a4 14 14 // 15 15 16 #include <containers/result >16 #include <containers/result.hfa> 17 17 #include <assert.h> 18 18 -
libcfa/src/containers/result.hfa
rf9feab8 r90152a4 28 28 struct result { 29 29 bool has_value; 30 in ner_result(T, E);30 inline union inner_result(T, E); 31 31 }; 32 32 -
libcfa/src/containers/vector.cfa
rf9feab8 r90152a4 14 14 // 15 15 16 #include <containers/vector >16 #include <containers/vector.hfa> 17 17 18 #include <stdlib >18 #include <stdlib.hfa> 19 19 20 20 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) -
libcfa/src/exception.c
rf9feab8 r90152a4 9 9 // Author : Andrew Beach 10 10 // Created On : Mon Jun 26 15:13:00 2017 11 // Last Modified By : Andrew Beach12 // Last Modified On : Th r Aug 17 15:45:00 201713 // Update Count : 711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Feb 22 18:17:34 2018 13 // Update Count : 11 14 14 // 15 15 … … 23 23 #include <stdio.h> 24 24 #include <unwind.h> 25 #include <bits/debug.h >25 #include <bits/debug.hfa> 26 26 27 27 // FIX ME: temporary hack to keep ARM build working … … 52 52 struct __cfaabi_ehm__try_resume_node * current_resume; 53 53 54 exception * current_exception;54 exception_t * current_exception; 55 55 int current_handler_index; 56 56 } shared_stack = {NULL, NULL, 0, 0}; … … 71 71 // This macro should be the only thing that needs to change across machines. Used in the personality function, way down 72 72 // in termination. 73 // struct _Unwind_Context * -> _Unwind_Reason_Code(*)(exception *)73 // struct _Unwind_Context * -> _Unwind_Reason_Code(*)(exception_t *) 74 74 #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)) 76 76 77 77 78 78 // RESUMPTION ================================================================ 79 79 80 void __cfaabi_ehm__throw_resume(exception * except) {80 void __cfaabi_ehm__throw_resume(exception_t * except) { 81 81 82 82 __cfaabi_dbg_print_safe("Throwing resumption exception\n"); … … 106 106 107 107 void __cfaabi_ehm__try_resume_setup(struct __cfaabi_ehm__try_resume_node * node, 108 _Bool (*handler)(exception * except)) {108 _Bool (*handler)(exception_t * except)) { 109 109 node->next = shared_stack.top_resume; 110 110 node->handler = handler; … … 126 126 }; 127 127 128 #define NODE_TO_EXCEPT(node) ((exception *)(1 + (node)))128 #define NODE_TO_EXCEPT(node) ((exception_t *)(1 + (node))) 129 129 #define EXCEPT_TO_NODE(except) ((struct __cfaabi_ehm__node *)(except) - 1) 130 130 131 131 // Creates a copy of the indicated exception and sets current_exception to it. 132 static void __cfaabi_ehm__allocate_exception( exception * except ) {132 static void __cfaabi_ehm__allocate_exception( exception_t * except ) { 133 133 struct exception_context_t * context = this_exception_context(); 134 134 … … 151 151 152 152 // Delete the provided exception, unsetting current_exception if relivant. 153 static void __cfaabi_ehm__delete_exception( exception * except ) {153 static void __cfaabi_ehm__delete_exception( exception_t * except ) { 154 154 struct exception_context_t * context = this_exception_context(); 155 155 … … 179 179 // If this isn't a rethrow (*except==0), delete the provided exception. 180 180 void __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 ); 182 182 } 183 183 … … 233 233 } 234 234 235 void __cfaabi_ehm__throw_terminate( exception * val ) {235 void __cfaabi_ehm__throw_terminate( exception_t * val ) { 236 236 __cfaabi_dbg_print_safe("Throwing termination exception\n"); 237 237 … … 348 348 // _Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher; 349 349 350 _Unwind_Reason_Code (*matcher)(exception *) =350 _Unwind_Reason_Code (*matcher)(exception_t *) = 351 351 MATCHER_FROM_CONTEXT(context); 352 352 int index = matcher(shared_stack.current_exception); … … 409 409 __attribute__((noinline)) 410 410 void __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)) { 413 413 //! volatile int xy = 0; 414 414 //! printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy); … … 453 453 // 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. 454 454 455 #if defined( __ x86_64__ ) || defined( __i386__)455 #if defined( __i386 ) || defined( __x86_64 ) 456 456 asm ( 457 457 //HEADER … … 476 476 // " .section .note.GNU-stack,\"x\",@progbits\n" 477 477 ); 478 #endif // __ x86_64__ || __i386__478 #endif // __i386 || __x86_64 -
libcfa/src/exception.h
rf9feab8 r90152a4 9 9 // Author : Andrew Beach 10 10 // Created On : Mon Jun 26 15:11:00 2017 11 // Last Modified By : Andrew Beach12 // Last Modified On : Th r Aug 17 15:44:00 201713 // Update Count : 611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Feb 22 18:11:15 2018 13 // Update Count : 8 14 14 // 15 15 … … 22 22 23 23 struct __cfaabi_ehm__base_exception_t; 24 typedef struct __cfaabi_ehm__base_exception_t exception ;24 typedef struct __cfaabi_ehm__base_exception_t exception_t; 25 25 struct __cfaabi_ehm__base_exception_t_vtable { 26 26 const struct __cfaabi_ehm__base_exception_t_vtable * parent; … … 39 39 40 40 // Used in throw statement translation. 41 void __cfaabi_ehm__throw_terminate(exception * except) __attribute__((noreturn));41 void __cfaabi_ehm__throw_terminate(exception_t * except) __attribute__((noreturn)); 42 42 void __cfaabi_ehm__rethrow_terminate() __attribute__((noreturn)); 43 void __cfaabi_ehm__throw_resume(exception * except);43 void __cfaabi_ehm__throw_resume(exception_t * except); 44 44 45 45 // Function catches termination exceptions. 46 46 void __cfaabi_ehm__try_terminate( 47 47 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)); 50 50 51 51 // Clean-up the exception in catch blocks. … … 55 55 struct __cfaabi_ehm__try_resume_node { 56 56 struct __cfaabi_ehm__try_resume_node * next; 57 _Bool (*handler)(exception * except);57 _Bool (*handler)(exception_t * except); 58 58 }; 59 59 … … 61 61 void __cfaabi_ehm__try_resume_setup( 62 62 struct __cfaabi_ehm__try_resume_node * node, 63 _Bool (*handler)(exception * except));63 _Bool (*handler)(exception_t * except)); 64 64 void __cfaabi_ehm__try_resume_cleanup( 65 65 struct __cfaabi_ehm__try_resume_node * node); -
libcfa/src/gmp.hfa
rf9feab8 r90152a4 10 10 // Created On : Tue Apr 19 08:43:43 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 4 09:54:33201713 // Update Count : 2 012 // Last Modified On : Thu Dec 7 09:10:41 2017 13 // Update Count : 21 14 14 // 15 15 … … 19 19 20 20 #include <gmp.h> // GNU multi-precise integers 21 #include <fstream > // sout21 #include <fstream.hfa> // sout 22 22 23 23 struct Int { mpz_t mpz; }; // wrap GMP implementation … … 257 257 // I/O 258 258 static inline forall( dtype istype | istream( istype ) ) 259 istype * ?|?( istype *is, Int & mp ) {259 istype & ?|?( istype & is, Int & mp ) { 260 260 gmp_scanf( "%Zd", &mp ); 261 261 return is; … … 263 263 264 264 static inline forall( dtype ostype | ostream( ostype ) ) 265 ostype * ?|?( ostype *os, Int mp ) {265 ostype & ?|?( ostype & os, Int mp ) { 266 266 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 267 267 gmp_printf( "%Zd", mp.mpz ); -
libcfa/src/iterator.cfa
rf9feab8 r90152a4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // iterator.c -- 7 // iterator.c -- 8 8 // 9 9 // Author : Richard C. Bilson … … 14 14 // 15 15 16 #include "iterator "16 #include "iterator.hfa" 17 17 18 18 forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) ) -
libcfa/src/math.hfa
rf9feab8 r90152a4 10 10 // Created On : Mon Apr 18 23:37:04 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 7 07:51:15 201713 // Update Count : 1 0812 // Last Modified On : Fri Jul 13 11:02:15 2018 13 // Update Count : 116 14 14 // 15 15 … … 348 348 static inline long double scalbln( long double x, long int exp ) { return scalblnl( x, exp ); } 349 349 350 //--------------------------------------- 351 352 #include "common.hfa" 353 354 //--------------------------------------- 355 356 forall( otype T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T );T ?*?( T, T ); } ) 357 T lerp( T x, T y, T a ) { return x * ((T){1} - a) + y * a; } 358 359 forall( otype T | { void ?{}( T &, zero_t ); void ?{}( T &, one_t ); int ?<?( T, T ); } ) 360 T step( T edge, T x ) { return x < edge ? (T){0} : (T){1}; } 361 362 forall( otype T | { void ?{}( T &, int ); T clamp( T, T, T ); T ?-?( T, T ); T ?*?( T, T ); T ?/?( T, T ); } ) 363 T 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 350 365 // Local Variables: // 351 366 // mode: c // -
libcfa/src/startup.hfa
rf9feab8 r90152a4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // startup.h --7 // startup.hfa -- 8 8 // 9 9 // Author : Thierry Delisle 10 10 // Created On : Wed Mar 29 15:56:41 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Jul 20 21:37:11 201713 // Update Count : 212 // Last Modified On : Tue Jul 24 16:16:37 2018 13 // Update Count : 4 14 14 // 15 15 … … 19 19 extern "C" { 20 20 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, 24 24 STARTUP_PRIORITY_IOSTREAM = 104, 25 STARTUP_PRIORITY_APPREADY = 105, 25 26 }; 26 27 } 27 28 #else 28 #define STARTUP_PRIORITY_ CORE10129 #define STARTUP_PRIORITY_ KERNEL10230 #define STARTUP_PRIORITY_ MEMORY10329 #define STARTUP_PRIORITY_MEMORY 101 30 #define STARTUP_PRIORITY_CORE 102 31 #define STARTUP_PRIORITY_KERNEL 103 31 32 #define STARTUP_PRIORITY_IOSTREAM 104 33 #define STARTUP_PRIORITY_APPREADY 105 32 34 #endif 33 35 -
libcfa/src/stdhdr/assert.h
rf9feab8 r90152a4 33 33 #define verify(x) assert(x) 34 34 #define verifyf(x, ...) assertf(x, __VA_ARGS__) 35 #define __CFA_WITH_VERIFY__ 35 36 #else 36 37 #define verify(x) -
libcfa/src/stdhdr/bfdlink.h
rf9feab8 r90152a4 10 10 // Created On : Tue Jul 18 07:26:04 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 18 07:46:50 201713 // Update Count : 312 // Last Modified On : Sun Jul 22 13:49:30 2018 13 // Update Count : 4 14 14 // 15 15 … … 20 20 #endif 21 21 22 #include_next <bfdlink.h> // must haveinternal check for multiple expansion22 #include_next <bfdlink.h> // has internal check for multiple expansion 23 23 24 24 #if defined( with ) && defined( __CFA_BFDLINK_H__ ) // reset only if set -
libcfa/src/stdhdr/hwloc.h
rf9feab8 r90152a4 10 10 // Created On : Tue Jul 18 07:45:00 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 18 07:56:33 201713 // Update Count : 312 // Last Modified On : Sun Jul 22 13:49:58 2018 13 // Update Count : 4 14 14 // 15 15 … … 20 20 #endif 21 21 22 #include_next <hwloc.h> // must haveinternal check for multiple expansion22 #include_next <hwloc.h> // has internal check for multiple expansion 23 23 24 24 #if defined( thread ) && defined( __CFA_HWLOC_H__ ) // reset only if set -
libcfa/src/stdhdr/krb5.h
rf9feab8 r90152a4 10 10 // Created On : Tue Jul 18 07:55:44 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 18 07:58:01 201713 // Update Count : 312 // Last Modified On : Sun Jul 22 13:50:24 2018 13 // Update Count : 4 14 14 // 15 15 … … 20 20 #endif 21 21 22 #include_next <krb5.h> // must haveinternal check for multiple expansion22 #include_next <krb5.h> // has internal check for multiple expansion 23 23 24 24 #if defined( enable ) && defined( __CFA_KRB5_H__ ) // reset only if set -
libcfa/src/stdhdr/malloc.h
rf9feab8 r90152a4 10 10 // Created On : Thu Jul 20 15:58:16 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 20 16:00:12 201713 // Update Count : 412 // Last Modified On : Sat Aug 11 09:06:31 2018 13 // Update Count : 10 14 14 // 15 16 17 size_t default_mmap_start(); // CFA extras 18 size_t default_heap_expansion(); 19 20 bool traceHeap(); 21 bool traceHeapOn(); 22 bool traceHeapOff(); 23 24 bool traceHeapTerm(); 25 bool traceHeapTermOn(); 26 bool traceHeapTermOff(); 27 28 bool checkFree(); 29 bool checkFreeOn(); 30 bool checkFreeOff(); 31 32 extern "C" { 33 size_t malloc_alignment( void * ); 34 bool malloc_zero_fill( void * ); 35 int malloc_stats_fd( int fd ); 36 void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize ); 37 } // extern "C" 15 38 16 39 extern "C" { -
libcfa/src/stdhdr/math.h
rf9feab8 r90152a4 10 10 // Created On : Mon Jul 4 23:25:26 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Jul 5 20:38:18 201613 // Update Count : 1 212 // Last Modified On : Thu Feb 22 18:16:07 2018 13 // Update Count : 13 14 14 // 15 15 16 16 extern "C" { 17 #if ! defined( exception ) // nesting ? 18 #define exception `exception` // make keyword an identifier 19 #define __CFA_MATH_H__ 20 #endif 21 17 22 #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 18 28 } // extern "C" 19 29
Note:
See TracChangeset
for help on using the changeset viewer.