<commit_before>#ifndef DSA_SDK_UTIL_ENABLE_SHARED_H_
#define DSA_SDK_UTIL_ENABLE_SHARED_H_

#if defined(_MSC_VER)
#pragma once
#endif

#include <stdexcept>
#include <mutex>
#include <memory>

namespace dsa {

template <class T, typename... Args>
inline shared_ptr_<T> make_shared_(Args &&... args) {
  return std::make_shared<T>(std::forward<Args>(args)...);
}

template <typename T>
class SharedDestroyable : public std::enable_shared_from_this<T> {
 private:
  bool _destroyed = false;

 protected:
  virtual void destroy_impl(){};
  virtual void post_in_strand(std::function<void()> &&) = 0;

 public:
  shared_ptr_<T> shared_from_this() {
    return std::enable_shared_from_this<T>::shared_from_this();
  }

  template <class Down>
  shared_ptr_<Down> share_this() {
    return std::dynamic_pointer_cast<Down>(shared_from_this());
  }

  std::mutex mutex;
  bool is_destroyed() const { return _destroyed; }

  // reuse any lock
  void destroy(std::lock_guard<std::mutex> &unique_lock) {
    if (!_destroyed) {
      _destroyed = true;
      destroy_impl();
    }
  }
  void destroy() {
    std::lock_guard<std::mutex> unique_lock(mutex);
    destroy(unique_lock);
  }

  void destroy_in_strand(shared_ptr_<SharedDestroyable<T>> &&destroyable) {
    post_in_strand(
        [ this, keep_ptr = std::move(destroyable) ]() { destroy(); });
  }
  void destroy_in_strand(shared_ptr_<SharedDestroyable<T>> &destroyable) {
    post_in_strand([ this, keep_ptr = destroyable ]() { destroy(); });
  }
};
}  // namespace dsa

#endif  // DSA_SDK_UTIL_ENABLE_SHARED_H_
<commit_msg>shared_ptr_ is in dsa_common.h, so added to the includes<commit_after>#ifndef DSA_SDK_UTIL_ENABLE_SHARED_H_
#define DSA_SDK_UTIL_ENABLE_SHARED_H_

#if defined(_MSC_VER)
#pragma once
#endif

#include <stdexcept>
#include <mutex>
#include <memory>

#include "dsa_common.h"

namespace dsa {

template <class T, typename... Args>
inline shared_ptr_<T> make_shared_(Args &&... args) {
  return std::make_shared<T>(std::forward<Args>(args)...);
}

template <typename T>
class SharedDestroyable : public std::enable_shared_from_this<T> {
 private:
  bool _destroyed = false;

 protected:
  virtual void destroy_impl(){};
  virtual void post_in_strand(std::function<void()> &&) = 0;

 public:
  shared_ptr_<T> shared_from_this() {
    return std::enable_shared_from_this<T>::shared_from_this();
  }

  template <class Down>
  shared_ptr_<Down> share_this() {
    return std::dynamic_pointer_cast<Down>(shared_from_this());
  }

  std::mutex mutex;
  bool is_destroyed() const { return _destroyed; }

  // reuse any lock
  void destroy(std::lock_guard<std::mutex> &unique_lock) {
    if (!_destroyed) {
      _destroyed = true;
      destroy_impl();
    }
  }
  void destroy() {
    std::lock_guard<std::mutex> unique_lock(mutex);
    destroy(unique_lock);
  }

  void destroy_in_strand(shared_ptr_<SharedDestroyable<T>> &&destroyable) {
    post_in_strand(
        [ this, keep_ptr = std::move(destroyable) ]() { destroy(); });
  }
  void destroy_in_strand(shared_ptr_<SharedDestroyable<T>> &destroyable) {
    post_in_strand([ this, keep_ptr = destroyable ]() { destroy(); });
  }
};
}  // namespace dsa

#endif  // DSA_SDK_UTIL_ENABLE_SHARED_H_

{'fraction_non_alphanumeric': 0.1395638629283489, 'fraction_numerical': 0.0006230529595015577, 'mean_word_length': 4.880952380952381, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '492218', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1141, 'n_words': 214}