Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSpinlock.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
12
13#if 0
15 #include <execinfo.h>
16 #include <stdio.h>
17
18 static void debug_trace() {
19 void* stack[64];
20 int len = backtrace(stack, std::size(stack));
21
22 // As you might imagine, we can't use an SkSpinlock here...
23 static SkMutex lock;
24 {
25 SkAutoMutexExclusive locked(lock);
26 fprintf(stderr, "\n");
27 backtrace_symbols_fd(stack, len, 2/*stderr*/);
28 fprintf(stderr, "\n");
29 }
30 }
31#else
32 static void debug_trace() {}
33#endif
34
35// Renamed from "pause" to avoid conflict with function defined in unistd.h
36#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
37 #include <emmintrin.h>
38 static void do_pause() { _mm_pause(); }
39#else
40 static void do_pause() { /*spin*/ }
41#endif
42
43void SkSpinlock::contendedAcquire() {
45
46 // To act as a mutex, we need an acquire barrier when we acquire the lock.
48 while (fLocked.exchange(true, std::memory_order_acquire)) {
49 do_pause();
50 }
52}
static void do_pause()
static void debug_trace()
#define SK_POTENTIALLY_BLOCKING_REGION_END
#define SK_POTENTIALLY_BLOCKING_REGION_BEGIN