Example #1
0
void deferred_refdec(pvm_object_storage_t *os)
{
    assert(inited);
#if 0
    if( os->_ah.refCount > 1 )
    {
        os->_ah.refCount--;
        if( os->_ah.refCount <= 0 )
        {
            os->_ah.refCount++;
            goto long_way;
        }
        return;
    }
#endif

    STAT_INC_CNT(DEFERRED_REFDEC_REQS);

    if(
       ( (refdec_put_ptr <= REFDEC_BUFFER_HALF) && (refdec_put_ptr > REFDEC_BUFFER_RED_ZONE ) )
       ||
       ( refdec_put_ptr > REFDEC_BUFFER_RED_ZONE+REFDEC_BUFFER_HALF )
      )
    {
        //hal_mutex_lock(  &deferred_refdec_mutex );

        hal_cond_signal( &start_refdec_cond );
        //hal_cond_wait(   &end_refdec_cond, &deferred_refdec_mutex );

        //hal_mutex_unlock( &deferred_refdec_mutex );
    }


    //long_way:
    // TODO ERROR atomic_add returns not what we assume!
    //int pos = atomic_add( (int *)&refdec_put_ptr, 1 );
    int pos = ATOMIC_ADD_AND_FETCH( (int *)&refdec_put_ptr, 1 );

    // Overflow
    if( (pos >= REFDEC_BUFFER_SIZE) || (pos == REFDEC_BUFFER_HALF) )
    {
        STAT_INC_CNT(DEFERRED_REFDEC_LOST);
        // We just loose refdec - big GC will pick it up
        return;
    }

    refdec_buffer[pos] = os;


}
Example #2
0
static void dpc_timed(void)
{
#if MULTIPLE_DPC_THREADS
    if( idle_dpc_threads < MIN_DPC_IDLE_THREADS )
    {
        SHOW_FLOW( 1, "Starting extra %d DPC thread...", dpc_threads);
        hal_start_kernel_thread(dpc_thread);
    }
#endif


    //hal_cond_broadcast( &dpc_thread_sleep_stone );
    hal_cond_signal( &dpc_thread_sleep_stone ); // Wake one thread
}
Example #3
0
static void thread1(void *a)
{
    char *name = a;
    while(!thread_stop_request)
    {
        thread_activity_counter++;

        if(TEST_CHATTY) printf("--- thread %s runs ---\n", name);
        pressEnter("");

        if(TEST_CHATTY) printf("Will lock mutex\n");
        hal_mutex_lock(&m);
        if(TEST_CHATTY) printf("locked mutex\n");
        checkEnterMutex();
        YIELD();
        if(TEST_CHATTY) printf("Will unlock mutex\n");
        checkLeaveMutex();
        hal_mutex_unlock(&m);
        if(TEST_CHATTY) printf("unlocked mutex\n");

        if( random() & 1 )
            hal_sem_acquire( &s );

        counter++;
        if(counter >7)
        {
            counter = 0;
            if(TEST_CHATTY) printf("Will signal cond\n");
            hal_cond_signal(&c);
            if(TEST_CHATTY) printf("Signalled cond\n");
        }
        YIELD();

    }
    FINISH();
}