<commit_before>/************************************************
 * Copyright (c) IBM Corp. 2014
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *************************************************/

/*
 * Contributors:
 *     lschneid - initial implementation
 */

/* WARNING: Data access is not thread-safe!! */

#ifndef __SKV_ARRAY_QUEUE_HPP__
#define __SKV_ARRAY_QUEUE_HPP__

#include <FxLogger.hpp>

template<class T, size_t SKV_ARRAY_QUEUE_SIZE>
class skv_array_queue_t
{
  size_t len;
  volatile T *Memory;
  volatile size_t head;
  volatile size_t tail;

public:
  skv_array_queue_t()
  {
    len = 0;
    Memory = new T[SKV_ARRAY_QUEUE_SIZE + 1];
    head = 0;
    tail = 0;
  }

  ~skv_array_queue_t()
  {
    delete[] Memory;
  }

  void push( const T element )
  {
    Memory[head] = element;
    len++;

    AssertLogLine( len < SKV_ARRAY_QUEUE_SIZE )
      << "skv_array_queue_t::push():  Queue overflow"
      << " size: " << len
      << " max: " << SKV_ARRAY_QUEUE_SIZE
      << EndLogLine;

    head = (head + 1) % SKV_ARRAY_QUEUE_SIZE;
  }

  T front()
  {
    return Memory[tail];
  }

  void pop()
  {
    if( (len > 0) && ((len%SKV_ARRAY_QUEUE_SIZE) == len) )
    {
      tail = (tail + 1) % SKV_ARRAY_QUEUE_SIZE;
      len--;
    }
    else
      AssertLogLine( 1 )
        << "skv_array_queue_t::pop(): queue underflow"
        << EndLogLine;
  }

  int size()
  {
    return len;
  }

  bool empty()
  {
    return (len == 0);
  }

};

#endif // __SKV_ARRAY_QUEUE_HPP__
<commit_msg>array queue needs volatile len too<commit_after>/************************************************
 * Copyright (c) IBM Corp. 2014
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *************************************************/

/*
 * Contributors:
 *     lschneid - initial implementation
 */

/* WARNING: Data access is not thread-safe!! */

#ifndef __SKV_ARRAY_QUEUE_HPP__
#define __SKV_ARRAY_QUEUE_HPP__

#include <FxLogger.hpp>

template<class T, size_t SKV_ARRAY_QUEUE_SIZE>
class skv_array_queue_t
{
  volatile size_t len;
  volatile T *Memory;
  volatile size_t head;
  volatile size_t tail;

public:
  skv_array_queue_t()
  {
    len = 0;
    Memory = new T[SKV_ARRAY_QUEUE_SIZE + 1];
    head = 0;
    tail = 0;
  }

  ~skv_array_queue_t()
  {
    delete[] Memory;
  }

  void push( const T element )
  {
    Memory[head] = element;
    len++;

    AssertLogLine( len < SKV_ARRAY_QUEUE_SIZE )
      << "skv_array_queue_t::push():  Queue overflow"
      << " size: " << len
      << " max: " << SKV_ARRAY_QUEUE_SIZE
      << EndLogLine;

    head = (head + 1) % SKV_ARRAY_QUEUE_SIZE;
  }

  T front()
  {
    return Memory[tail];
  }

  void pop()
  {
    if( (len > 0) && ((len%SKV_ARRAY_QUEUE_SIZE) == len) )
    {
      tail = (tail + 1) % SKV_ARRAY_QUEUE_SIZE;
      len--;
    }
    else
      AssertLogLine( 1 )
        << "skv_array_queue_t::pop(): queue underflow"
        << EndLogLine;
  }

  int size()
  {
    return len;
  }

  bool empty()
  {
    return (len == 0);
  }

};

#endif // __SKV_ARRAY_QUEUE_HPP__

{'fraction_non_alphanumeric': 0.16996507566938301, 'fraction_numerical': 0.00989522700814901, 'mean_word_length': 2.9460390355912742, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3372838', 'n_tokens_mistral': 1267, 'n_tokens_neox': 1204, 'n_words': 288}