Source files in libcamera start by a comment block header, which
includes the file name and a one-line description of the file contents.
While the latter is useful to get a quick overview of the file contents
at a glance, the former is mostly a source of inconvenience. The name in
the comments can easily get out of sync with the file name when files
are renamed, and copy & paste during development have often lead to
incorrect names being used to start with.
Readers of the source code are expected to know which file they're
looking it. Drop the file name from the header comment block.
The change was generated with the following script:
----------------------------------------
dirs="include/libcamera src test utils"
declare -rA patterns=(
['c']=' \* '
['cpp']=' \* '
['h']=' \* '
['py']='# '
['sh']='# '
)
for ext in ${!patterns[@]} ; do
files=$(for dir in $dirs ; do find $dir -name "*.${ext}" ; done)
pattern=${patterns[${ext}]}
for file in $files ; do
name=$(basename ${file})
sed -i "s/^\(${pattern}\)${name} - /\1/" "$file"
done
done
----------------------------------------
This misses several files that are out of sync with the comment block
header. Those will be addressed separately and manually.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
135 lines
2.0 KiB
C++
135 lines
2.0 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2021, Google Inc.
|
|
*
|
|
* Mutex classes with clang thread safety annotation
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <condition_variable>
|
|
#include <mutex>
|
|
|
|
#include <libcamera/base/private.h>
|
|
|
|
#include <libcamera/base/thread_annotations.h>
|
|
|
|
namespace libcamera {
|
|
|
|
/* \todo using Mutex = std::mutex if libc++ is used. */
|
|
|
|
#ifndef __DOXYGEN__
|
|
|
|
class LIBCAMERA_TSA_CAPABILITY("mutex") Mutex final
|
|
{
|
|
public:
|
|
constexpr Mutex()
|
|
{
|
|
}
|
|
|
|
void lock() LIBCAMERA_TSA_ACQUIRE()
|
|
{
|
|
mutex_.lock();
|
|
}
|
|
|
|
void unlock() LIBCAMERA_TSA_RELEASE()
|
|
{
|
|
mutex_.unlock();
|
|
}
|
|
|
|
private:
|
|
friend class MutexLocker;
|
|
|
|
std::mutex mutex_;
|
|
};
|
|
|
|
class LIBCAMERA_TSA_SCOPED_CAPABILITY MutexLocker final
|
|
{
|
|
public:
|
|
explicit MutexLocker(Mutex &mutex) LIBCAMERA_TSA_ACQUIRE(mutex)
|
|
: lock_(mutex.mutex_)
|
|
{
|
|
}
|
|
|
|
MutexLocker(Mutex &mutex, std::defer_lock_t t) noexcept LIBCAMERA_TSA_EXCLUDES(mutex)
|
|
: lock_(mutex.mutex_, t)
|
|
{
|
|
}
|
|
|
|
~MutexLocker() LIBCAMERA_TSA_RELEASE()
|
|
{
|
|
}
|
|
|
|
void lock() LIBCAMERA_TSA_ACQUIRE()
|
|
{
|
|
lock_.lock();
|
|
}
|
|
|
|
bool try_lock() LIBCAMERA_TSA_TRY_ACQUIRE(true)
|
|
{
|
|
return lock_.try_lock();
|
|
}
|
|
|
|
void unlock() LIBCAMERA_TSA_RELEASE()
|
|
{
|
|
lock_.unlock();
|
|
}
|
|
|
|
private:
|
|
friend class ConditionVariable;
|
|
|
|
std::unique_lock<std::mutex> lock_;
|
|
};
|
|
|
|
class ConditionVariable final
|
|
{
|
|
public:
|
|
ConditionVariable()
|
|
{
|
|
}
|
|
|
|
void notify_one() noexcept
|
|
{
|
|
cv_.notify_one();
|
|
}
|
|
|
|
void notify_all() noexcept
|
|
{
|
|
cv_.notify_all();
|
|
}
|
|
|
|
template<class Predicate>
|
|
void wait(MutexLocker &locker, Predicate stopWaiting)
|
|
{
|
|
cv_.wait(locker.lock_, stopWaiting);
|
|
}
|
|
|
|
template<class Rep, class Period, class Predicate>
|
|
bool wait_for(MutexLocker &locker,
|
|
const std::chrono::duration<Rep, Period> &relTime,
|
|
Predicate stopWaiting)
|
|
{
|
|
return cv_.wait_for(locker.lock_, relTime, stopWaiting);
|
|
}
|
|
|
|
private:
|
|
std::condition_variable cv_;
|
|
};
|
|
|
|
#else /* __DOXYGEN__ */
|
|
|
|
class Mutex final
|
|
{
|
|
};
|
|
|
|
class MutexLocker final
|
|
{
|
|
};
|
|
|
|
class ConditionVariable final
|
|
{
|
|
};
|
|
|
|
#endif /* __DOXYGEN__ */
|
|
} /* namespace libcamera */
|