Skip to content

Commit 0d94e72

Browse files
committed
pointer magic
1 parent e76000f commit 0d94e72

File tree

6 files changed

+13
-49
lines changed

6 files changed

+13
-49
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

profiling-ffi/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ build_common = { path = "../build-common" }
2727
[dependencies]
2828
anyhow = "1.0"
2929
chrono = {version = "0.4", default-features = false }
30+
crossbeam-queue = "0.3.11"
3031
datadog-crashtracker = { path = "../crashtracker" }
3132
datadog-profiling = { path = "../profiling" }
3233
hyper = { version = "0.14", default-features = false }

profiling-ffi/src/array_queue.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
use anyhow::Context;
2-
use datadog_profiling::internal;
32
use ddcommon_ffi::Error;
43
use std::ffi::c_void;
54

65
#[repr(C)]
76
pub struct ArrayQueue {
8-
pub inner: *mut internal::ArrayQueue,
7+
inner: *mut c_void,
98
}
109

1110
impl ArrayQueue {
12-
pub fn new(inner: internal::ArrayQueue) -> Self {
13-
Self {
14-
inner: Box::into_raw(Box::new(inner)),
15-
}
11+
pub fn new(inner: *mut c_void) -> Self {
12+
Self { inner }
1613
}
1714
}
1815

@@ -25,19 +22,23 @@ pub enum ArrayQueueNewResult {
2522

2623
#[no_mangle]
2724
pub unsafe extern "C" fn array_queue_new(capacity: usize) -> ArrayQueueNewResult {
28-
let internal_queue = internal::ArrayQueue::new(capacity);
29-
let ffi_queue = ArrayQueue::new(internal_queue);
25+
let internal_queue: crossbeam_queue::ArrayQueue<*mut c_void> =
26+
crossbeam_queue::ArrayQueue::new(capacity);
27+
let internal_queue_ptr = Box::into_raw(Box::new(internal_queue));
28+
let ffi_queue = ArrayQueue::new(internal_queue_ptr as *mut c_void);
3029
ArrayQueueNewResult::Ok(ffi_queue)
3130
}
3231

3332
unsafe fn array_queue_ptr_to_inner<'a>(
3433
queue_ptr: *mut ArrayQueue,
35-
) -> anyhow::Result<&'a mut internal::ArrayQueue> {
34+
) -> anyhow::Result<&'a mut crossbeam_queue::ArrayQueue<*mut c_void>> {
3635
match queue_ptr.as_mut() {
3736
None => anyhow::bail!("queue_ptr is null"),
3837
Some(queue) => match queue.inner.as_mut() {
3938
None => anyhow::bail!("queue.inner is null"),
40-
Some(inner) => Ok(inner),
39+
Some(inner) => {
40+
Ok(&mut *(inner as *mut c_void as *mut crossbeam_queue::ArrayQueue<*mut c_void>))
41+
}
4142
},
4243
}
4344
}

profiling/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ anyhow = "1.0"
2222
bitmaps = "3.2.0"
2323
bytes = "1.1"
2424
chrono = {version = "0.4", default-features = false, features = ["std", "clock"]}
25-
crossbeam-queue = "0.3.11"
2625
datadog-alloc = {path = "../alloc"}
2726
ddcommon = {path = "../ddcommon"}
2827
derivative = "2.2.0"

profiling/src/internal/array_queue.rs

-35
This file was deleted.

profiling/src/internal/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/
22
// SPDX-License-Identifier: Apache-2.0
33

4-
mod array_queue;
54
mod endpoint_stats;
65
mod endpoints;
76
mod function;
@@ -17,7 +16,6 @@ mod timestamp;
1716
mod upscaling;
1817
mod value_type;
1918

20-
pub use array_queue::*;
2119
pub use endpoint_stats::*;
2220
pub use endpoints::*;
2321
pub use function::*;

0 commit comments

Comments
 (0)