tsan_rtl_proc.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //===-- tsan_rtl_proc.cpp -----------------------------------------------===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file is a part of ThreadSanitizer (TSan), a race detector.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "sanitizer_common/sanitizer_placement_new.h"
  13. #include "tsan_rtl.h"
  14. #include "tsan_mman.h"
  15. #include "tsan_flags.h"
  16. namespace __tsan {
  17. Processor *ProcCreate() {
  18. void *mem = InternalAlloc(sizeof(Processor));
  19. internal_memset(mem, 0, sizeof(Processor));
  20. Processor *proc = new(mem) Processor;
  21. proc->thr = nullptr;
  22. #if !SANITIZER_GO
  23. AllocatorProcStart(proc);
  24. #endif
  25. if (common_flags()->detect_deadlocks)
  26. proc->dd_pt = ctx->dd->CreatePhysicalThread();
  27. return proc;
  28. }
  29. void ProcDestroy(Processor *proc) {
  30. CHECK_EQ(proc->thr, nullptr);
  31. #if !SANITIZER_GO
  32. AllocatorProcFinish(proc);
  33. #endif
  34. ctx->metamap.OnProcIdle(proc);
  35. if (common_flags()->detect_deadlocks)
  36. ctx->dd->DestroyPhysicalThread(proc->dd_pt);
  37. proc->~Processor();
  38. InternalFree(proc);
  39. }
  40. void ProcWire(Processor *proc, ThreadState *thr) {
  41. CHECK_EQ(thr->proc1, nullptr);
  42. CHECK_EQ(proc->thr, nullptr);
  43. thr->proc1 = proc;
  44. proc->thr = thr;
  45. }
  46. void ProcUnwire(Processor *proc, ThreadState *thr) {
  47. CHECK_EQ(thr->proc1, proc);
  48. CHECK_EQ(proc->thr, thr);
  49. thr->proc1 = nullptr;
  50. proc->thr = nullptr;
  51. }
  52. } // namespace __tsan