Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Commit

Permalink
Squashed 'deps/ccommon/' changes from 45b7bac..0094e2a
Browse files Browse the repository at this point in the history
0094e2a add convenience array api (twitter#239)
6024ef7 add pipe config to rust ccommon-channel (twitter#247)
eaf7f07 remove ccommon-time (twitter#248)

git-subtree-dir: deps/ccommon
git-subtree-split: 0094e2a99e4d535f8dec590e8474e6e4686bda07
  • Loading branch information
Yao Yue committed Jul 14, 2020
1 parent 686fd02 commit e865600
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 118 deletions.
24 changes: 15 additions & 9 deletions include/cc_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,43 @@ typedef int (*array_compare_fn)(const void *, const void *);
typedef rstatus_i (*array_each_fn)(void *, void *);

struct array {
uint32_t nalloc; /* # allocated element */
size_t size; /* element size */
uint32_t nalloc; /* # allocated element */
uint32_t nelem; /* # element */
uint8_t *data; /* elements */
};


static inline uint32_t
array_nalloc(const struct array *arr)
{
return arr->nalloc;
}

static inline size_t
array_size(const struct array *arr)
{
return arr->size;
}

static inline uint32_t
array_nalloc(const struct array *arr)
{
return arr->nalloc;
}

static inline uint32_t
array_nelem(const struct array *arr)
{
return arr->nelem;
}

static inline size_t
array_nfree(const struct array *arr)
{
return arr->nalloc - arr->nelem;
}

/* resets all fields in array to zero w/o freeing up any memory */
static inline void
array_reset(struct array *arr)
{
arr->nalloc = 0;
arr->size = 0;
arr->nalloc = 0;
arr->nelem = 0;
arr->data = NULL;
}
Expand All @@ -82,8 +88,8 @@ array_reset(struct array *arr)
static inline void
array_data_assign(struct array *arr, uint32_t nalloc, size_t size, void *data)
{
arr->nalloc = nalloc;
arr->size = size;
arr->nalloc = nalloc;
arr->nelem = 0;
arr->data = data;
}
Expand Down
1 change: 0 additions & 1 deletion rust/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ if(HAVE_RUST)
add_subdirectory(ccommon-stats)
add_subdirectory(ccommon-stream)
add_subdirectory(ccommon-sys)
add_subdirectory(ccommon-time)

endif()
49 changes: 4 additions & 45 deletions rust/ccommon-channel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,8 @@
// Licensed under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
mod pipe;
mod tcp;

// constants to define default values
const TCP_BACKLOG: usize = 128;
const TCP_POOLSIZE: usize = 0;

// helper functions
fn backlog() -> usize {
TCP_BACKLOG
}

fn poolsize() -> usize {
TCP_POOLSIZE
}

// definitions
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TcpConfig {
#[cfg_attr(feature = "serde", serde(default = "backlog"))]
backlog: usize,
#[cfg_attr(feature = "serde", serde(default = "poolsize"))]
poolsize: usize,
}

// implementation
impl TcpConfig {
pub fn backlog(&self) -> usize {
self.backlog
}

pub fn poolsize(&self) -> usize {
self.poolsize
}
}

// trait implementations
impl Default for TcpConfig {
fn default() -> Self {
Self {
backlog: backlog(),
poolsize: poolsize(),
}
}
}
pub use pipe::*;
pub use tcp::*;
38 changes: 38 additions & 0 deletions rust/ccommon-channel/src/pipe/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2020 Twitter, Inc.
// Licensed under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

// constants to define default values
const PIPE_POOLSIZE: usize = 0;

// helper functions
fn poolsize() -> usize {
PIPE_POOLSIZE
}

// definitions
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct PipeConfig {
#[cfg_attr(feature = "serde", serde(default = "poolsize"))]
poolsize: usize,
}

// implementation
impl PipeConfig {
pub fn poolsize(&self) -> usize {
self.poolsize
}
}

// trait implementations
impl Default for PipeConfig {
fn default() -> Self {
Self {
poolsize: poolsize(),
}
}
}
50 changes: 50 additions & 0 deletions rust/ccommon-channel/src/tcp/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2020 Twitter, Inc.
// Licensed under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

// constants to define default values
const TCP_BACKLOG: usize = 128;
const TCP_POOLSIZE: usize = 0;

// helper functions
fn backlog() -> usize {
TCP_BACKLOG
}

fn poolsize() -> usize {
TCP_POOLSIZE
}

// definitions
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TcpConfig {
#[cfg_attr(feature = "serde", serde(default = "backlog"))]
backlog: usize,
#[cfg_attr(feature = "serde", serde(default = "poolsize"))]
poolsize: usize,
}

// implementation
impl TcpConfig {
pub fn backlog(&self) -> usize {
self.backlog
}

pub fn poolsize(&self) -> usize {
self.poolsize
}
}

// trait implementations
impl Default for TcpConfig {
fn default() -> Self {
Self {
backlog: backlog(),
poolsize: poolsize(),
}
}
}
2 changes: 0 additions & 2 deletions rust/ccommon-time/CMakeLists.txt

This file was deleted.

14 changes: 0 additions & 14 deletions rust/ccommon-time/Cargo.toml

This file was deleted.

47 changes: 0 additions & 47 deletions rust/ccommon-time/src/lib.rs

This file was deleted.

0 comments on commit e865600

Please sign in to comment.