Changeset 428adbc


Ignore:
Timestamp:
Aug 10, 2022, 8:33:42 PM (21 months ago)
Author:
z277zhu <z277zhu@…>
Branches:
ADT, ast-experimental, master, pthread-emulation
Children:
7f6a7c9
Parents:
20be782
Message:

fix pthread_sig* interpose problems; add test doc

Signed-off-by: z277zhu <z277zhu@…>

Files:
13 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/bits/defs.hfa

    r20be782 r428adbc  
    2121#include <stdint.h>
    2222#include <assert.h>
    23 
     23#include <signal.h>
    2424
    2525#define likely(x)   __builtin_expect(!!(x), 1)
     
    5353        int real_pthread_attr_setstack( pthread_attr_t *attr, void *stackaddr, size_t stacksize );
    5454        int real_pthread_attr_getstacksize( const pthread_attr_t *attr, size_t *stacksize );
    55         //int real_pthread_sigqueue(pthread_t _thread, int sig, const union sigval value);
    56         //int real_pthread_sigmask( int /* how */, const sigset_t * /* set */, sigset_t * /* oset */ );
     55        int real_pthread_sigqueue(pthread_t _thread, int sig, const union sigval value);
     56        int real_pthread_sigmask( int how, const sigset_t *set, sigset_t *oset);
    5757}
    5858#endif
  • libcfa/src/concurrency/io.cfa

    r20be782 r428adbc  
    610610                if( we ) {
    611611                        sigval_t value = { PREEMPT_IO };
    612                         pthread_sigqueue(ctx->proc->kernel_thread, SIGUSR1, value);
     612                        real_pthread_sigqueue(ctx->proc->kernel_thread, SIGUSR1, value);
    613613                }
    614614
  • libcfa/src/concurrency/io/setup.cfa

    r20be782 r428adbc  
    337337        //      iopoll.run = false;
    338338        //      sigval val = { 1 };
    339         //      pthread_sigqueue( iopoll.thrd, SIGUSR1, val );
     339        //      real_pthread_sigqueue( iopoll.thrd, SIGUSR1, val );
    340340
    341341        //      // Make sure all this is done
  • libcfa/src/concurrency/preemption.cfa

    r20be782 r428adbc  
    368368        sigset_t oldset;
    369369        int ret;
    370         ret = pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset);  // workaround trac#208: cast should be unnecessary
     370        ret = real_pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset);  // workaround trac#208: cast should be unnecessary
    371371        if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); }
    372372
     
    401401        sigaddset( &mask, sig );
    402402
    403         if ( pthread_sigmask( SIG_UNBLOCK, &mask, 0p ) == -1 ) {
     403        if ( real_pthread_sigmask( SIG_UNBLOCK, &mask, 0p ) == -1 ) {
    404404            abort( "internal error, pthread_sigmask" );
    405405        }
     
    412412        sigaddset( &mask, sig );
    413413
    414         if ( pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {
     414        if ( real_pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {
    415415                abort( "internal error, pthread_sigmask" );
    416416        }
     
    420420static void preempt( processor * this ) {
    421421        sigval_t value = { PREEMPT_NORMAL };
    422         pthread_sigqueue( this->kernel_thread, SIGUSR1, value );
     422        real_pthread_sigqueue( this->kernel_thread, SIGUSR1, value );
    423423}
    424424
     
    431431        sigset_t oldset;
    432432        int ret;
    433         ret = pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset);  // workaround trac#208: cast should be unnecessary
     433        ret = real_pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset);  // workaround trac#208: cast should be unnecessary
    434434        if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); }
    435435
     
    450450        sigset_t oldset;
    451451        int ret;
    452         ret = pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset);  // workaround trac#208: cast should be unnecessary
     452        ret = real_pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset);  // workaround trac#208: cast should be unnecessary
    453453        if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); }
    454454
     
    608608        sigval val;
    609609        val.sival_int = 0;
    610         pthread_sigqueue( alarm_thread, SIGALRM, val );
     610        real_pthread_sigqueue( alarm_thread, SIGALRM, val );
    611611
    612612        // Wait for the preemption thread to finish
     
    682682        static_assert( sizeof( sigset_t ) == sizeof( cxt->uc_sigmask ), "Expected cxt->uc_sigmask to be of sigset_t" );
    683683        #endif
    684         if ( pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), 0p ) == -1 ) {
     684        if ( real_pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), 0p ) == -1 ) {
    685685                abort( "internal error, sigprocmask" );
    686686        }
     
    710710        sigset_t mask;
    711711        sigfillset(&mask);
    712         if ( pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {
     712        if ( real_pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {
    713713            abort( "internal error, pthread_sigmask" );
    714714        }
  • libcfa/src/concurrency/pthread.cfa

    r20be782 r428adbc  
    666666
    667667
    668     // int pthread_sigmask( int /* how */, const sigset_t * /* set */, sigset_t * /* oset */ ) libcfa_public __THROW {
    669         //     return 0;
    670     // } // pthread_sigmask
     668    int pthread_sigmask( int /* how */, const sigset_t * /* set */, sigset_t * /* oset */ ) libcfa_public __THROW {
     669             return 0;
     670    } // pthread_sigmask
    671671
    672672    int pthread_kill( pthread_t _thread __attribute__(( unused )), int sig ) libcfa_public __THROW {
     
    679679    } // pthread_kill
    680680
    681     // int pthread_sigqueue(pthread_t , int sig, const union sigval) libcfa_public __THROW {
    682     //     return 0;
    683     // } // pthread_sigqueue
     681    int pthread_sigqueue(pthread_t , int sig, const union sigval) libcfa_public __THROW {
     682        return 0;
     683    } // pthread_sigqueue
    684684
    685685    //######################### Scheduling #########################
  • libcfa/src/interpose.cfa

    r20be782 r428adbc  
    118118        typeof(pthread_attr_destroy) pthread_attr_destroy;
    119119        typeof(pthread_attr_getstacksize) pthread_attr_getstacksize;
    120         //typeof(pthread_sigmask) pthread_sigmask;
    121         //typeof(pthread_sigqueue) pthread_sigqueue;
     120        typeof(pthread_sigmask) pthread_sigmask;
     121        typeof(pthread_sigqueue) pthread_sigqueue;
    122122} __cabi_libc;
    123123
     
    142142                INTERPOSE_LIBC( pthread_attr_setstack , version );
    143143                INTERPOSE_LIBC( pthread_attr_getstacksize , version );
    144                 //INTERPOSE_LIBC( pthread_sigmask , version );
    145                 //INTERPOSE_LIBC( pthread_sigqueue , version );
     144                INTERPOSE_LIBC( pthread_sigmask , version );
     145                INTERPOSE_LIBC( pthread_sigqueue , version );
    146146#pragma GCC diagnostic pop
    147147
     
    229229                return __cabi_libc.pthread_attr_getstacksize(attr, stacksize);
    230230        }
    231         // libcfa_public int real_pthread_sigmask(int how, const sigset_t *set, sigset_t *oldset){
    232         //      return __cabi_libc.pthread_sigmask(how, set, oldset);
    233         // }
    234         // libcfa_public int real_pthread_sigqueue(pthread_t _thread, int sig, const union sigval value){
    235         //      return __cabi_libc.real_pthread_sigqueue(_thread, sig, value);
    236         // }
     231        libcfa_public int real_pthread_sigmask(int how, const sigset_t *set, sigset_t *oldset){
     232                return __cabi_libc.pthread_sigmask(how, set, oldset);
     233        }
     234        libcfa_public int real_pthread_sigqueue(pthread_t _thread, int sig, const union sigval value){
     235                return __cabi_libc.pthread_sigqueue(_thread, sig, value);
     236        }
    237237}
    238238
  • tests/concurrent/pthread/.expect/pthread_attr_test.txt

    r20be782 r428adbc  
    1 Hi
     1stack size is 123456789
  • tests/concurrent/pthread/bounded_buffer.cfa

    r20be782 r428adbc  
    44#include <pthread.h>
    55#include <errno.h>
     6// tested pthread mutex related routines, pthread cond related routines
     7// tested pthread_create/join
     8
    69enum { BufferSize = 50 };
    710
  • tests/concurrent/pthread/pthread_attr_test.cfa

    r20be782 r428adbc  
    44#include <thread.hfa>
    55
    6 void* foo(void* arg){
    7     sout | "Hi";
     6void* foo(void* _attr){
     7    size_t size;
     8    pthread_attr_t* attr = (pthread_attr_t*)_attr;
     9    int status = pthread_attr_getstacksize(attr, &size);
     10    if (status != 0){
     11        sout | "error return code";
     12        exit(1);
     13    }
     14    sout | "stack size is " | size;
    815    return NULL;
    916}
     
    1623    pthread_t thr;
    1724    void* res;
    18     pthread_create(&thr, &attr, foo, NULL);
     25    pthread_create(&thr, &attr, foo, (void*)&attr);
    1926    pthread_join(thr, &res);
    20     //pthread_attr_destroy(&attr);
     27    pthread_attr_destroy(&attr);
    2128    return 0;
    2229}
  • tests/concurrent/pthread/pthread_cond_test.cfa

    r20be782 r428adbc  
    1 /* test cond provide sync */
     1/* small test of pthread cond */
    22
    33#include <fstream.hfa>
  • tests/concurrent/pthread/pthread_demo_create_join.cfa

    r20be782 r428adbc  
    11#include <fstream.hfa>
    22#include <thread.hfa>
    3 /* test that threads can create successfully and join correct result */
     3/* test pthread create/join/exit */
     4
    45int arr[20];
    56
  • tests/concurrent/pthread/pthread_key_test.cfa

    r20be782 r428adbc  
    11
    2 /* This test is to test that multiple threads can create one key and set their own specifics
     2/* test pthread_key_create/set_specific/get_specific
    33    get specific == set specific
    44    dtor is invoked (no mem leak)
  • tests/concurrent/pthread/pthread_once_test.cfa

    r20be782 r428adbc  
    1 #ifndef _OPEN_THREADS                                                           
    2 #define _OPEN_THREADS                                                           
    3 #endif                                                                         
     1// tested pthread once,create,join
     2
    43                                                         
    54                                                                               
Note: See TracChangeset for help on using the changeset viewer.