
#ifndef PLS_THREAD_STATE_H
#define PLS_THREAD_STATE_H

#include <random>

#include "pls/internal/data_structures/aligned_stack.h"
#include "pls/internal/base/swmr_spin_lock.h"
#include "abstract_task.h"

namespace pls {
namespace internal {
namespace scheduling {

// forward declaration
class scheduler;

struct thread_state {
  alignas(base::system_details::CACHE_LINE_SIZE) scheduler *scheduler_;
  alignas(base::system_details::CACHE_LINE_SIZE) abstract_task *root_task_;
  alignas(base::system_details::CACHE_LINE_SIZE) abstract_task *current_task_;
  alignas(base::system_details::CACHE_LINE_SIZE) data_structures::aligned_stack *task_stack_;
  alignas(base::system_details::CACHE_LINE_SIZE) size_t id_;
  alignas(base::system_details::CACHE_LINE_SIZE) base::swmr_spin_lock lock_;
  alignas(base::system_details::CACHE_LINE_SIZE) std::minstd_rand random_;

  thread_state() :
      scheduler_{nullptr},
      root_task_{nullptr},
      current_task_{nullptr},
      task_stack_{nullptr},
      id_{0},
      lock_{},
      random_{id_} {};

  thread_state(scheduler *scheduler, data_structures::aligned_stack *task_stack, unsigned int id) :
      scheduler_{scheduler},
      root_task_{nullptr},
      current_task_{nullptr},
      task_stack_{task_stack},
      id_{id},
      lock_{},
      random_{id_} {}
};

}
}
}

#endif //PLS_THREAD_STATE_H
