source: src/Concurrency/MutexFuncHash.hpp@ c9d36b1

stuck-waitfor-destruct
Last change on this file since c9d36b1 was c9d36b1, checked in by Matthew Au-Yeung <mw2auyeu@…>, 3 days ago

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

  • Property mode set to 100644
File size: 1.5 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// MutexFuncHash.hpp -- Hash utility for mutex function identity.
8//
9// Author : Matthew Au-Yeung
10// Created On : Tue Jan 28 2026
11//
12
13#pragma once
14
15#include <cstdint>
16#include <string>
17
18#include "AST/Decl.hpp"
19#include "AST/Expr.hpp"
20#include "AST/Type.hpp"
21#include "SymTab/Mangler.hpp"
22
23namespace Concurrency {
24
25// FNV-1a hash of a function declaration's mangled name.
26// Used to identify mutex functions across translation units,
27// since function pointers may differ for static inline functions.
28static inline uint64_t hashMangle( const ast::DeclWithType * decl ) {
29 std::string name = Mangle::mangle( decl );
30 uint64_t hash = 14695981039346656037ULL; // FNV offset basis
31 for ( char c : name ) {
32 hash ^= static_cast<uint64_t>( c );
33 hash *= 1099511628211ULL; // FNV prime
34 }
35 return hash;
36}
37
38// Create a ConstantExpr for the hash with proper ULL suffix to avoid
39// C compiler warnings about large unsigned constants.
40static inline ast::ConstantExpr * hashMangleExpr(
41 const CodeLocation & location, const ast::DeclWithType * decl ) {
42 uint64_t hash = hashMangle( decl );
43 return new ast::ConstantExpr{
44 location,
45 new ast::BasicType{ ast::BasicKind::LongLongUnsignedInt },
46 std::to_string( hash ) + "ull",
47 (unsigned long long)hash };
48}
49
50} // namespace Concurrency
Note: See TracBrowser for help on using the repository browser.