<commit_before>/* <x0/Queue.h>
 *
 * This file is part of the x0 web server project and is released under GPL-3.
 * http://www.xzero.io/
 *
 * (c) 2009-2013 <NAME> <<EMAIL>>
 */

#pragma once

#include <x0/Api.h>
#include <x0/Defines.h>

namespace x0 {

/*! Implements a basic lock free & non-blocking queue.
 *
 * See http://www.cs.rochester.edu/u/scott/papers/1996_PODC_queues.pdf for further
 * implementation details.
 */
template<typename T>
class X0_API Queue
{
private:
	struct NodePtr;
	struct Node;

	NodePtr front_;
	NodePtr back_;

public:
	Queue();
	~Queue();

	void enqueue(const T& value);
	bool dequeue(T* result);
};

// {{{ Queue<T>::NodePtr impl
template<typename T>
struct Queue<T>::NodePtr
{
	Node* ptr;
	unsigned count;

	NodePtr() : ptr(nullptr), count(0) {}
	NodePtr(Node* p, unsigned c) : ptr(p), count(c) {}

	NodePtr(const NodePtr& np) :
		ptr(nullptr),
		count(0)
	{
		__sync_lock_test_and_set(&count, np.count);
		__sync_lock_test_and_set(&ptr, np.ptr);
	}

	NodePtr(const NodePtr* np) :
		ptr(nullptr),
		count(0)
	{
		if (likely(np != nullptr)) {
			__sync_lock_test_and_set(&count, np->count);
			__sync_lock_test_and_set(&ptr, np->ptr);
		}
	}

	Node* get() const {
		return ptr;
	}

	Node* operator->() {<commit_msg>[base] Queue: drop gcc warning.<commit_after>/* <x0/Queue.h>
 *
 * This file is part of the x0 web server project and is released under GPL-3.
 * http://www.xzero.io/
 *
 * (c) 2009-2013 <NAME> <<EMAIL>>
 */

#pragma once

#include <x0/Api.h>
#include <x0/Defines.h>

namespace x0 {

/*! Implements a basic lock free & non-blocking queue.
 *
 * See http://www.cs.rochester.edu/u/scott/papers/1996_PODC_queues.pdf for further
 * implementation details.
 */
template<typename T>
class X0_API Queue
{
private:
	struct NodePtr;
	struct Node;

	NodePtr front_;
	NodePtr back_;

public:
	Queue();
	~Queue();

	void enqueue(const T& value);
	bool dequeue(T* result);
};

// {{{ Queue<T>::NodePtr impl
template<typename T>
struct Queue<T>::NodePtr
{
	Node* ptr;
	unsigned count;

	NodePtr() : ptr(nullptr), count(0) {}
	NodePtr(Node* p, unsigned c) : ptr(p), count(c) {}

	NodePtr(const NodePtr& np) :
		ptr(np.ptr),
		count(np.count)
	{
	}

	NodePtr(const NodePtr* np) :
		ptr(nullptr),
		count(0)
	{
		if (likely(np != nullptr)) {
			count = np->count;
			ptr = np->ptr;
		}
	}

	Node* get() const {
		return ptr;
	}

	Node* operator->() {
{'fraction_non_alphanumeric': 0.16540722082283796, 'fraction_numerical': 0.018052057094878254, 'mean_word_length': 3.7094861660079053, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2084449', 'n_tokens_mistral': 1002, 'n_tokens_neox': 940, 'n_words': 228}