common/kernel: removed ScopedLock type in favor of C++11 lock_guard

This commit is contained in:
Lunaphied 2026-04-10 18:32:38 +02:00
parent 25482d990f
commit 18f5a4b754
8 changed files with 9 additions and 79 deletions

View File

@ -47,7 +47,6 @@ target_sources(nextpnr_kernel PUBLIC
pywrappers.h
relptr.h
report.cc
scope_lock.h
sdc.cc
sdf.cc
sso_array.h

View File

@ -1,67 +0,0 @@
/*
* nextpnr -- Next Generation Place and Route
*
* Copyright (C) 2021 Symbiflow Authors.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
#ifndef SCOPE_LOCK_H
#define SCOPE_LOCK_H
#include <stdexcept>
#include "nextpnr_namespaces.h"
NEXTPNR_NAMESPACE_BEGIN
// Provides a simple RAII locking object. ScopeLock takes a lock when
// constructed, and releases the lock on destruction or if "unlock_early" is
// called.
//
// LockingObject must have a method "void lock(void)" and "void unlock(void)".
template <typename LockingObject> class ScopeLock
{
public:
ScopeLock(LockingObject *obj) : obj_(obj), locked_(false)
{
obj_->lock();
locked_ = true;
}
ScopeLock(const ScopeLock &other) = delete;
ScopeLock(const ScopeLock &&other) = delete;
~ScopeLock()
{
if (locked_) {
obj_->unlock();
}
}
void unlock_early()
{
if (!locked_) {
throw std::runtime_error("Lock already released?");
}
locked_ = false;
obj_->unlock();
}
private:
LockingObject *obj_;
bool locked_;
};
NEXTPNR_NAMESPACE_END
#endif /* SCOPE_LOCK_H */

View File

@ -23,7 +23,6 @@
#if !defined(NPNR_DISABLE_THREADS)
#include "detail_place_core.h"
#include "scope_lock.h"
#include <chrono>
#include <mutex>
@ -450,7 +449,7 @@ struct ParallelRefine
void run()
{
ScopeLock<Context> lock(ctx);
std::lock_guard<Context> lock{*ctx};
auto refine_start = std::chrono::high_resolution_clock::now();
g.tmg.setup_only = true;

View File

@ -31,6 +31,7 @@
#include <limits>
#include <list>
#include <map>
#include <mutex>
#include <ostream>
#include <queue>
#include <set>
@ -42,7 +43,6 @@
#include "fast_bels.h"
#include "log.h"
#include "place_common.h"
#include "scope_lock.h"
#include "timing.h"
#include "util.h"
@ -138,7 +138,7 @@ class SAPlacer
{
log_break();
ScopeLock<Context> lock(ctx);
std::lock_guard<Context> lock{*ctx};
size_t placed_cells = 0;
std::vector<CellInfo *> autoplaced;

View File

@ -38,6 +38,7 @@
#include <chrono>
#include <deque>
#include <fstream>
#include <mutex>
#include <numeric>
#include <queue>
#include <tuple>
@ -48,7 +49,6 @@
#include "parallel_refine.h"
#include "place_common.h"
#include "placer1.h"
#include "scope_lock.h"
#include "timing.h"
#include "util.h"
@ -177,7 +177,7 @@ class HeAPPlacer
{
auto startt = std::chrono::high_resolution_clock::now();
ScopeLock<Context> lock(ctx);
std::lock_guard<Context> lock{*ctx};
place_constraints();
build_fast_bels();
alloc_control_sets();

View File

@ -34,7 +34,6 @@
#include "parallel_refine.h"
#include "place_common.h"
#include "placer1.h"
#include "scope_lock.h"
#include "timing.h"
#include "util.h"

View File

@ -20,10 +20,10 @@
#include <chrono>
#include <cmath>
#include <queue>
#include <mutex>
#include "log.h"
#include "router1.h"
#include "scope_lock.h"
#include "timing.h"
namespace {
@ -1163,7 +1163,7 @@ bool router1(Context *ctx, const Router1Cfg &cfg)
try {
log_break();
log_info("Routing..\n");
ScopeLock<Context> lock(ctx);
std::lock_guard<Context> lock{*ctx};
auto rstart = std::chrono::high_resolution_clock::now();
log_info("Setting up routing queue.\n");

View File

@ -34,6 +34,7 @@
#include <deque>
#include <fstream>
#include <limits>
#include <mutex>
#include <queue>
#include <set>
@ -41,7 +42,6 @@
#include "nextpnr.h"
#include "nextpnr_assertions.h"
#include "router1.h"
#include "scope_lock.h"
#include "timing.h"
#include "util.h"
@ -1680,7 +1680,7 @@ struct Router2
ThreadContext st;
int iter = 1;
ScopeLock<Context> lock(ctx);
std::lock_guard<Context> lock{*ctx};
for (size_t i = 0; i < nets_by_udata.size(); i++)
route_queue.push_back(i);