Skip to content

Commit

Permalink
replace zp_ prefix with z_
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Feb 28, 2024
1 parent 74c42b8 commit a229066
Show file tree
Hide file tree
Showing 22 changed files with 91 additions and 104 deletions.
2 changes: 1 addition & 1 deletion examples/z_liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int main(int argc, char **argv) {
while (c != 'q') {
c = getchar();
if (c == -1) {
zp_sleep_s(1);
z_sleep_s(1);
} else if (c == 'd') {
printf("Undeclaring liveliness token...\n");
z_drop(z_move(token));
Expand Down
8 changes: 4 additions & 4 deletions examples/z_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int main(int argc, char** argv) {
z_mutex_lock(&mutex);
if (args.warmup_ms) {
printf("Warming up for %dms...\n", args.warmup_ms);
zp_clock_t warmup_start = zp_clock_now();
z_clock_t warmup_start = z_clock_now();

unsigned long elapsed_us = 0;
while (elapsed_us < args.warmup_ms * 1000) {
Expand All @@ -66,18 +66,18 @@ int main(int argc, char** argv) {
if (s != 0) {
handle_error_en(s, "z_condvar_wait");
}
elapsed_us = zp_clock_elapsed_us(&warmup_start);
elapsed_us = z_clock_elapsed_us(&warmup_start);
}
}
unsigned long* results = malloc(sizeof(unsigned long) * args.number_of_pings);
for (int i = 0; i < args.number_of_pings; i++) {
zp_clock_t measure_start = zp_clock_now();
z_clock_t measure_start = z_clock_now();
z_publisher_put(z_loan(pub), data, args.size, NULL);
int s = z_condvar_wait(&cond, &mutex);
if (s != 0) {
handle_error_en(s, "z_condvar_wait");
}
results[i] = zp_clock_elapsed_us(&measure_start);
results[i] = z_clock_elapsed_us(&measure_start);
}
for (int i = 0; i < args.number_of_pings; i++) {
printf("%d bytes: seq=%d rtt=%luµs, lat=%luµs\n", args.size, i, results[i], results[i] / 2);
Expand Down
2 changes: 1 addition & 1 deletion examples/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int main(int argc, char **argv) {

char buf[256];
for (int idx = 0; 1; ++idx) {
zp_sleep_s(1);
z_sleep_s(1);
sprintf(buf, "[%4d] %s", idx, value);
printf("Putting Data ('%s': '%s')...\n", keyexpr, buf);
z_publisher_put_options_t options = z_publisher_put_options_default();
Expand Down
2 changes: 1 addition & 1 deletion examples/z_pub_attachment.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int main(int argc, char **argv) {
char buf[256];
char buf_ind[16];
for (int idx = 0; 1; ++idx) {
zp_sleep_s(1);
z_sleep_s(1);

// add some other attachment value
sprintf(buf_ind, "%d", idx);
Expand Down
2 changes: 1 addition & 1 deletion examples/z_pub_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int main(int argc, char **argv) {

char buf[256];
for (int idx = 0; 1; ++idx) {
zp_sleep_s(1);
z_sleep_s(1);
sprintf(buf, "[%4d] %s", idx, value);
printf("Putting Data ('%s': '%s')...\n", keyexpr, buf);
z_put(z_loan(s), z_keyexpr(keyexpr), (const uint8_t *)buf, strlen(buf), NULL);
Expand Down
2 changes: 1 addition & 1 deletion examples/z_pub_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int main(int argc, char **argv) {
snprintf(buf, 255, "[%4d] %s", idx, value);
size_t len = strlen(buf);
zc_shmbuf_set_length(&shmbuf, len);
zp_sleep_s(1);
z_sleep_s(1);
printf("Putting Data ('%s': '%s')...\n", keyexpr, buf);
z_publisher_put_options_t options = z_publisher_put_options_default();
options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL);
Expand Down
2 changes: 1 addition & 1 deletion examples/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int main(int argc, char **argv) {
while (c != 'q') {
c = getchar();
if (c == -1) {
zp_sleep_s(1);
z_sleep_s(1);
} else {
z_subscriber_pull(z_loan(sub));
}
Expand Down
2 changes: 1 addition & 1 deletion examples/z_query_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main(int argc, char **argv) {
while (c != 'q') {
c = getchar();
if (c == -1) {
zp_sleep_s(1);
z_sleep_s(1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int main(int argc, char **argv) {
while (c != 'q') {
c = getchar();
if (c == -1) {
zp_sleep_s(1);
z_sleep_s(1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/z_scout.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ int main(int argc, char **argv) {
z_owned_closure_hello_t closure = z_closure(callback, drop, context);
printf("Scouting...\n");
z_scout(z_move(config), z_move(closure));
zp_sleep_s(1);
z_sleep_s(1);
return 0;
}
2 changes: 1 addition & 1 deletion examples/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int main(int argc, char **argv) {
while (c != 'q') {
c = getchar();
if (c == -1) {
zp_sleep_s(1);
z_sleep_s(1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/z_sub_attachment.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int main(int argc, char **argv) {
while (c != 'q') {
c = getchar();
if (c == -1) {
zp_sleep_s(1);
z_sleep_s(1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/z_sub_liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int main(int argc, char **argv) {
while (c != 'q') {
c = getchar();
if (c == -1) {
zp_sleep_s(1);
z_sleep_s(1);
}
}

Expand Down
10 changes: 5 additions & 5 deletions examples/z_sub_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
typedef struct {
volatile unsigned long count;
volatile unsigned long finished_rounds;
zp_clock_t start;
zp_clock_t first_start;
z_clock_t start;
z_clock_t first_start;
bool started;
} z_stats_t;

Expand All @@ -36,7 +36,7 @@ z_stats_t *z_stats_make() {
void on_sample(const z_sample_t *sample, void *context) {
z_stats_t *stats = (z_stats_t *)context;
if (stats->count == 0) {
stats->start = zp_clock_now();
stats->start = z_clock_now();
if (!stats->started) {
stats->first_start = stats->start;
stats->started = true;
Expand All @@ -46,14 +46,14 @@ void on_sample(const z_sample_t *sample, void *context) {
stats->count++;
} else {
stats->finished_rounds++;
printf("%f msg/s\n", 1000.0 * N / zp_clock_elapsed_ms(&stats->start));
printf("%f msg/s\n", 1000.0 * N / z_clock_elapsed_ms(&stats->start));
stats->count = 0;
}
}
void drop_stats(void *context) {
const z_stats_t *stats = (z_stats_t *)context;
const unsigned long sent_messages = N * stats->finished_rounds + stats->count;
double elapsed_s = zp_clock_elapsed_s(&stats->first_start);
double elapsed_s = z_clock_elapsed_s(&stats->first_start);
printf("Stats being dropped after unsubscribing: sent %ld messages over %f seconds (%f msg/s)\n", sent_messages,
elapsed_s, (double)sent_messages / elapsed_s);
free(context);
Expand Down
65 changes: 26 additions & 39 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ typedef struct z_owned_bytes_map_t {
uint64_t _0[2];
size_t _1[4];
} z_owned_bytes_map_t;
/**
* Clock
* Uses monotonic clock
*/
typedef struct z_clock_t {
double t;
} z_clock_t;
/**
* Represents a Zenoh ID.
*
Expand Down Expand Up @@ -812,6 +819,13 @@ typedef struct z_task_t {
typedef struct z_task_attr_t {
size_t _0;
} z_task_attr_t;
/**
* Time
* Uses system clock
*/
typedef struct z_time_t {
double t;
} z_time_t;
/**
* The options for `zc_liveliness_declare_token`
*/
Expand Down Expand Up @@ -981,30 +995,6 @@ typedef struct ze_querying_subscriber_options_t {
typedef struct ze_querying_subscriber_t {
const struct ze_owned_querying_subscriber_t *_0;
} ze_querying_subscriber_t;
/**
* Condvar
*
*/
typedef struct z_condvar_t {
size_t _0;
} z_condvar_t;
/**
* Mutex
*
*/
typedef struct z_mutex_t {
size_t _0;
} z_mutex_t;
/**
* Task
*
*/
typedef struct z_task_t {
size_t _0;
} z_task_t;
typedef struct z_task_attr_t {
size_t _0;
} z_task_attr_t;
ZENOHC_API extern const unsigned int Z_ROUTER;
ZENOHC_API extern const unsigned int Z_PEER;
ZENOHC_API extern const unsigned int Z_CLIENT;
Expand Down Expand Up @@ -1147,6 +1137,10 @@ ZENOHC_API struct z_bytes_t z_bytes_null(void);
* Constructs a `len` bytes long view starting at `start`.
*/
ZENOHC_API struct z_bytes_t z_bytes_wrap(const uint8_t *start, size_t len);
ZENOHC_API uint64_t z_clock_elapsed_ms(const struct z_clock_t *time);
ZENOHC_API uint64_t z_clock_elapsed_s(const struct z_clock_t *time);
ZENOHC_API uint64_t z_clock_elapsed_us(const struct z_clock_t *time);
ZENOHC_API struct z_clock_t z_clock_now(void);
/**
* Closes a zenoh session. This drops and invalidates `session` for double-drop safety.
*
Expand Down Expand Up @@ -2005,6 +1999,9 @@ struct z_session_t z_session_loan(const struct z_owned_session_t *s);
* Constructs a null safe-to-drop value of 'z_owned_session_t' type
*/
ZENOHC_API struct z_owned_session_t z_session_null(void);
ZENOHC_API int8_t z_sleep_ms(size_t time);
ZENOHC_API int8_t z_sleep_s(size_t time);
ZENOHC_API int8_t z_sleep_us(size_t time);
/**
* Returns ``true`` if `strs` is valid.
*/
Expand Down Expand Up @@ -2067,6 +2064,11 @@ int8_t z_task_init(struct z_task_t *task,
void (*fun)(void *arg),
void *arg);
ZENOHC_API int8_t z_task_join(struct z_task_t *task);
ZENOHC_API uint64_t z_time_elapsed_ms(const struct z_time_t *time);
ZENOHC_API uint64_t z_time_elapsed_s(const struct z_time_t *time);
ZENOHC_API uint64_t z_time_elapsed_us(const struct z_time_t *time);
ZENOHC_API struct z_time_t z_time_now(void);
ZENOHC_API const char *z_time_now_as_str(const char *buf, size_t len);
/**
* Returns ``true`` if `ts` is a valid timestamp
*/
Expand Down Expand Up @@ -2589,18 +2591,3 @@ int8_t ze_undeclare_publication_cache(struct ze_owned_publication_cache_t *pub_c
*/
ZENOHC_API
int8_t ze_undeclare_querying_subscriber(struct ze_owned_querying_subscriber_t *sub);
ZENOHC_API int8_t z_condvar_free(struct z_condvar_t *cv);
ZENOHC_API int8_t z_condvar_init(struct z_condvar_t *cv);
ZENOHC_API int8_t z_condvar_signal(struct z_condvar_t *cv);
ZENOHC_API int8_t z_condvar_wait(struct z_condvar_t *cv, struct zp_mutex_t *m);
ZENOHC_API int8_t z_mutex_free(struct z_mutex_t *m);
ZENOHC_API int8_t z_mutex_init(struct z_mutex_t *m);
ZENOHC_API int8_t z_mutex_lock(struct z_mutex_t *m);
ZENOHC_API int8_t z_mutex_try_lock(struct z_mutex_t *m);
ZENOHC_API int8_t z_mutex_unlock(struct z_mutex_t *m);
ZENOHC_API
int8_t z_task_init(struct z_task_t *task,
const struct z_task_attr_t *_attr,
void (*fun)(void *arg),
void *arg);
ZENOHC_API int8_t zp_task_join(struct z_task_t *task);
34 changes: 17 additions & 17 deletions src/platform/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,53 @@ lazy_static! {
/// Uses monotonic clock
#[repr(C)]
#[derive(Clone, Copy)]
pub struct zp_clock_t {
pub struct z_clock_t {
t: f64,
}

#[no_mangle]
pub extern "C" fn zp_clock_now() -> zp_clock_t {
zp_clock_t {
pub extern "C" fn z_clock_now() -> z_clock_t {
z_clock_t {
t: CLOCK_BASE.elapsed().as_secs_f64(),
}
}
#[allow(clippy::missing_safety_doc)]
unsafe fn get_elapsed_seconds(time: *const zp_clock_t) -> f64 {
unsafe fn get_elapsed_seconds(time: *const z_clock_t) -> f64 {
if time.is_null() {
return 0.0;
}
zp_clock_now().t - (*time).t
z_clock_now().t - (*time).t
}

#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn zp_clock_elapsed_s(time: *const zp_clock_t) -> u64 {
pub unsafe extern "C" fn z_clock_elapsed_s(time: *const z_clock_t) -> u64 {
get_elapsed_seconds(time) as u64
}

#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn zp_clock_elapsed_ms(time: *const zp_clock_t) -> u64 {
pub unsafe extern "C" fn z_clock_elapsed_ms(time: *const z_clock_t) -> u64 {
(get_elapsed_seconds(time) * 1000.0) as u64
}

#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn zp_clock_elapsed_us(time: *const zp_clock_t) -> u64 {
pub unsafe extern "C" fn z_clock_elapsed_us(time: *const z_clock_t) -> u64 {
(get_elapsed_seconds(time) * 1000000.0) as u64
}

/// Time
/// Uses system clock
#[repr(C)]
#[derive(Clone, Copy)]
pub struct zp_time_t {
pub struct z_time_t {
t: f64,
}

#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn zp_time_now_as_str(buf: *const c_char, len: usize) -> *const c_char {
pub unsafe extern "C" fn z_time_now_as_str(buf: *const c_char, len: usize) -> *const c_char {
if len == 0 {
return buf;
}
Expand All @@ -78,36 +78,36 @@ pub unsafe extern "C" fn zp_time_now_as_str(buf: *const c_char, len: usize) -> *
}

#[no_mangle]
pub extern "C" fn zp_time_now() -> zp_time_t {
zp_time_t {
pub extern "C" fn z_time_now() -> z_time_t {
z_time_t {
t: SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or(Duration::new(0, 0))
.as_secs_f64(),
}
}
#[allow(clippy::missing_safety_doc)]
unsafe fn get_elapsed_seconds_system_clock(time: *const zp_time_t) -> f64 {
unsafe fn get_elapsed_seconds_system_clock(time: *const z_time_t) -> f64 {
if time.is_null() {
return 0.0;
}
0.0f64.max(zp_time_now().t - (*time).t)
0.0f64.max(z_time_now().t - (*time).t)
}

#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn zp_time_elapsed_s(time: *const zp_time_t) -> u64 {
pub unsafe extern "C" fn z_time_elapsed_s(time: *const z_time_t) -> u64 {
get_elapsed_seconds_system_clock(time) as u64
}

#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn zp_time_elapsed_ms(time: *const zp_time_t) -> u64 {
pub unsafe extern "C" fn z_time_elapsed_ms(time: *const z_time_t) -> u64 {
(get_elapsed_seconds_system_clock(time) * 1000.0) as u64
}

#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn zp_time_elapsed_us(time: *const zp_time_t) -> u64 {
pub unsafe extern "C" fn z_time_elapsed_us(time: *const z_time_t) -> u64 {
(get_elapsed_seconds_system_clock(time) * 1000000.0) as u64
}
Loading

0 comments on commit a229066

Please sign in to comment.