<commit_before>// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! A lock-free concurrent work-stealing deque
//!
//! This module contains an implementation of the Chase-Lev work stealing deque
//! described in "Dynamic Circular Work-Stealing Deque". The implementation is
//! heavily based on the pseudocode found in the paper.
//!
//! # Example
//!
//! ```
//! use crossbeam::sync::chase_lev;
//! let (mut worker, stealer) = chase_lev::deque();
//!
//! // Only the worker may push/try_pop
//! worker.push(1);
//! worker.try_pop();
//!
//! // Stealers take data from the other end of the deque
//! worker.push(1);
//! stealer.steal();
//!
//! // Stealers can be cloned to have many stealers stealing in parallel
//! worker.push(1);
//! let stealer2 = stealer.clone();
//! stealer2.steal();
//! ```

// FIXME: all atomic operations in this module use a SeqCst ordering. That is
//      probably overkill

use std::cell::UnsafeCell;
use std::mem;
use std::ptr;
use std::sync::atomic::Ordering::SeqCst;
use std::sync::atomic::AtomicIsize;
use std::sync::Arc;

use mem::epoch::{self, Atomic, Shared, Owned};

// Once the queue is less than 1/K full, then it will be downsized. Note that
// the deque requires that this number be less than 2.
const K: isize = 4;

// Minimum number of bits that a buffer size should be. No buffer will resize to
// under this value, and all deques will initially contain a buffer of this
// size.
//
// The size in question is 1 << MIN_BITS
const MIN_BITS: u32 = 7;

struct Deque<T> {
    bottom: AtomicIsize,
    top: AtomicIsize,
    array: Atomic<Buffer<T>>,
}

// FIXME: can these constraints be relaxed?
unsafe impl<T: Send + Sync> Send for Deque<T> {}
unsafe impl<T: Send + Sync> Sync for Deque<T> {}<commit_msg>Relax the requirements for `Deque<T>` to be `Send` and `Sync`.<commit_after>// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! A lock-free concurrent work-stealing deque
//!
//! This module contains an implementation of the Chase-Lev work stealing deque
//! described in "Dynamic Circular Work-Stealing Deque". The implementation is
//! heavily based on the pseudocode found in the paper.
//!
//! # Example
//!
//! ```
//! use crossbeam::sync::chase_lev;
//! let (mut worker, stealer) = chase_lev::deque();
//!
//! // Only the worker may push/try_pop
//! worker.push(1);
//! worker.try_pop();
//!
//! // Stealers take data from the other end of the deque
//! worker.push(1);
//! stealer.steal();
//!
//! // Stealers can be cloned to have many stealers stealing in parallel
//! worker.push(1);
//! let stealer2 = stealer.clone();
//! stealer2.steal();
//! ```

// FIXME: all atomic operations in this module use a SeqCst ordering. That is
//      probably overkill

use std::cell::UnsafeCell;
use std::mem;
use std::ptr;
use std::sync::atomic::Ordering::SeqCst;
use std::sync::atomic::AtomicIsize;
use std::sync::Arc;

use mem::epoch::{self, Atomic, Shared, Owned};

// Once the queue is less than 1/K full, then it will be downsized. Note that
// the deque requires that this number be less than 2.
const K: isize = 4;

// Minimum number of bits that a buffer size should be. No buffer will resize to
// under this value, and all deques will initially contain a buffer of this
// size.
//
// The size in question is 1 << MIN_BITS
const MIN_BITS: u32 = 7;

struct Deque<T> {
    bottom: AtomicIsize,
    top: AtomicIsize,
    array: Atomic<Buffer<T>>,
}

// FIXME: can these constraints be relaxed?
unsafe impl<T: Send> Send for Deque<T> {}
unsafe impl<T: Send> Sync for Deque<T> {}
{'fraction_non_alphanumeric': 0.14311884588962676, 'fraction_numerical': 0.009159606136936112, 'mean_word_length': 3.4708290685772774, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5248256', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1335, 'n_words': 529}