lkml.org 
[lkml]   [2018]   [May]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [tip:locking/core] locking/atomics: Simplify the op definitions in atomic.h some more
On Tue, May 15, 2018 at 01:41:44PM +0200, Peter Zijlstra wrote:
> #!/bin/bash
>
> gen_proto() {
> local cnt=0;
>
> proto=$1; shift;
> ret=$1; shift;
> pfx=$1; shift;
> sfx=$1; shift;
>
> echo -n "${ret} ";
>
> name=${proto%(*};
> echo -n "${pfx}${name}${sfx}("
>
> args=${proto#*\(};
> for arg in ${args//[,)]/ };
> do
> if [ $cnt -gt 0 ]
> then
> echo -n ", ";
> fi
> let cnt++;
> echo -n "${TYPES[$arg]} ${arg}"
> done
> echo ");"
> }
>
> gen_proto_order() {
> gen_proto $1 $2 $3 $4
> gen_proto $1 $2 $3 $4_acquire
> gen_proto $1 $2 $3 $4_release
> gen_proto $1 $2 $3 $4_relaxed
> }
>
> gen_void_protos() {
> grep -v -e "^$" -e "^#" atomic.tbl | while read proto meta;
> do
> gen_proto ${proto} "void" ${TYPES[pfx]} ""
> done
> }
>
> gen_return_protos() {
> grep -v -e "^$" -e "^#" atomic.tbl | while read proto meta;
> do
> if [[ $meta =~ "R" ]]; then
> gen_proto_order ${proto} ${TYPES[i]} ${TYPES[pfx]} "_return"
> fi
> done
> }
>
> gen_fetch_protos() {
> grep -v -e "^$" -e "^#" atomic.tbl | while read proto meta;
> do
> if [[ $meta =~ "F" ]]; then
> gen_proto_order ${proto} ${TYPES[i]} "${TYPES[pfx]}fetch_" ""
> fi
> done
> }
>
> gen_exchange_protos() {
> grep -v -e "^$" -e "^#" atomic.tbl | while read proto meta;
> do
> if [[ $meta =~ "X" ]]; then

ret=${TYPES[i]};
if [[ $meta =~ "B" ]]; then
ret="bool"
fi
gen_proto_order ${proto} ${ret} ${TYPES[pfx]} ""

> fi
> done
> }
>
> gen_protos() {
> gen_void_protos
> gen_return_protos
> gen_fetch_protos
> gen_exchange_protos
> }
>
> declare -A TYPES=( [pfx]="atomic_" [v]="atomic_t *" [i]="int" [j]="int" [I]="int *" )
>
> gen_protos
>
> declare -A TYPES=( [pfx]="atomic64_" [v]="atomic64_t *" [i]="s64" [j]="s64" [I]="s64 *" )
>
> gen_protos
>
> declare -A TYPES=( [pfx]="atomic_long_" [v]="atomic_long_t *" [i]="long" [j]="long" [I]="long *" )
>
> gen_protos
>
>

\
 
 \ /
  Last update: 2018-05-15 14:13    [W:0.135 / U:5.652 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site