Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change task counter AtomicU64 to AtomicU32 #141

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/task/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::fmt;
use std::pin::Pin;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::atomic::{AtomicU32, Ordering};
use std::thread;
use std::time::Duration;

Expand All @@ -13,9 +13,9 @@ use crate::future::Future;
use crate::task::{Context, Poll};
use crate::utils::abort_on_panic;

const MAX_THREADS: u64 = 10_000;
const MAX_THREADS: u32 = 10_000;

static DYNAMIC_THREAD_COUNT: AtomicU64 = AtomicU64::new(0);
static DYNAMIC_THREAD_COUNT: AtomicU32 = AtomicU32::new(0);

struct Pool {
sender: Sender<async_task::Task<()>>,
Expand Down
16 changes: 8 additions & 8 deletions src/task/task.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::fmt;
use std::i64;
use std::i32;
use std::mem;
use std::num::NonZeroU64;
use std::num::NonZeroU32;
use std::pin::Pin;
use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
use std::sync::atomic::{AtomicU32, AtomicUsize, Ordering};
use std::sync::Arc;

use super::local;
Expand Down Expand Up @@ -105,22 +105,22 @@ impl<T> Future for JoinHandle<T> {
/// })
/// ```
#[derive(Eq, PartialEq, Clone, Copy, Hash, Debug)]
pub struct TaskId(NonZeroU64);
pub struct TaskId(NonZeroU32);

impl TaskId {
pub(crate) fn new() -> TaskId {
static COUNTER: AtomicU64 = AtomicU64::new(1);
static COUNTER: AtomicU32 = AtomicU32::new(1);

let id = COUNTER.fetch_add(1, Ordering::Relaxed);

if id > i64::MAX as u64 {
if id > i32::MAX as u32 {
std::process::abort();
}
unsafe { TaskId(NonZeroU64::new_unchecked(id)) }
unsafe { TaskId(NonZeroU32::new_unchecked(id)) }
}

pub(crate) fn as_u64(&self) -> u64 {
self.0.get()
self.0.get() as u64
}
}

Expand Down