Welcome to mirror list, hosted at ThFree Co, Russian Federation.

lazy_threading.cc « intern « blenlib « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4f6d3a75ecc33fcdfa51ea40716117b57de8a26e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* SPDX-License-Identifier: GPL-2.0-or-later */

#include "BLI_lazy_threading.hh"
#include "BLI_stack.hh"
#include "BLI_vector.hh"

namespace blender::lazy_threading {

/**
 * This uses a "raw" stack and vector so that it can be destructed after Blender checks for memory
 * leaks. A new list of receivers is created whenever an isolated region is entered to avoid
 * deadlocks.
 */
using HintReceivers = RawStack<RawVector<FunctionRef<void()>, 0>, 0>;
thread_local HintReceivers hint_receivers = []() {
  HintReceivers receivers;
  /* Make sure there is always at least one vector. */
  receivers.push_as();
  return receivers;
}();

void send_hint()
{
  for (const FunctionRef<void()> &fn : hint_receivers.peek()) {
    fn();
  }
}

HintReceiver::HintReceiver(const FunctionRef<void()> fn)
{
  hint_receivers.peek().append(fn);
}

HintReceiver::~HintReceiver()
{
  hint_receivers.peek().pop_last();
}

ReceiverIsolation::ReceiverIsolation()
{
  hint_receivers.push_as();
}

ReceiverIsolation::~ReceiverIsolation()
{
  BLI_assert(hint_receivers.peek().is_empty());
  hint_receivers.pop();
}

}  // namespace blender::lazy_threading