mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-05 17:52:29 +00:00
Stuff.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "pid_watcher.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <torrent/exceptions.h>
|
||||
|
||||
PidWatcher::PidWatcher(std::thread::id thread_id)
|
||||
: m_thread_id(thread_id) {
|
||||
}
|
||||
|
||||
PidWatcher::~PidWatcher() = default;
|
||||
|
||||
void
|
||||
PidWatcher::prepare_spawn() {
|
||||
assert(std::this_thread::get_id() == m_thread_id);
|
||||
|
||||
if (m_spawn_in_progress.exchange(true, std::memory_order_acquire))
|
||||
throw torrent::internal_error("PidWatcher::prepare_spawn() called while spawn already in progress.");
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef RTORRENT_PID_WATCHER_H
|
||||
#define RTORRENT_PID_WATCHER_H
|
||||
|
||||
#include <torrent/common.h>
|
||||
|
||||
struct atomic_queue {
|
||||
std::array<std::atomic<pid_t>, 16> queue{};
|
||||
|
||||
|
||||
class PidWatcher {
|
||||
public:
|
||||
PidWatcher(std::thread::id thread_id);
|
||||
~PidWatcher();
|
||||
|
||||
void prepare_spawn();
|
||||
void completed_spawn(pid_t pid);
|
||||
|
||||
private:
|
||||
std::thread::id m_thread_id;
|
||||
|
||||
align_cacheline
|
||||
|
||||
std::atomic<bool> m_spawn_in_progress{};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user