<commit_before>

#include <boost/test/unit_test.hpp>

#include "SoftXMT.hpp"
#include "Cache.hpp"
#include "ForkJoin.hpp"

//RESUME!
//all variations and declare and wrap

BOOST_AUTO_TEST_SUITE( CacheWrapped_tests );


struct task_arg {
    int num;
    GlobalAddress<Semaphore> sem;
};

void pointer_task_f( task_arg * arg ) {
    CHECK( arg->num == 1 ) << "num=" << arg->num;
    arg->num++;
    Semaphore::release( &(arg->sem), 1 );
}
DECLARE_CACHE_WRAPPED(pointer_task_f_CW, &pointer_task_f, task_arg)

void ref_task_f( task_arg& arg ) {
    CHECK( arg.num == 1 ) << "num=" << arg.num;
    arg.num++;
    Semaphore::release( &(arg.sem), 1);
}
DECLARE_CACHE_WRAPPED(ref_task_f_CW, &ref_task_f, task_arg)

void c_pointer_task_f( const task_arg * arg ) {
    CHECK( arg->num == 1 ) << "num=" << arg->num ;
    GlobalAddress<Semaphore> * sa = (GlobalAddress<Semaphore>*) &arg->sem;
    Semaphore::release( sa, 1 );  // don't care about const of address
}
DECLARE_CACHE_WRAPPED(c_pointer_task_f_CW, &c_pointer_task_f, task_arg)

void c_ref_task_f( const task_arg& arg ) {
    CHECK( arg.num == 1 ) << "num=" << arg.num ;
    GlobalAddress<Semaphore> * sa = (GlobalAddress<Semaphore>*) &arg.sem;
    Semaphore::release( sa, 1 ); // don't care about const of address
}
DECLARE_CACHE_WRAPPED(c_ref_task_f_CW, &c_ref_task_f, task_arg)


struct user_main_args {
};

void user_main( user_main_args * args ) 
{
    BOOST_MESSAGE( "pointer RW, declared" );
    {
        for ( Node i=0; i<2; i++ ) {
            Semaphore sem( 1, 0 );
            task_arg args = { 1, make_global( &sem ) };
            SoftXMT_remote_privateTask( &pointer_task_f_CW, make_global( &args ), i );
            sem.acquire_all( CURRENT_THREAD );
            // User sync will not guarentee this
//            CHECK( args.num == 2 ) << "num=" << args.num << " i=" << i; 
        }
    }
    
//    BOOST_MESSAGE( "pointer RW, callsite" );
//    {
//        for ( Node i=0; i<2; i++ ) {
//            phore sem( 1, 0 );
//            task_arg args = { 1, make_global( &sem ) };
//            SoftXMT_remote_privateTask( CACHE_WRAP( &pointer_task_f, &args ), i );
//            sem.acquire_all( CURRENT_THREAD );
//            BOOST_CHECK( args.num == 2 );
//        }
//    }
    
    BOOST_MESSAGE( "ref RW, declared" );
    {
        for ( Node i=0; i<2; i++ ) {
            Semaphore sem( 1, 0 );
            task_arg args = { 1, make_global( &sem ) };
            SoftXMT_remote_privateTask( &ref_task_f_CW, make_global( &args ), i );
            sem.acquire_all( CURRENT_THREAD );
            // User sync will not guarentee this
//            CHECK( args.num == 2 ) << "num=" << args.num << " i=" << i; 
        }
    }
    
//    BOOST_MESSAGE( "ref RW, callsite" );<commit_msg>fix commenting on user synchronization documentation in CacheWrapped tests<commit_after>

#include <boost/test/unit_test.hpp>

#include "SoftXMT.hpp"
#include "Cache.hpp"
#include "ForkJoin.hpp"

//RESUME!
//all variations and declare and wrap

BOOST_AUTO_TEST_SUITE( CacheWrapped_tests );


struct task_arg {
    int num;
    GlobalAddress<Semaphore> sem;
};

void pointer_task_f( task_arg * arg ) {
    CHECK( arg->num == 1 ) << "num=" << arg->num;
    arg->num++;
    Semaphore::release( &(arg->sem), 1 );
}
DECLARE_CACHE_WRAPPED(pointer_task_f_CW, &pointer_task_f, task_arg)

void ref_task_f( task_arg& arg ) {
    CHECK( arg.num == 1 ) << "num=" << arg.num;
    arg.num++;
    Semaphore::release( &(arg.sem), 1);
}
DECLARE_CACHE_WRAPPED(ref_task_f_CW, &ref_task_f, task_arg)

void c_pointer_task_f( const task_arg * arg ) {
    CHECK( arg->num == 1 ) << "num=" << arg->num ;
    GlobalAddress<Semaphore> * sa = (GlobalAddress<Semaphore>*) &arg->sem;
    Semaphore::release( sa, 1 );  // don't care about const of address
}
DECLARE_CACHE_WRAPPED(c_pointer_task_f_CW, &c_pointer_task_f, task_arg)

void c_ref_task_f( const task_arg& arg ) {
    CHECK( arg.num == 1 ) << "num=" << arg.num ;
    GlobalAddress<Semaphore> * sa = (GlobalAddress<Semaphore>*) &arg.sem;
    Semaphore::release( sa, 1 ); // don't care about const of address
}
DECLARE_CACHE_WRAPPED(c_ref_task_f_CW, &c_ref_task_f, task_arg)


struct user_main_args {
};

void user_main( user_main_args * args ) 
{
    BOOST_MESSAGE( "pointer RW, declared" );
    {
        for ( Node i=0; i<2; i++ ) {
            Semaphore sem( 1, 0 );
            task_arg args = { 1, make_global( &sem ) };
            SoftXMT_remote_privateTask( &pointer_task_f_CW, make_global( &args ), i );
            sem.acquire_all( CURRENT_THREAD );
            // User sync will not guarentee this
            //CHECK( args.num == 2 ) << "num=" << args.num << " i=" << i; 
        }
    }
    
//    BOOST_MESSAGE( "pointer RW, callsite" );
//    {
//        for ( Node i=0; i<2; i++ ) {
//            phore sem( 1, 0 );
//            task_arg args = { 1, make_global( &sem ) };
//            SoftXMT_remote_privateTask( CACHE_WRAP( &pointer_task_f, &args ), i );
//            sem.acquire_all( CURRENT_THREAD );
//            BOOST_CHECK( args.num == 2 );
//        }
//    }
    
    BOOST_MESSAGE( "ref RW, declared" );
    {
        for ( Node i=0; i<2; i++ ) {
            Semaphore sem( 1, 0 );
            task_arg args = { 1, make_global( &sem ) };
            SoftXMT_remote_privateTask( &ref_task_f_CW, make_global( &args ), i );
            sem.acquire_all( CURRENT_THREAD );
            // User sync will not guarentee this
            //CHECK( args.num == 2 ) << "num=" << args.num << " i=" << i; 
        }
    }
    
//    BOOST_MESSAGE( "ref RW, callsite" );
{'fraction_non_alphanumeric': 0.1541225076342734, 'fraction_numerical': 0.009340758038440812, 'mean_word_length': 2.548757170172084, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5976264', 'n_tokens_mistral': 2113, 'n_tokens_neox': 2018, 'n_words': 452}