refactor: remove atomic

This commit is contained in:
MusiKid 2022-01-25 18:23:09 +01:00 committed by musikid
parent 11762b7654
commit 9dae2b66b3
No known key found for this signature in database
GPG key ID: 7567D43648C6E2F4

View file

@ -281,20 +281,17 @@ auto identify(pam_handle_t *pamh, int flags, int argc, const char **argv,
// it's too recent (C++20) // it's too recent (C++20)
std::mutex m; std::mutex m;
std::condition_variable cv; std::condition_variable cv;
std::atomic<ConfirmationType> confirmation_type(ConfirmationType::Unset); ConfirmationType confirmation_type(ConfirmationType::Unset);
// This task wait for the status of the python subprocess (we don't want a // This task wait for the status of the python subprocess (we don't want a
// zombie process) // zombie process)
optional_task<int> child_task([&] { optional_task<int> child_task([&] {
int status; int status;
wait(&status); wait(&status);
{ {
std::unique_lock<std::mutex> lk(m); std::unique_lock<std::mutex> lk(m);
ConfirmationType type = confirmation_type.load(std::memory_order_relaxed); if (confirmation_type == ConfirmationType::Unset) {
if (type == ConfirmationType::Unset) { confirmation_type = ConfirmationType::Howdy;
confirmation_type.store(ConfirmationType::Howdy,
std::memory_order_relaxed);
} }
} }
cv.notify_one(); cv.notify_one();
@ -310,10 +307,8 @@ auto identify(pam_handle_t *pamh, int flags, int argc, const char **argv,
pamh, PAM_AUTHTOK, const_cast<const char **>(&auth_tok_ptr), nullptr); pamh, PAM_AUTHTOK, const_cast<const char **>(&auth_tok_ptr), nullptr);
{ {
std::unique_lock<std::mutex> lk(m); std::unique_lock<std::mutex> lk(m);
ConfirmationType type = confirmation_type.load(std::memory_order_relaxed); if (confirmation_type == ConfirmationType::Unset) {
if (type == ConfirmationType::Unset) { confirmation_type = ConfirmationType::Pam;
confirmation_type.store(ConfirmationType::Pam,
std::memory_order_relaxed);
} }
} }
cv.notify_one(); cv.notify_one();