On Fri, Apr 20, 2018 at 12:14:27PM +0200, Anders Selhammer wrote:
> @@ -81,7 +81,7 @@ int dscmp2(struct dataset *a, struct dataset *b)
>       return 0;
>  }
>  
> -int dscmp_ieee1588(struct dataset *a, struct dataset *b)
> +static int dscmp(struct dataset *a, struct dataset *b, enum bmca_type type)

Let's think about where this is headed...

> @@ -96,15 +96,18 @@ int dscmp_ieee1588(struct dataset *a, struct dataset *b)
>       }
>  
>       diff = memcmp(&a->identity, &b->identity, sizeof(a->identity));
> -     if (!diff) {
> -             return dscmp2(a, b);
> -     }
>  
> -     if (a->priority1 < b->priority1) {
> -             return A_BETTER;
> -     }
> -     if (a->priority1 > b->priority1) {
> -             return B_BETTER;
> +     if (IEEE1588_BMCA == type) {
> +             if (!diff) {
> +                     return dscmp2(a, b);
> +             }
> +
> +             if (a->priority1 < b->priority1) {
> +                     return A_BETTER;
> +             }
> +             if (a->priority1 > b->priority1) {
> +                     return B_BETTER;
> +             }

How will the code look after the tenth different BMCA is published?

        if (type == AAA || type == BBB) {
                ...
        } else if (type != FFF && type > DDD) {
                ...
        } else if (...) {
                ...
        }

We want the code to match the flow charts in the published standards.
That is why I have placed the alternate function into its own C
function.  Also, that is why it makes sense to make an exception to
the coding style and dispense with the extra braces here.

Thanks,
Richard

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to