1 //===-- tsan_mutexset.h -----------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is a part of ThreadSanitizer (TSan), a race detector.
11 // MutexSet holds the set of mutexes currently held by a thread.
12 //===----------------------------------------------------------------------===//
13 #ifndef TSAN_MUTEXSET_H
14 #define TSAN_MUTEXSET_H
16 #include "tsan_defs.h"
22 // Holds limited number of mutexes.
23 // The oldest mutexes are discarded on overflow.
24 static constexpr uptr kMaxSize
= 16;
32 Desc() { internal_memset(this, 0, sizeof(*this)); }
33 Desc(const Desc
& other
) { *this = other
; }
34 Desc
& operator=(const MutexSet::Desc
& other
) {
35 internal_memcpy(this, &other
, sizeof(*this));
42 void AddAddr(uptr addr
, StackID stack_id
, bool write
);
43 void DelAddr(uptr addr
, bool destroy
= false);
45 Desc
Get(uptr i
) const;
51 Desc descs_
[kMaxSize
];
53 void RemovePos(uptr i
);
57 // MutexSet is too large to live on stack.
58 // DynamicMutexSet can be use used to create local MutexSet's.
59 class DynamicMutexSet
{
63 MutexSet
* operator->() { return ptr_
; }
64 operator MutexSet
*() { return ptr_
; }
65 DynamicMutexSet(const DynamicMutexSet
&) = delete;
66 DynamicMutexSet
& operator=(const DynamicMutexSet
&) = delete;
75 // Go does not have mutexes, so do not spend memory and time.
76 // (Go sync.Mutex is actually a semaphore -- can be unlocked
77 // in different goroutine).
79 MutexSet::MutexSet() {}
80 void MutexSet::Reset() {}
81 void MutexSet::AddAddr(uptr addr
, StackID stack_id
, bool write
) {}
82 void MutexSet::DelAddr(uptr addr
, bool destroy
) {}
83 uptr
MutexSet::Size() const { return 0; }
84 MutexSet::Desc
MutexSet::Get(uptr i
) const { return Desc(); }
85 DynamicMutexSet::DynamicMutexSet() : ptr_(&set_
) {}
86 DynamicMutexSet::~DynamicMutexSet() {}
91 #endif // TSAN_MUTEXSET_H