first commit

This commit is contained in:
陈赣
2026-06-03 12:43:14 +08:00
commit ba76cfae28
608 changed files with 120791 additions and 0 deletions

39
utils/vp_semaphore.h Executable file
View File

@@ -0,0 +1,39 @@
#pragma once
#include <condition_variable>
#include <mutex>
namespace vp_utils {
// semaphore for queue/deque data structures in VideoPipe, used for producer-consumer pattern.
// it blocks the consumer thread until data has come.
class vp_semaphore
{
public:
vp_semaphore() {
count_ = 0;
}
void signal() {
std::unique_lock<std::mutex> lock(mutex_);
++count_;
cv_.notify_one();
}
void wait() {
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait(lock, [=] { return count_ > 0; });
--count_;
}
void reset() {
std::unique_lock<std::mutex> lock(mutex_);
count_ = 0;
cv_.notify_one();
}
private:
std::mutex mutex_;
std::condition_variable cv_;
int count_;
};
}