source: src/Concurrency/MutexFuncHash.hpp@ 7e8c071

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

cleanup and add tests

  • Property mode set to 100644
File size: 1.2 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 "SymTab/Mangler.hpp"
21
22namespace Concurrency {
23
24// FNV-1a hash of a function declaration's mangled name.
25// Used to identify mutex functions across translation units,
26// since function pointers may differ for static inline functions.
27static inline uint64_t hashMangle( const ast::DeclWithType * decl ) {
28 std::string name = Mangle::mangleType( decl );
29 uint64_t hash = 14695981039346656037ULL; // FNV offset basis
30 for ( char c : name ) {
31 hash ^= static_cast<uint64_t>( c );
32 hash *= 1099511628211ULL; // FNV prime
33 }
34 return hash;
35}
36
37// Create a ConstantExpr with the hash of the mangled name.
38static inline ast::ConstantExpr * hashMangleExpr(
39 const CodeLocation & location, const ast::DeclWithType * decl ) {
40 return ast::ConstantExpr::from_ulonglong( location, hashMangle( decl ) );
41}
42
43} // namespace Concurrency
Note: See TracBrowser for help on using the repository browser.