mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2026-06-02 22:14:47 -04:00
Use spin-locks for short-lived, non-recursive locking sequences
This commit is contained in:
+2
-2
@@ -521,7 +521,7 @@ void GLFont::drawString(const std::wstring& str, int pxHeight, float xpos, float
|
||||
if (cacheable) {
|
||||
gcCounter++;
|
||||
|
||||
std::lock_guard<std::mutex> lock(cache_busy);
|
||||
std::lock_guard<SpinMutex> lock(cache_busy);
|
||||
|
||||
if (gcCounter > GC_DRAW_COUNT_PERIOD) {
|
||||
|
||||
@@ -793,7 +793,7 @@ void GLFont::doCacheGC() {
|
||||
|
||||
void GLFont::clearCache() {
|
||||
|
||||
std::lock_guard<std::mutex> lock(cache_busy);
|
||||
std::lock_guard<SpinMutex> lock(cache_busy);
|
||||
|
||||
std::map<std::wstring, GLFontStringCache * >::iterator cache_iter;
|
||||
|
||||
|
||||
+3
-4
@@ -13,6 +13,8 @@
|
||||
#include "wx/filename.h"
|
||||
#include "wx/stdpaths.h"
|
||||
|
||||
#include "SpinMutex.h"
|
||||
|
||||
class GLFontStringCache {
|
||||
public:
|
||||
GLFontStringCache();
|
||||
@@ -76,9 +78,6 @@ private:
|
||||
class GLFont {
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
enum Align {
|
||||
GLFONT_ALIGN_LEFT, GLFONT_ALIGN_RIGHT, GLFONT_ALIGN_CENTER, GLFONT_ALIGN_TOP, GLFONT_ALIGN_BOTTOM
|
||||
};
|
||||
@@ -176,7 +175,7 @@ private:
|
||||
|
||||
GLuint texId;
|
||||
int gcCounter;
|
||||
std::mutex cache_busy;
|
||||
SpinMutex cache_busy;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright (c) Charles J. Cliffe
|
||||
// SPDX-License-Identifier: GPL-2.0+
|
||||
|
||||
#pragma once
|
||||
#include <atomic>
|
||||
|
||||
// A non-recursive Mutex implemented as a spin-lock.
|
||||
class SpinMutex {
|
||||
|
||||
public:
|
||||
SpinMutex() = default;
|
||||
|
||||
SpinMutex(const SpinMutex&) = delete;
|
||||
|
||||
SpinMutex& operator=(const SpinMutex&) = delete;
|
||||
|
||||
~SpinMutex() { lock_state.clear(std::memory_order_release); }
|
||||
|
||||
void lock() { while (lock_state.test_and_set(std::memory_order_acquire)); }
|
||||
|
||||
void unlock() { lock_state.clear(std::memory_order_release); }
|
||||
|
||||
private:
|
||||
std::atomic_flag lock_state = ATOMIC_FLAG_INIT;
|
||||
};
|
||||
Reference in New Issue
Block a user