Skip to content

Commit e76000f

Browse files
committed
not sure whether this is right way? but builds and passes lint
1 parent 5d0d2e3 commit e76000f

File tree

7 files changed

+73
-27
lines changed

7 files changed

+73
-27
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

profiling-ffi/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ 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"
3130
datadog-crashtracker = { path = "../crashtracker" }
3231
datadog-profiling = { path = "../profiling" }
3332
hyper = { version = "0.14", default-features = false }

profiling-ffi/cbindgen.toml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ renaming_overrides_prefixing = true
3333
"Vec_Tag" = "ddog_Vec_Tag"
3434
"Vec_U8" = "ddog_Vec_U8"
3535

36+
"ArrayQueueNewResult" = "ddog_prof_ArrayQueue_NewResult"
37+
"ArrayQueuePushResult" = "ddog_prof_ArrayQueue_PushResult"
38+
"ArrayQueuePopResult" = "ddog_prof_ArrayQueue_PopResult"
39+
"ArrayQueueIsEmptyResult" = "ddog_prof_ArrayQueue_IsEmptyResult"
40+
"ArrayQueueLenResult" = "ddog_prof_ArrayQueue_LenResult"
3641
"ProfilingEndpoint" = "ddog_prof_Endpoint"
3742
"ExporterNewResult" = "ddog_prof_Exporter_NewResult"
3843
"File" = "ddog_prof_Exporter_File"
@@ -57,5 +62,10 @@ must_use = "DDOG_CHECK_RETURN"
5762

5863
[parse]
5964
parse_deps = true
60-
include = ["ddcommon", "ddcommon-ffi", "datadog-profiling", "datadog-crashtracker", "ux"]
61-
65+
include = [
66+
"ddcommon",
67+
"ddcommon-ffi",
68+
"datadog-profiling",
69+
"datadog-crashtracker",
70+
"ux",
71+
]

profiling-ffi/src/array_queue.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
use anyhow::Context;
2-
use crossbeam_queue::ArrayQueue as CBArrayQueue;
2+
use datadog_profiling::internal;
33
use ddcommon_ffi::Error;
44
use std::ffi::c_void;
55

6-
#[allow(dead_code)]
76
#[repr(C)]
87
pub struct ArrayQueue {
9-
inner: *mut CBArrayQueue<*mut c_void>,
8+
pub inner: *mut internal::ArrayQueue,
109
}
1110

1211
impl ArrayQueue {
13-
fn new(queue: CBArrayQueue<*mut c_void>) -> Self {
12+
pub fn new(inner: internal::ArrayQueue) -> Self {
1413
Self {
15-
inner: Box::into_raw(Box::new(queue)),
14+
inner: Box::into_raw(Box::new(inner)),
1615
}
1716
}
1817
}
@@ -24,32 +23,16 @@ pub enum ArrayQueueNewResult {
2423
Err(Error),
2524
}
2625

27-
#[allow(unused)]
28-
#[repr(C)]
29-
pub enum ArrayQueuePushResult {
30-
Ok(bool),
31-
Err(Error),
32-
}
33-
34-
impl From<Result<(), anyhow::Error>> for ArrayQueuePushResult {
35-
fn from(result: Result<(), anyhow::Error>) -> Self {
36-
match result {
37-
Ok(_) => ArrayQueuePushResult::Ok(true),
38-
Err(err) => ArrayQueuePushResult::Err(err.into()),
39-
}
40-
}
41-
}
42-
4326
#[no_mangle]
4427
pub unsafe extern "C" fn array_queue_new(capacity: usize) -> ArrayQueueNewResult {
45-
let internal_queue = CBArrayQueue::new(capacity);
28+
let internal_queue = internal::ArrayQueue::new(capacity);
4629
let ffi_queue = ArrayQueue::new(internal_queue);
4730
ArrayQueueNewResult::Ok(ffi_queue)
4831
}
4932

5033
unsafe fn array_queue_ptr_to_inner<'a>(
5134
queue_ptr: *mut ArrayQueue,
52-
) -> anyhow::Result<&'a mut crossbeam_queue::ArrayQueue<*mut c_void>> {
35+
) -> anyhow::Result<&'a mut internal::ArrayQueue> {
5336
match queue_ptr.as_mut() {
5437
None => anyhow::bail!("queue_ptr is null"),
5538
Some(queue) => match queue.inner.as_mut() {
@@ -59,6 +42,22 @@ unsafe fn array_queue_ptr_to_inner<'a>(
5942
}
6043
}
6144

45+
#[allow(unused)]
46+
#[repr(C)]
47+
pub enum ArrayQueuePushResult {
48+
Ok(bool),
49+
Err(Error),
50+
}
51+
52+
impl From<Result<(), anyhow::Error>> for ArrayQueuePushResult {
53+
fn from(result: Result<(), anyhow::Error>) -> Self {
54+
match result {
55+
Ok(_) => ArrayQueuePushResult::Ok(true),
56+
Err(err) => ArrayQueuePushResult::Err(err.into()),
57+
}
58+
}
59+
}
60+
6261
#[no_mangle]
6362
pub unsafe extern "C" fn array_queue_push(
6463
queue_ptr: *mut ArrayQueue,

profiling/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ 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"
2526
datadog-alloc = {path = "../alloc"}
2627
ddcommon = {path = "../ddcommon"}
2728
derivative = "2.2.0"

profiling/src/internal/array_queue.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use std::ffi::c_void;
2+
3+
#[derive(Debug)]
4+
#[allow(unused)]
5+
pub struct ArrayQueue {
6+
inner: crossbeam_queue::ArrayQueue<*mut c_void>,
7+
}
8+
9+
impl ArrayQueue {
10+
#[allow(unused)]
11+
pub fn new(capacity: usize) -> Self {
12+
Self {
13+
inner: crossbeam_queue::ArrayQueue::new(capacity),
14+
}
15+
}
16+
17+
#[allow(unused)]
18+
pub fn push(&self, value: *mut c_void) -> Result<(), *mut c_void> {
19+
self.inner.push(value)
20+
}
21+
22+
#[allow(unused)]
23+
pub fn pop(&self) -> Option<*mut c_void> {
24+
self.inner.pop()
25+
}
26+
27+
#[allow(unused)]
28+
pub fn is_empty(&self) -> bool {
29+
self.inner.is_empty()
30+
}
31+
32+
pub fn len(&self) -> usize {
33+
self.inner.len()
34+
}
35+
}

profiling/src/internal/mod.rs

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

4+
mod array_queue;
45
mod endpoint_stats;
56
mod endpoints;
67
mod function;
@@ -16,6 +17,7 @@ mod timestamp;
1617
mod upscaling;
1718
mod value_type;
1819

20+
pub use array_queue::*;
1921
pub use endpoint_stats::*;
2022
pub use endpoints::*;
2123
pub use function::*;

0 commit comments

Comments
 (0)