Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965166AbcJGQrl (ORCPT ); Fri, 7 Oct 2016 12:47:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53604 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965031AbcJGQrU (ORCPT ); Fri, 7 Oct 2016 12:47:20 -0400 From: Luiz Capitulino To: rostedt@goodmis.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/3] cpu.h: use standard types instead of glib's Date: Fri, 7 Oct 2016 12:47:09 -0400 Message-Id: <1475858831-32687-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1475858831-32687-1-git-send-email-lcapitulino@redhat.com> References: <1475858831-32687-1-git-send-email-lcapitulino@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 07 Oct 2016 16:47:20 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3124 Lines: 125 Future commits will introduce standard C code that wants to use cpu.h. Let's convert cpu.h to standard types. I'm choosing not to change the gui code that uses cpu.h though. I think that in all platforms where glib is supported, guint64 should always be uint64_t and guint should always be unsigned int. Signed-off-by: Luiz Capitulino --- cpu.h | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/cpu.h b/cpu.h index 05c7f17..fc0b3c4 100644 --- a/cpu.h +++ b/cpu.h @@ -20,45 +20,48 @@ #ifndef _CPU_H #define _CPU_H -static inline int cpu_isset(guint64 *cpu_mask, gint cpu) +#include +#include + +static inline int cpu_isset(uint64_t *cpu_mask, int cpu) { - guint64 mask; + uint64_t mask; mask = *(cpu_mask + (cpu >> 6)); return mask & (1ULL << (cpu & ((1ULL << 6) - 1))); } -static inline gboolean cpu_allset(guint64 *cpu_mask, gint max_cpus) +static inline bool cpu_allset(uint64_t *cpu_mask, int max_cpus) { - gint cpu; + int cpu; for (cpu = 0; cpu < max_cpus; cpu++) { if (!cpu_isset(cpu_mask, cpu)) - return FALSE; + return false; } - return TRUE; + return true; } -static inline void cpu_set(guint64 *cpu_mask, gint cpu) +static inline void cpu_set(uint64_t *cpu_mask, int cpu) { - guint64 *mask; + uint64_t *mask; mask = cpu_mask + (cpu >> 6); *mask |= (1ULL << (cpu & ((1ULL << 6) - 1))); } -static inline void cpu_clear(guint64 *cpu_mask, gint cpu) +static inline void cpu_clear(uint64_t *cpu_mask, int cpu) { - guint64 *mask; + uint64_t *mask; mask = cpu_mask + (cpu >> 6); *mask &= ~(1ULL << (cpu & ((1ULL << 6) - 1))); } -static inline void set_cpus(guint64 *cpu_mask, gint cpus) +static inline void set_cpus(uint64_t *cpu_mask, int cpus) { - gint idx; + int idx; for (idx = 0; idx < (cpus >> 6); idx++) { *(cpu_mask + idx) = -1ULL; @@ -67,22 +70,22 @@ static inline void set_cpus(guint64 *cpu_mask, gint cpus) *(cpu_mask) = (1ULL << (cpus & ((1ULL << 6) - 1))) - 1; } -static inline gboolean cpus_equal(guint64 *a_mask, guint64 *b_mask, - gint cpus) +static inline bool cpus_equal(uint64_t *a_mask, uint64_t *b_mask, + int cpus) { - gint idx; + int idx; for (idx = 0; idx < (cpus >> 6) + 1; idx++) { if (*(a_mask + idx) != *(b_mask + idx)) - return FALSE; + return false; } - return TRUE; + return true; } /* Hamming weight */ -static inline guint hweight(guint mask) +static inline unsigned int hweight(unsigned int mask) { - guint64 w = mask; + uint64_t w = mask; w -= (w >> 1) & 0x5555555555555555ul; w = (w & 0x3333333333333333ul) + ((w >> 2) & 0x3333333333333333ul); @@ -90,10 +93,10 @@ static inline guint hweight(guint mask) return (w * 0x0101010101010101ul) >> 56; } -static inline guint cpu_weight(guint64 *cpu_mask, guint cpus) +static inline unsigned int cpu_weight(uint64_t *cpu_mask, unsigned int cpus) { - guint weight = 0; - gint idx; + unsigned int weight = 0; + int idx; for (idx = 0; idx < (cpus >> 6) + 1; idx++) weight += hweight(*(cpu_mask + idx)); -- 2.5.5