Changeset 44940ee


Ignore:
Timestamp:
Feb 25, 2026, 12:56:30 AM (21 hours ago)
Author:
Matthew Au-Yeung <mw2auyeu@…>
Branches:
stuck-waitfor-destruct
Children:
88bb0b4
Parents:
a0548c2
Message:

Revert "Add a generated hash to fix stuck waitfor comparing static inline mutex destructors"

This reverts commit a30fceb1a73c4ef2bbee39a2b5406da881f51111.

Files:
1 deleted
10 edited

Legend:

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

    ra0548c2 r44940ee  
    2626
    2727typedef void (* fptr_t)();
    28 typedef uint64_t func_id_t;
    2928typedef int_fast16_t __lock_size_t;
    3029
  • libcfa/src/concurrency/invoke.h

    ra0548c2 r44940ee  
    159159                // last function that acquired monitors
    160160                fptr_t func;
    161 
    162                 // hash-based function identity for cross-TU matching
    163                 func_id_t func_id;
    164161        };
    165162
     
    291288                        (this.size){0};
    292289                        (this.func){NULL};
    293                         (this.func_id){0};
    294                 }
    295 
    296                 static inline void ?{}(__monitor_group_t & this, struct monitor$ ** data, __lock_size_t size, fptr_t func, func_id_t func_id) {
     290                }
     291
     292                static inline void ?{}(__monitor_group_t & this, struct monitor$ ** data, __lock_size_t size, fptr_t func) {
    297293                        (this.data){data};
    298294                        (this.size){size};
    299295                        (this.func){func};
    300                         (this.func_id){func_id};
    301296                }
    302297
     
    304299                        if( (lhs.data != 0) != (rhs.data != 0) ) return false;
    305300                        if( lhs.size != rhs.size ) return false;
    306                         // Use hash-based comparison when both sides have a valid func_id,
    307                         // otherwise fall back to function pointer comparison (for library code
    308                         // like join() that cannot compute the hash at compile time).
    309                         if( lhs.func_id != 0 && rhs.func_id != 0 ) {
    310                                 if( lhs.func_id != rhs.func_id ) return false;
    311                         } else {
    312                                 if( lhs.func != rhs.func ) return false;
    313                         }
     301                        if( lhs.func != rhs.func ) return false;
    314302
    315303                        // Check that all the monitors match
     
    326314                        lhs.size = rhs.size;
    327315                        lhs.func = rhs.func;
    328                         lhs.func_id = rhs.func_id;
    329316                }
    330317        }
  • libcfa/src/concurrency/kernel/startup.cfa

    ra0548c2 r44940ee  
    517517        doregister(curr_cluster, this);
    518518
    519         monitors{ &self_mon_p, 1, (fptr_t)0, (func_id_t)0 };
     519        monitors{ &self_mon_p, 1, (fptr_t)0 };
    520520}
    521521
  • libcfa/src/concurrency/monitor.cfa

    ra0548c2 r44940ee  
    140140}
    141141
    142 static void __dtor_enter( monitor$ * this, fptr_t func, func_id_t func_id, bool join ) {
     142static void __dtor_enter( monitor$ * this, fptr_t func, bool join ) {
    143143        thread$ * thrd = active_thread();
    144144        #if defined( __CFA_WITH_VERIFY__ )
     
    190190        __lock_size_t count = 1;
    191191        monitor$ ** monitors = &this;
    192         __monitor_group_t group = { &this, 1, func, func_id };
     192        __monitor_group_t group = { &this, 1, func };
    193193        if ( is_accepted( this, group) ) {
    194194                __cfaabi_dbg_print_safe( "Kernel : mon accepts dtor, block and signal it \n" );
     
    341341// Ctor for monitor guard
    342342// Sorts monitors before entering
    343 void ?{}( monitor_guard_t & this, monitor$ * m [], __lock_size_t count, fptr_t func, func_id_t func_id ) libcfa_public {
     343void ?{}( monitor_guard_t & this, monitor$ * m [], __lock_size_t count, fptr_t func ) libcfa_public {
    344344        thread$ * thrd = active_thread();
    345345
     
    355355
    356356        // Update thread context (needed for conditions)
    357         (thrd->monitors){m, count, func, func_id};
     357        (thrd->monitors){m, count, func};
    358358
    359359        // __cfaabi_dbg_print_safe( "MGUARD : enter %d\n", count);
    360360
    361361        // Enter the monitors in order
    362         __monitor_group_t group = {this.m, this.count, func, func_id};
     362        __monitor_group_t group = {this.m, this.count, func};
    363363        enter( group );
    364364
     
    367367
    368368void ?{}( monitor_guard_t & this, monitor$ * m [], __lock_size_t count ) libcfa_public {
    369         this{ m, count, 0p, 0 };
     369        this{ m, count, 0p };
    370370}
    371371
     
    386386// Ctor for monitor guard
    387387// Sorts monitors before entering
    388 void ?{}( monitor_dtor_guard_t & this, monitor$ * m [], fptr_t func, func_id_t func_id, bool join ) libcfa_public {
     388void ?{}( monitor_dtor_guard_t & this, monitor$ * m [], fptr_t func, bool join ) libcfa_public {
    389389        // optimization
    390390        thread$ * thrd = active_thread();
     
    400400
    401401        // Update thread context (needed for conditions)
    402         (thrd->monitors){m, 1, func, func_id};
    403 
    404         __dtor_enter( this.m, func, func_id, join );
     402        (thrd->monitors){m, 1, func};
     403
     404        __dtor_enter( this.m, func, join );
    405405}
    406406
  • libcfa/src/concurrency/monitor.hfa

    ra0548c2 r44940ee  
    4848};
    4949
    50 void ?{}( monitor_guard_t & this, monitor$ ** m, __lock_size_t count, void (*func)(), func_id_t func_id );
     50void ?{}( monitor_guard_t & this, monitor$ ** m, __lock_size_t count, void (*func)() );
    5151void ?{}( monitor_guard_t & this, monitor$ ** m, __lock_size_t count );
    5252void ^?{}( monitor_guard_t & this );
     
    5858};
    5959
    60 void ?{}( monitor_dtor_guard_t & this, monitor$ ** m, void (*func)(), func_id_t func_id, bool join );
     60void ?{}( monitor_dtor_guard_t & this, monitor$ ** m, void (*func)(), bool join );
    6161void ^?{}( monitor_dtor_guard_t & this );
    6262
  • libcfa/src/concurrency/thread.cfa

    ra0548c2 r44940ee  
    6161
    6262        doregister(curr_cluster, this);
    63         monitors{ &self_mon_p, 1, (fptr_t)0, (func_id_t)0 };
     63        monitors{ &self_mon_p, 1, (fptr_t)0 };
    6464}
    6565
     
    9393    | { EHM_DEFAULT_VTABLE(ThreadCancelled(T)); })
    9494void ?{}( thread_dtor_guard_t & this,
    95                 T & thrd, func_id_t func_id, void(*cancelHandler)(ThreadCancelled(T) &)) {
     95                T & thrd, void(*cancelHandler)(ThreadCancelled(T) &)) {
    9696        monitor$ * m = get_monitor(thrd);
    9797        thread$ * desc = get_thread(thrd);
     
    100100        void (*dtor)(T& mutex this) = ^?{};
    101101        bool join = cancelHandler != (void(*)(ThreadCancelled(T)&))0;
    102         this.func_id = func_id;
    103         (this.mg){&m, (void(*)())dtor, func_id, join};
     102        (this.mg){&m, (void(*)())dtor, join};
    104103
    105104
     
    173172        | { EHM_DEFAULT_VTABLE(ThreadCancelled(T)); })
    174173T & join( T & this ) {
    175         thread_dtor_guard_t guard = { this, (func_id_t)0, defaultResumptionHandler };
     174        thread_dtor_guard_t guard = { this, defaultResumptionHandler };
    176175        return this;
    177176}
  • libcfa/src/concurrency/thread.hfa

    ra0548c2 r44940ee  
    8383struct thread_dtor_guard_t {
    8484        monitor_dtor_guard_t mg;
    85         func_id_t func_id;
    8685};
    8786
    8887forall( T & | is_thread(T) | IS_EXCEPTION(ThreadCancelled(T))
    8988        | { EHM_DEFAULT_VTABLE(ThreadCancelled(T)); })
    90 void ?{}( thread_dtor_guard_t & this, T & thrd, func_id_t func_id, void(*)(ThreadCancelled(T) &) );
     89void ?{}( thread_dtor_guard_t & this, T & thrd, void(*)(ThreadCancelled(T) &) );
    9190void ^?{}( thread_dtor_guard_t & this );
    9291
  • src/Concurrency/Keywords.cpp

    ra0548c2 r44940ee  
    2929#include "Common/Examine.hpp"
    3030#include "Common/Utility.hpp"
    31 #include "Concurrency/MutexFuncHash.hpp"
    3231#include "Common/UniqueName.hpp"
    3332#include "ControlStruct/LabelGenerator.hpp"
     
    10781077
    10791078        // In reverse order:
    1080         // monitor_dtor_guard_t __guard = { __monitor, func, func_id, false };
     1079        // monitor_dtor_guard_t __guard = { __monitor, func, false };
    10811080        mutBody->push_front(
    10821081                new ast::DeclStmt( location, new ast::ObjectDecl(
     
    10951094                                                        generic_func,
    10961095                                                        ast::ExplicitCast ) ),
    1097                                         new ast::SingleInit( location,
    1098                                                 Concurrency::hashMangleExpr( location, func ) ),
    10991096                                        new ast::SingleInit( location,
    11001097                                                ast::ConstantExpr::from_bool( location, false ) ),
     
    11781175                                                ast::ExplicitCast
    11791176                                        ) ),
    1180                                         new ast::SingleInit( location,
    1181                                                 Concurrency::hashMangleExpr( location, func ) ),
    11821177                                },
    11831178                                {},
     
    14801475
    14811476ast::CompoundStmt * MutexKeyword::addThreadDtorStatements(
    1482                 const ast::FunctionDecl* func, const ast::CompoundStmt * body,
     1477                const ast::FunctionDecl*, const ast::CompoundStmt * body,
    14831478                const std::vector<const ast::DeclWithType * > & args ) {
    14841479        assert( args.size() == 1 );
     
    14921487        const CodeLocation & location = mutBody->location;
    14931488
    1494         // thread_dtor_guard_t __guard = { this, func_id, intptr( 0 ) };
     1489        // thread_dtor_guard_t __guard = { this, intptr( 0 ) };
    14951490        mutBody->push_front( new ast::DeclStmt(
    14961491                location,
     
    15051500                                                new ast::CastExpr( location,
    15061501                                                        new ast::VariableExpr( location, arg ), argType ) ),
    1507                                         new ast::SingleInit( location,
    1508                                                 Concurrency::hashMangleExpr( location, func ) ),
    15091502                                        new ast::SingleInit(
    15101503                                                location,
  • src/Concurrency/Waitfor.cpp

    ra0548c2 r44940ee  
    2222#include "InitTweak/InitTweak.hpp"
    2323#include "ResolvExpr/Resolver.hpp"
    24 #include "Concurrency/MutexFuncHash.hpp"
    2524
    2625#include "AST/Print.hpp"
     
    332331                makeAccStmt( location, acceptables, index, "func",
    333332                        funcExpr, context ),
    334                 makeAccStmt( location, acceptables, index, "func_id",
    335                         Concurrency::hashMangleExpr( location,
    336                                 variableExpr->var.strict_as<ast::DeclWithType>() ),
    337                         context ),
    338333                makeAccStmt( location, acceptables, index, "data",
    339334                        new ast::VariableExpr( location, monitors ), context ),
  • src/Validate/Autogen.cpp

    ra0548c2 r44940ee  
    402402        }
    403403
    404         return genProto( "^?{}", { dst }, {} );
     404        ast::FunctionDecl * decl = genProto( "^?{}", { dst }, {} );
     405        // For concurrent types, remove static storage and inline specifier, and add
     406        // cfa_linkonce attribute so the destructor has external linkage with linkonce
     407        // semantics. This is required for waitfor to work correctly across translation
     408        // units - the function pointer must be the same everywhere, and cfa_linkonce
     409        // ensures only one definition survives linking.
     410        if ( isConcurrentType() ) {
     411                auto mut = ast::mutate( decl );
     412                mut->storage = ast::Storage::Classes();
     413                mut->funcSpec = ast::Function::Specs();
     414                mut->attributes.push_back( new ast::Attribute( "cfa_linkonce" ) );
     415        }
     416        return decl;
    405417}
    406418
Note: See TracChangeset for help on using the changeset viewer.