<commit_before>using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;

namespace NMaier.SimpleDlna.FileMediaServer
{
  internal sealed class Thumbnailer
  {
    private struct Item
    {
      public readonly WeakReference Store;
      public readonly WeakReference File;

      public Item(WeakReference store, WeakReference file)
      {
        Store = store;
        File = file;
      }
    }

    private static readonly ConcurrentQueue<Item> queue = CreateQueue();
    private static readonly AutoResetEvent signal = new AutoResetEvent(false);

    private static ConcurrentQueue<Item> CreateQueue()
    {
      new Thread(Run)
      {
        IsBackground = true,
        Priority = ThreadPriority.Lowest
      }.Start();

      return new ConcurrentQueue<Item>();
    }

    private static void Run()
    {
      var logger = log4net.LogManager.GetLogger(typeof(Thumbnailer));
      logger.Debug("thumber started");
      while (signal.WaitOne()) {
        Item item;
        while (queue.TryDequeue(out item)) {
          var store = item.Store.Target as FileStore;
          var file = item.File.Target as BaseFile;
          if (store == null || file == null) {
            continue;
          }
          try {
            if (store.HasCover(file)) {
              continue;
            }
            logger.DebugFormat("Trying {0}", file.Item.FullName);
            file.LoadCover();
            using (var k = file.Cover.Content) {
              k.ReadByte();
            }
          }
          catch (Exception) {
            // Already logged and don't care.
          }
        }
      }
    }

    public static void AddFiles(FileStore store, IEnumerable<WeakReference> items)
    {
      var storeRef = new WeakReference(store);
      foreach (var i in items) {
        queue.Enqueue(new Item(storeRef, i));
      }
      signal.Set();
    }
  }
}<commit_msg>FSServer: Switch Thumbnailer to BlockingCollection<commit_after>using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;

namespace NMaier.SimpleDlna.FileMediaServer
{
  internal sealed class Thumbnailer
  {
    private struct Item
    {
      public readonly WeakReference Store;
      public readonly WeakReference File;

      public Item(WeakReference store, WeakReference file)
      {
        Store = store;
        File = file;
      }
    }

    private static readonly BlockingCollection<Item> queue = CreateQueue();

    private static BlockingCollection<Item> CreateQueue()
    {
      new Thread(Run)
      {
        IsBackground = true,
        Priority = ThreadPriority.Lowest
      }.Start();

      return new BlockingCollection<Item>(new ConcurrentQueue<Item>());
    }

    private static void Run()
    {
      var logger = log4net.LogManager.GetLogger(typeof(Thumbnailer));
      logger.Debug("Thumber started");
      try {
        for (; ; ) {
          var item = queue.Take();
          var store = item.Store.Target as FileStore;
          var file = item.File.Target as BaseFile;
          if (store == null || file == null) {
            continue;
          }
          try {
            if (store.HasCover(file)) {
              continue;
            }
            logger.DebugFormat("Trying {0}", file.Item.FullName);
            file.LoadCover();
            using (var k = file.Cover.Content) {
              k.ReadByte();
            }
          }
          catch (Exception) {
            // Already logged and don't care.
          }
        }
      }
      finally {
        logger.Debug("Thumber stopped");
      }
    }

    public static void AddFiles(FileStore store, IEnumerable<WeakReference> items)
    {
      var storeRef = new WeakReference(store);
      foreach (var i in items) {
        queue.Add(new Item(storeRef, i));
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.09679917398038203, 'fraction_numerical': 0.0010325245224574084, 'mean_word_length': 1.955758962623951, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '2607286', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1036, 'n_words': 264}