Re: [PATCH v3 1/2] alloc.c: remove the alloc_raw_commit_node() function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jul 11, 2014 at 12:58:31AM +0100, Ramsay Jones wrote:

>  #define DEFINE_ALLOCATOR(name, type)				\
> -static unsigned int name##_allocs;				\
> +static struct alloc_state name##_state;				\
>  void *alloc_##name##_node(void)					\
>  {								\
> -	static int nr;						\
> -	static type *block;					\
> -	void *ret;						\
> -								\
> -	if (!nr) {						\
> -		nr = BLOCKING;					\
> -		block = xmalloc(BLOCKING * sizeof(type));	\
> -	}							\
> -	nr--;							\
> -	name##_allocs++;					\
> -	ret = block++;						\
> -	memset(ret, 0, sizeof(type));				\
> -	return ret;						\
> +	return alloc_node(&name##_state, sizeof(type));		\
>  }

Yay. Not only does this solve the problem, but it gets rid of nasty
multi-line macro. In fact, I kind of wonder if we should just do away
with the macro entirely, and write out:

  static struct alloc_state blob_state;
  void alloc_blob_node(void)
  {
	return alloc_node(&blob_state, sizeof(struct blob));
  }

It's more lines, but it is probably less obfuscated to a reader.

-Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]