chromium/third_party/ipcz/src/util/multi_mutex_lock.h

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef IPCZ_SRC_UTIL_MULTI_MUTEX_LOCK_H_
#define IPCZ_SRC_UTIL_MULTI_MUTEX_LOCK_H_

#include <algorithm>
#include <array>
#include <cstddef>

#include "third_party/abseil-cpp/absl/synchronization/mutex.h"

namespace ipcz {

// MultiMutexLock is a scoped mutex locker capable of locking between two and
// four mutexes simultaneously. Locks are always acquired in a globally
// consistent order  based on the address of each Mutex.
template <size_t N>
class ABSL_SCOPED_LOCKABLE MultiMutexLock {};

// Helpful deduction guides so instantiations can omit a template argument.
<deduction guide for MultiMutexLock>(absl::Mutex *, absl::Mutex *);
<deduction guide for MultiMutexLock>(absl::Mutex *, absl::Mutex *, absl::Mutex *);
<deduction guide for MultiMutexLock>(absl::Mutex *, absl::Mutex *, absl::Mutex *, absl::Mutex *);

}  // namespace ipcz

#endif  // IPCZ_SRC_UTIL_MULTI_MUTEX_LOCK_H_