Skip to content

Commit

Permalink
Add atomic_iperf_size_t for atomic (thread-safe) operations
Browse files Browse the repository at this point in the history
  • Loading branch information
swlars authored and bmah888 committed Nov 8, 2023
1 parent 0755cc4 commit 30ce2d5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
25 changes: 14 additions & 11 deletions src/iperf.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,17 @@
#endif // HAVE_SSL

#include <pthread.h>
#include <stdatomic.h>

#if !defined(__IPERF_API_H)
typedef uint64_t iperf_size_t;
//typedef uint64_t iperf_size_t;
typedef uint_fast64_t iperf_size_t;
typedef atomic_uint_fast64_t atomic_iperf_size_t;
#endif // __IPERF_API_H

struct iperf_interval_results
{
iperf_size_t bytes_transferred; /* bytes transferred in this interval */
atomic_iperf_size_t bytes_transferred; /* bytes transferred in this interval */
struct iperf_time interval_start_time;
struct iperf_time interval_end_time;
float interval_duration;
Expand Down Expand Up @@ -115,11 +118,11 @@ struct iperf_interval_results

struct iperf_stream_result
{
iperf_size_t bytes_received;
iperf_size_t bytes_sent;
iperf_size_t bytes_received_this_interval;
iperf_size_t bytes_sent_this_interval;
iperf_size_t bytes_sent_omit;
atomic_iperf_size_t bytes_received;
atomic_iperf_size_t bytes_sent;
atomic_iperf_size_t bytes_received_this_interval;
atomic_iperf_size_t bytes_sent_this_interval;
atomic_iperf_size_t bytes_sent_omit;
long stream_prev_total_retrans;
long stream_retrans;
long stream_max_rtt;
Expand Down Expand Up @@ -359,11 +362,11 @@ struct iperf_test

int num_streams; /* total streams in the test (-P) */

iperf_size_t bytes_sent;
iperf_size_t blocks_sent;
atomic_iperf_size_t bytes_sent;
atomic_iperf_size_t blocks_sent;

iperf_size_t bytes_received;
iperf_size_t blocks_received;
atomic_iperf_size_t bytes_received;
atomic_iperf_size_t blocks_received;

iperf_size_t bitrate_limit_stats_count; /* Number of stats periods accumulated for server's total bitrate average */
iperf_size_t *bitrate_limit_intervals_traffic_bytes; /* Pointer to a cyclic array that includes the last interval's bytes transferred */
Expand Down
2 changes: 1 addition & 1 deletion src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,7 @@ iperf_check_total_rate(struct iperf_test *test, iperf_size_t last_interval_bytes
return;

/* Calculating total bytes traffic to be averaged */
for (total_bytes = 0, i = 0; i < test->settings->bitrate_limit_stats_per_interval; i++) {
for (i = 0, total_bytes = 0; i < test->settings->bitrate_limit_stats_per_interval; i++) {
total_bytes += test->bitrate_limit_intervals_traffic_bytes[i];
}

Expand Down
4 changes: 3 additions & 1 deletion src/iperf_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
extern "C" { /* open extern "C" */
#endif

#include <stdatomic.h>

struct iperf_test;
struct iperf_stream_result;
Expand All @@ -46,7 +47,8 @@ struct iperf_stream;
struct iperf_time;

#if !defined(__IPERF_H)
typedef uint64_t iperf_size_t;
typedef uint_fast64_t iperf_size_t;
typedef atomic_uint_fast64_t atomic_iperf_size_t;
#endif // __IPERF_H

/* default settings */
Expand Down

0 comments on commit 30ce2d5

Please sign in to comment.