* rseq_mempool_attr_set_init: Set pool attribute structure memory init functions.
*
* The @init_func callback used to initialized memory after allocation
- * for the pool. The @init_func callback must return 0 on success, -1 on
- * error with errno set. If @init_func returns failure, the allocation
- * of the pool memory fails, which either causes the pool creation to
- * fail or memory allocation to fail (for extensible memory pools).
+ * for the pool. The @cpu argument of @init_func, if >= 0, is the cpu to
+ * which belongs the range starting at @addr of length @len. If cpu is
+ * -1, it means the range belongs to a global pool. The @init_func
+ * callback must return 0 on success, -1 on error with errno set. If
+ * @init_func returns failure, the allocation of the pool memory fails,
+ * which either causes the pool creation to fail or memory allocation to
+ * fail (for extensible memory pools).
*
* The @init_priv argument is a private data pointer passed to the
* @init_func callback.
goto error_alloc;
}
if (pool->attr.init_set) {
- int cpu;
-
- for (cpu = 0; cpu < pool->attr.max_nr_cpus; cpu++) {
+ switch (pool->attr.type) {
+ case MEMPOOL_TYPE_GLOBAL:
if (pool->attr.init_func(pool->attr.init_priv,
- base + (pool->attr.stride * cpu),
- pool->attr.stride, cpu)) {
+ base, pool->attr.stride, -1)) {
goto error_alloc;
}
+ break;
+ case MEMPOOL_TYPE_PERCPU:
+ {
+ int cpu;
+ for (cpu = 0; cpu < pool->attr.max_nr_cpus; cpu++) {
+ if (pool->attr.init_func(pool->attr.init_priv,
+ base + (pool->attr.stride * cpu),
+ pool->attr.stride, cpu)) {
+ goto error_alloc;
+ }
+ }
+ break;
+ }
+ default:
+ abort();
}
}
return range;