Skip to content

File logmutex.h

File List > code_source > templat > include > TempLat > util > log > logmutex.h

Go to the documentation of this file

#ifndef TEMPLAT_UTIL_LOG_LOGMUTEX_H
#define TEMPLAT_UTIL_LOG_LOGMUTEX_H

/* This file is part of TempLat, available at https://cosmolattice.github.io/templat .
   Copyright 2021-2026 The TempLat authors, see AUTHORS.md.
   Released under the MIT license, see LICENSE.md. */

// File info: Main contributor(s): Wessel Valkenburg, Year: 2019

#include <memory>
#include <mutex>
#include <iostream>

#include "TempLat/util/tdd/tddmacros.h"

namespace TempLat
{

  class LogMutex
  {
  public:
    // Put public methods here. These should change very little over time.
    LogMutex() = default;

    static void lock()
    {
      std::cerr << "Mutex locking.\n";
      mutex()->lock();
    }

    static void unlock()
    {
      std::cerr << "Mutex unlocking.\n";
      mutex()->unlock();
    }

    static inline std::unique_ptr<std::lock_guard<std::recursive_mutex>> guard()
    {
      return std::make_unique<std::lock_guard<std::recursive_mutex>>(*mutex());
    }

  private:
    /* Put all member variables and private methods here. These may change arbitrarily. */

    inline static std::shared_ptr<std::recursive_mutex> mutex()
    {
      static std::shared_ptr<std::recursive_mutex> mut = std::make_shared<std::recursive_mutex>();
      return mut;
    }

  public:
    template <typename TestObjectUnknownHere> static inline void Test(TestObjectUnknownHere &tdd);
  };
} // namespace TempLat

#endif