Skip to content

Commit

Permalink
introduce container_.of.h
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Pronin <Pronin.D@raidix.com>
  • Loading branch information
dpronin committed Aug 1, 2023
1 parent dc7988b commit 16bf132
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
26 changes: 26 additions & 0 deletions container_of.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef _CONTAINER_OF_H
#define _CONTAINER_OF_H

#ifdef __cplusplus

#include <cstdlib>
#include <cstddef>

extern "C" {

#define container_of(ptr, type, member) ({ \
auto const *__mptr = static_cast<__typeof__( ((type *)0)->member ) const*>(ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
}

#else // __cplusplus

#include <stdlib.h>
#include <stddef.h>

#define container_of(ptr, type, member) ({ \
const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif

#endif // _CONTAINER_OF_H
11 changes: 2 additions & 9 deletions flist.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@
#include <stdlib.h>
#include <stddef.h>

#ifdef __cplusplus
#include "container_of.h"

#ifdef __cplusplus
extern "C" {

#define container_of(ptr, type, member) ({ \
auto const *__mptr = static_cast<__typeof__( ((type *)0)->member ) const*>(ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#else
#define container_of(ptr, type, member) ({ \
const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif

/*
Expand Down
16 changes: 8 additions & 8 deletions options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2473,8 +2473,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
},
{
.name = "randrepeat",
.alias = "allrandrepeat",
.lname = "Random repeatable",
.alias = "allrandrepeat",
.type = FIO_OPT_BOOL,
.off1 = offsetof(struct thread_options, rand_repeatable),
.help = "Use repeatable random IO pattern",
Expand Down Expand Up @@ -3694,8 +3694,6 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
.off1 = offsetof(struct thread_options, fdp_pli_select),
.help = "Select which FDP placement ID to use next",
.def = "roundrobin",
.category = FIO_OPT_C_IO,
.group = FIO_OPT_G_INVALID,
.posval = {
{ .ival = "random",
.oval = FIO_FDP_RANDOM,
Expand All @@ -3706,6 +3704,8 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
.help = "Round robin select Placement IDs",
},
},
.category = FIO_OPT_C_IO,
.group = FIO_OPT_G_INVALID,
},
{
.name = "fdp_pli",
Expand Down Expand Up @@ -3819,10 +3819,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
.lname = "I/O nice priority hint",
.type = FIO_OPT_INT,
.off1 = offsetof(struct thread_options, ioprio_hint),
.help = "Set job IO priority hint",
.minval = IOPRIO_MIN_PRIO_HINT,
.maxval = IOPRIO_MAX_PRIO_HINT,
.minval = IOPRIO_MIN_PRIO_HINT,
.interval = 1,
.help = "Set job IO priority hint",
.category = FIO_OPT_C_GENERAL,
.group = FIO_OPT_G_CRED,
},
Expand Down Expand Up @@ -5276,15 +5276,15 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
.name = "steadystate_check_interval",
.lname = "Steady state check interval",
.alias = "ss_interval",
.parent = "steadystate",
.type = FIO_OPT_STR_VAL_TIME,
.off1 = offsetof(struct thread_options, ss_check_interval),
.help = "Polling interval for the steady state check (too low means steadystate will not converge)",
.def = "1",
.is_seconds = 1,
.is_time = 1,
.parent = "steadystate",
.category = FIO_OPT_C_GENERAL,
.group = FIO_OPT_G_RUNTIME,
.is_seconds = 1,
.is_time = 1,
},
{
.name = NULL,
Expand Down

0 comments on commit 16bf132

Please sign in to comment.