Changeset b1e68d03 for src/libcfa


Ignore:
Timestamp:
Nov 2, 2017, 11:45:03 AM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
4f748c5
Parents:
85d340d (diff), 0dc954b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

Location:
src/libcfa
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/kernel.c

    r85d340d rb1e68d03  
    548548
    549549        int len = snprintf( abort_text, abort_text_size, "Error occurred while executing task %.256s (%p)", thrd->self_cor.name, thrd );
    550         __lib_debug_write( STDERR_FILENO, abort_text, len );
     550        __lib_debug_write( abort_text, len );
    551551
    552552        if ( thrd != this_coroutine ) {
    553553                len = snprintf( abort_text, abort_text_size, " in coroutine %.256s (%p).\n", this_coroutine->name, this_coroutine );
    554                 __lib_debug_write( STDERR_FILENO, abort_text, len );
     554                __lib_debug_write( abort_text, len );
    555555        }
    556556        else {
    557                 __lib_debug_write( STDERR_FILENO, ".\n", 2 );
     557                __lib_debug_write( ".\n", 2 );
    558558        }
    559559}
  • src/libcfa/concurrency/monitor.c

    r85d340d rb1e68d03  
    2121#include "kernel_private.h"
    2222
     23#include "bits/algorithms.h"
     24
    2325//-----------------------------------------------------------------------------
    2426// Forward declarations
     
    9597                else if( this->owner == thrd) {
    9698                        // We already have the monitor, just note how many times we took it
    97                         verify( this->recursion > 0 );
    9899                        this->recursion += 1;
    99100
     
    207208                // it means we don't need to do anything
    208209                if( this->recursion != 0) {
     210                        LIB_DEBUG_PRINT_SAFE("Kernel :  recursion still %d\n", this->recursion);
    209211                        unlock( &this->lock );
    210212                        return;
     
    291293
    292294        // Sort monitors based on address -> TODO use a sort specialized for small numbers
    293         qsort(this.m, count);
     295        __libcfa_small_sort(this.m, count);
    294296
    295297        // Save previous thread context
     
    492494        set_owner( monitors, count, signallee );
    493495
     496        LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : signal_block condition %p (s: %p)\n", this, signallee );
     497
    494498        //Everything is ready to go to sleep
    495499        BlockInternal( locks, count, &signallee, 1 );
     
    498502        // WE WOKE UP
    499503
     504
     505        LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel :   signal_block returned\n" );
    500506
    501507        //We are back, restore the masks and recursions
     
    536542        short actual_count = aggregate( mon_storage, mask );
    537543
    538         LIB_DEBUG_PRINT_SAFE("Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (short)max);
     544        LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (short)max);
    539545
    540546        if(actual_count == 0) return;
    541547
    542         LIB_DEBUG_PRINT_SAFE("Kernel : waitfor internal proceeding\n");
     548        LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : waitfor internal proceeding\n");
    543549
    544550        // Create storage for monitor context
     
    556562                        *mask.accepted = index;
    557563                        if( mask.clauses[index].is_dtor ) {
    558                                 LIB_DEBUG_PRINT_SAFE("Kernel : dtor already there\n");
     564                                LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : dtor already there\n");
    559565                                verifyf( mask.clauses[index].size == 1        , "ERROR: Accepted dtor has more than 1 mutex parameter." );
    560566
     
    568574                        }
    569575                        else {
    570                                 LIB_DEBUG_PRINT_SAFE("Kernel : thread present, baton-passing\n");
     576                                LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : thread present, baton-passing\n");
    571577
    572578                                // Create the node specific to this wait operation
     
    576582                                monitor_save;
    577583
     584                                LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel :  baton of %d monitors : ", count );
     585                                #ifdef __CFA_DEBUG_PRINT__
     586                                        for( int i = 0; i < count; i++) {
     587                                                LIB_DEBUG_PRINT_BUFFER_LOCAL( "%p %p ", monitors[i], monitors[i]->signal_stack.top );
     588                                        }
     589                                #endif
     590                                LIB_DEBUG_PRINT_BUFFER_LOCAL( "\n");
     591
    578592                                // Set the owners to be the next thread
    579593                                set_owner( monitors, count, next );
     
    585599                                monitor_restore;
    586600
    587                                 LIB_DEBUG_PRINT_SAFE("Kernel : thread present, returned\n");
     601                                LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : thread present, returned\n");
    588602                        }
    589603
    590                         LIB_DEBUG_PRINT_SAFE("Kernel : accepted %d\n", *mask.accepted);
     604                        LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);
    591605
    592606                        return;
     
    596610
    597611        if( duration == 0 ) {
    598                 LIB_DEBUG_PRINT_SAFE("Kernel : non-blocking, exiting\n");
     612                LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : non-blocking, exiting\n");
    599613
    600614                unlock_all( locks, count );
    601615
    602                 LIB_DEBUG_PRINT_SAFE("Kernel : accepted %d\n", *mask.accepted);
     616                LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);
    603617                return;
    604618        }
     
    607621        verifyf( duration < 0, "Timeout on waitfor statments not supported yet.");
    608622
    609         LIB_DEBUG_PRINT_SAFE("Kernel : blocking waitfor\n");
     623        LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : blocking waitfor\n");
    610624
    611625        // Create the node specific to this wait operation
     
    629643        monitor_restore;
    630644
    631         LIB_DEBUG_PRINT_SAFE("Kernel : exiting\n");
    632 
    633         LIB_DEBUG_PRINT_SAFE("Kernel : accepted %d\n", *mask.accepted);
     645        LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : exiting\n");
     646
     647        LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);
    634648}
    635649
     
    648662
    649663static inline void set_owner( monitor_desc ** monitors, short count, thread_desc * owner ) {
    650         for( int i = 0; i < count; i++ ) {
    651                 set_owner( monitors[i], owner );
     664        monitors[0]->owner     = owner;
     665        monitors[0]->recursion = 1;
     666        for( int i = 1; i < count; i++ ) {
     667                monitors[i]->owner     = owner;
     668                monitors[i]->recursion = 0;
    652669        }
    653670}
     
    667684static inline thread_desc * next_thread( monitor_desc * this ) {
    668685        //Check the signaller stack
     686        LIB_DEBUG_PRINT_SAFE("Kernel :  mon %p AS-stack top %p\n", this, this->signal_stack.top);
    669687        __condition_criterion_t * urgent = pop( &this->signal_stack );
    670688        if( urgent ) {
     
    718736        for(int i = 0; i < count; i++) {
    719737                (criteria[i]){ monitors[i], waiter };
     738                LIB_DEBUG_PRINT_SAFE( "Kernel :  target %p = %p\n", criteria[i].target, &criteria[i] );
    720739                push( &criteria[i].target->signal_stack, &criteria[i] );
    721740        }
     
    788807        }
    789808
    790         // LIB_DEBUG_PRINT_SAFE( "Runing %i\n", ready2run );
     809        LIB_DEBUG_PRINT_SAFE( "Kernel :  Runing %i (%p)\n", ready2run, ready2run ? node->waiting_thread : NULL );
    791810        return ready2run ? node->waiting_thread : NULL;
    792811}
     
    856875        short size = 0;
    857876        for( int i = 0; i < mask.size; i++ ) {
     877                __libcfa_small_sort( mask.clauses[i].list, mask.clauses[i].size );
    858878                for( int j = 0; j < mask.clauses[i].size; j++) {
    859879                        insert_unique( storage, size, mask.clauses[i].list[j] );
    860880                }
    861881        }
    862         qsort( storage, size );
     882        // TODO insertion sort instead of this
     883        __libcfa_small_sort( storage, size );
    863884        return size;
    864885}
  • src/libcfa/concurrency/preemption.c

    r85d340d rb1e68d03  
    380380
    381381        if ( sigaction( sig, &act, NULL ) == -1 ) {
    382                 LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO,
     382                LIB_DEBUG_PRINT_BUFFER_DECL(
    383383                        " __kernel_sigaction( sig:%d, handler:%p, flags:%d ), problem installing signal handler, error(%d) %s.\n",
    384384                        sig, handler, flags, errno, strerror( errno )
     
    397397
    398398        if ( sigaction( sig, &act, NULL ) == -1 ) {
    399                 LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO,
     399                LIB_DEBUG_PRINT_BUFFER_DECL(
    400400                        " __kernel_sigdefault( sig:%d ), problem reseting signal handler, error(%d) %s.\n",
    401401                        sig, errno, strerror( errno )
  • src/libcfa/interpose.c

    r85d340d rb1e68d03  
    127127                        va_end( args );
    128128
    129                         __lib_debug_write( STDERR_FILENO, abort_text, len );
    130                         __lib_debug_write( STDERR_FILENO, "\n", 1 );
     129                        __lib_debug_write( abort_text, len );
     130                        __lib_debug_write( "\n", 1 );
    131131                }
    132132
    133133                len = snprintf( abort_text, abort_text_size, "Cforall Runtime error (UNIX pid:%ld)\n", (long int)getpid() ); // use UNIX pid (versus getPid)
    134                 __lib_debug_write( STDERR_FILENO, abort_text, len );
     134                __lib_debug_write( abort_text, len );
    135135
    136136
  • src/libcfa/libhdr/libdebug.c

    r85d340d rb1e68d03  
    99// Author           : Thierry Delisle
    1010// Created On       : Thu Mar 30 12:30:01 2017
    11 // Last Modified By : 
    12 // Last Modified On : 
     11// Last Modified By :
     12// Last Modified On :
    1313// Update Count     : 0
    1414//
     
    2828extern "C" {
    2929
    30         void __lib_debug_write( int fd, const char *in_buffer, int len ) {
     30        void __lib_debug_write( const char *in_buffer, int len ) {
    3131                // ensure all data is written
    32                 for ( int count = 0, retcode; count < len; count += retcode ) { 
     32                for ( int count = 0, retcode; count < len; count += retcode ) {
    3333                        in_buffer += count;
    3434
    3535                        for ( ;; ) {
    36                                 retcode = write( fd, in_buffer, len - count );
     36                                retcode = write( STDERR_FILENO, in_buffer, len - count );
    3737
    3838                                // not a timer interrupt ?
    39                                 if ( retcode != -1 || errno != EINTR ) break; 
     39                                if ( retcode != -1 || errno != EINTR ) break;
    4040                        }
    4141
     
    5252                va_start( args, fmt );
    5353                __lib_debug_acquire();
    54                
     54
    5555                int len = vsnprintf( buffer, buffer_size, fmt, args );
    56                 __lib_debug_write( STDERR_FILENO, buffer, len );
     56                __lib_debug_write( buffer, len );
    5757
    5858                __lib_debug_release();
     
    6464
    6565                va_start( args, fmt );
    66                
     66
    6767                int len = vsnprintf( buffer, buffer_size, fmt, args );
    68                 __lib_debug_write( STDERR_FILENO, buffer, len );
     68                __lib_debug_write( buffer, len );
    6969
    7070                va_end( args );
     
    7373        void __lib_debug_print_vararg( const char fmt[], va_list args ) {
    7474                int len = vsnprintf( buffer, buffer_size, fmt, args );
    75                 __lib_debug_write( STDERR_FILENO, buffer, len );
     75                __lib_debug_write( buffer, len );
    7676        }
    7777
     
    8080
    8181                va_start( args, fmt );
    82                
     82
    8383                int len = vsnprintf( in_buffer, in_buffer_size, fmt, args );
    84                 __lib_debug_write( STDERR_FILENO, in_buffer, len );
     84                __lib_debug_write( in_buffer, len );
    8585
    8686                va_end( args );
  • src/libcfa/libhdr/libdebug.h

    r85d340d rb1e68d03  
    4444extern "C" {
    4545#endif
    46       #include <stdarg.h>
     46        #include <stdarg.h>
     47        #include <stdio.h>
    4748
    48       extern void __lib_debug_write( int fd, const char *buffer, int len );
     49      extern void __lib_debug_write( const char *buffer, int len );
    4950      extern void __lib_debug_acquire();
    5051      extern void __lib_debug_release();
     
    5859
    5960#ifdef __CFA_DEBUG_PRINT__
    60         #define LIB_DEBUG_WRITE( fd, buffer, len )     __lib_debug_write( fd, buffer, len )
     61        #define LIB_DEBUG_WRITE( buffer, len )         __lib_debug_write( buffer, len )
    6162        #define LIB_DEBUG_ACQUIRE()                    __lib_debug_acquire()
    6263        #define LIB_DEBUG_RELEASE()                    __lib_debug_release()
     
    6465        #define LIB_DEBUG_PRINT_NOLOCK(...)            __lib_debug_print_nolock (__VA_ARGS__)
    6566        #define LIB_DEBUG_PRINT_BUFFER(...)            __lib_debug_print_buffer (__VA_ARGS__)
    66         #define LIB_DEBUG_PRINT_BUFFER_DECL(fd, ...)   char text[256]; int len = snprintf( text, 256, __VA_ARGS__ ); __lib_debug_write( fd, text, len );
    67         #define LIB_DEBUG_PRINT_BUFFER_LOCAL(fd, ...)  len = snprintf( text, 256, __VA_ARGS__ ); __lib_debug_write( fd, text, len );
     67        #define LIB_DEBUG_PRINT_BUFFER_DECL(...)       char __dbg_text[256]; int __dbg_len = snprintf( __dbg_text, 256, __VA_ARGS__ ); __lib_debug_write( __dbg_text, __dbg_len );
     68        #define LIB_DEBUG_PRINT_BUFFER_LOCAL(...)      __dbg_len = snprintf( __dbg_text, 256, __VA_ARGS__ ); __lib_debug_write( __dbg_text, __dbg_len );
    6869#else
    6970        #define LIB_DEBUG_WRITE(...)               ((void)0)
  • src/libcfa/stdlib

    r85d340d rb1e68d03  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 23 20:29:47 2017
    13 // Update Count     : 224
     12// Last Modified On : Tue Oct 31 13:47:24 2017
     13// Update Count     : 245
    1414//
    1515
     
    2727// allocation, non-array types
    2828static inline forall( dtype T | sized(T) ) T * malloc( void ) {
    29         //printf( "X1\n" );
     29        // printf( "* malloc\n" );
    3030        return (T *)(void *)malloc( (size_t)sizeof(T) );        // C malloc
    3131} // malloc
     32
     33// static inline forall( dtype T | sized(T) ) T & malloc( void ) {
     34//      int & p = *(T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc
     35//      printf( "& malloc %p\n", &p );
     36//      return p;
     37// //   return (T &)*(T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc
     38// } // malloc
    3239
    3340extern "C" { void * calloc( size_t dim, size_t size ); } // default C routine
     
    206213//---------------------------------------
    207214
    208 void rand48seed( long int s );
    209 char rand48( void );
    210 int rand48( void );
    211 unsigned int rand48( void );
    212 long int rand48( void );
    213 unsigned long int rand48( void );
    214 float rand48( void );
    215 double rand48( void );
    216 float _Complex rand48( void );
    217 double _Complex rand48( void );
    218 long double _Complex rand48( void );
     215void random_seed( long int s );
     216char random( void );
     217char random( char l, char u );
     218int random( void );
     219unsigned int random( void );
     220unsigned int random( unsigned int u );
     221unsigned int random( unsigned int l, unsigned int u );
     222//long int random( void );
     223unsigned long int random( void );
     224unsigned long int random( unsigned long int u );
     225unsigned long int random( unsigned long int l, unsigned long int u );
     226float random( void );
     227double random( void );
     228float _Complex random( void );
     229double _Complex random( void );
     230long double _Complex random( void );
    219231
    220232//---------------------------------------
  • src/libcfa/stdlib.c

    r85d340d rb1e68d03  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 23 20:30:44 2017
    13 // Update Count     : 292
     12// Last Modified On : Mon Oct 30 22:43:02 2017
     13// Update Count     : 297
    1414//
    1515
     
    275275//---------------------------------------
    276276
    277 void rand48seed( long int s ) { srand48( s ); }
    278 char rand48( void ) { return mrand48(); }
    279 int rand48( void ) { return mrand48(); }
    280 unsigned int rand48( void ) { return lrand48(); }
    281 long int rand48( void ) { return mrand48(); }
    282 unsigned long int rand48( void ) { return lrand48(); }
    283 float rand48( void ) { return (float)drand48(); }               // otherwise float uses lrand48
    284 double rand48( void ) { return drand48(); }
    285 float _Complex rand48( void ) { return (float)drand48() + (float _Complex)(drand48() * _Complex_I); }
    286 double _Complex rand48( void ) { return drand48() + (double _Complex)(drand48() * _Complex_I); }
    287 long double _Complex rand48( void) { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); }
     277void random_seed( long int s ) { srand48( s ); }
     278char random( void ) { return mrand48(); }
     279char random( char l, char u ) { return lrand48() % (u - l) + l; }
     280int random( void ) { return mrand48(); }
     281unsigned int random( void ) { return lrand48(); }
     282unsigned int random( unsigned int u ) { return lrand48() % u; }
     283unsigned int random( unsigned int l, unsigned int u ) { return lrand48() % (u - l) + l; }
     284//long int random( void ) { return mrand48(); }
     285unsigned long int random( void ) { return lrand48(); }
     286unsigned long int random( unsigned long int u ) { return lrand48() % u; }
     287unsigned long int random( unsigned long int l, unsigned long int u ) { return lrand48() % (u - l) + l; }
     288float random( void ) { return (float)drand48(); }               // otherwise float uses lrand48
     289double random( void ) { return drand48(); }
     290float _Complex random( void ) { return (float)drand48() + (float _Complex)(drand48() * _Complex_I); }
     291double _Complex random( void ) { return drand48() + (double _Complex)(drand48() * _Complex_I); }
     292long double _Complex random( void) { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); }
    288293
    289294//---------------------------------------
Note: See TracChangeset for help on using the changeset viewer.