Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Waituntil.cpp

    rfc0996a rc86b08d  
    1414//
    1515
     16#include <string>
     17
    1618#include "Waituntil.hpp"
    17 
    18 #include <string>
    19 
    20 #include "AST/Copy.hpp"
    2119#include "AST/Expr.hpp"
    2220#include "AST/Pass.hpp"
     
    9593                        case 0:
    9694                            try {
    97                                     on_selected( A, clause1 );
     95                                if (on_selected( A, clause1 ))
    9896                                    doA();
    9997                            }
     
    122120        // the unregister and on_selected calls are needed to support primitives where the acquire has side effects
    123121        // so the corresponding block MUST be run for those primitives to not lose state (example is channels)
    124         if ( !has_run(clause_statuses[0]) && whenA && unregister_select(A, clause1) )
    125             on_selected( A, clause1 )
     122        if ( ! has_run(clause_statuses[0]) && whenA && unregister_select(A, clause1) && on_selected( A, clause1 ) )
    126123            doA();
    127124        ... repeat if above for B and C ...
     
    620617
    621618// Generates:
    622 /* on_selected( target_1, node_1 ); ... corresponding body of target_1 ...
     619/* if ( on_selected( target_1, node_1 )) ... corresponding body of target_1 ...
    623620*/
    624621CompoundStmt * GenerateWaitUntilCore::genStmtBlock( const WhenClause * clause, const ClauseData * data ) {
     
    626623    return new CompoundStmt( cLoc,
    627624        {
    628             new ExprStmt( cLoc,
    629                 genSelectTraitCall( clause, data, "on_selected" )
    630             ),
    631             ast::deepCopy( clause->stmt )
     625            new IfStmt( cLoc,
     626                genSelectTraitCall( clause, data, "on_selected" ),
     627                new CompoundStmt( cLoc,
     628                    {
     629                        ast::deepCopy( clause->stmt )
     630                    }
     631                )
     632            )
    632633        }
    633634    );
     
    641642            case 0:
    642643                try {
    643                     on_selected( target1, clause1 );
    644                     dotarget1stmt();
     644                    if (on_selected( target1, clause1 ))
     645                        dotarget1stmt();
    645646                }
    646647                finally { clause_statuses[i] = __SELECT_RUN; unregister_select(target1, clause1); }
     
    661662        case 0:
    662663            try {
    663                 on_selected( target1, clause1 );
    664                 dotarget1stmt();
     664                if (on_selected( target1, clause1 ))
     665                    dotarget1stmt();
    665666            }
    666667            finally { clause_statuses[i] = __SELECT_RUN; unregister_select(target1, clause1); }
     
    937938        }
    938939
     940    // C_TODO: will remove this commented code later. Currently it isn't needed but may switch to a modified version of this later if it has better performance
     941    // std::vector<ptr<CaseClause>> switchCases;
     942
     943    // int idx = 0;
     944    // for ( const auto & clause: stmt->clauses ) {
     945    //     const CodeLocation & cLoc = clause->location;
     946    //     switchCases.push_back(
     947    //         new CaseClause( cLoc,
     948    //             new CastExpr( cLoc,
     949    //                 new AddressExpr( cLoc, new NameExpr( cLoc, data.at(idx)->targetName ) ),
     950    //                 new BasicType( BasicType::Kind::LongUnsignedInt ), GeneratedFlag::ExplicitCast
     951    //             ),
     952    //             {
     953    //                 new CompoundStmt( cLoc,
     954    //                     {
     955    //                         ast::deepCopy( clause->stmt ),
     956    //                         new BranchStmt( cLoc, BranchStmt::Kind::Break, Label( cLoc ) )
     957    //                     }
     958    //                 )
     959    //             }
     960    //         )
     961    //     );
     962    //     idx++;
     963    // }
     964
    939965    return new CompoundStmt( loc,
    940966        {
    941967            new ExprStmt( loc, new UntypedExpr( loc, new NameExpr( loc, "park" ) ) ),
    942968            outerIf
     969            // new SwitchStmt( loc,
     970            //     new NameExpr( loc, statusName ),
     971            //     std::move( switchCases )
     972            // )
    943973        }
    944974    );
     
    9831013    const CodeLocation & cLoc = stmt->clauses.at(idx)->location;
    9841014
    985     Expr * baseCond = genSelectTraitCall( stmt->clauses.at(idx), data.at(idx), "register_select" );
    9861015    Expr * ifCond;
    9871016
     
    9941023            ),
    9951024            new CastExpr( cLoc,
    996                 baseCond,
     1025                genSelectTraitCall( stmt->clauses.at(idx), data.at(idx), "register_select" ),
    9971026                new BasicType( BasicType::Kind::Bool ), GeneratedFlag::ExplicitCast
    9981027            ),
    9991028            LogicalFlag::AndExpr
    10001029        );
    1001     } else ifCond = baseCond;
     1030    } else ifCond = genSelectTraitCall( stmt->clauses.at(idx), data.at(idx), "register_select" );
    10021031
    10031032    return new CompoundStmt( cLoc,
     
    10171046                ifCond,
    10181047                genStmtBlock( stmt->clauses.at(idx), data.at(idx) ),
     1048                // ast::deepCopy( stmt->clauses.at(idx)->stmt ),
    10191049                recursiveOrIfGen( stmt, data, idx + 1, elseWhenName )
    10201050            )
Note: See TracChangeset for help on using the changeset viewer.