Commit 472c135e authored by Éric Thiébaut's avatar Éric Thiébaut
Browse files

New function tao_shared_array_fill

parent c652ddbb
......@@ -173,6 +173,38 @@ tao_shared_array* tao_shared_array_create(
return obj;
}
tao_shared_array* tao_shared_array_fill(
tao_shared_array* arr,
double val)
{
long n = tao_shared_array_get_length(arr);
void* ptr = tao_shared_array_get_data(arr);
if (n > 0 && ptr != NULL) {
#define FILL(T) \
do { \
T x = (T)val; \
T* a = (T*)ptr; \
for (long i = 0; i < n; ++i) { \
a[i] = x; \
} \
} while (false)
switch (arr->eltype) {
case TAO_INT8 : FILL(int8_t ); break;
case TAO_UINT8 : FILL(uint8_t ); break;
case TAO_INT16 : FILL(int16_t ); break;
case TAO_UINT16: FILL(uint16_t); break;
case TAO_INT32 : FILL(int32_t ); break;
case TAO_UINT32: FILL(uint32_t); break;
case TAO_INT64 : FILL(int64_t ); break;
case TAO_UINT64: FILL(uint64_t); break;
case TAO_FLOAT : FILL(float ); break;
case TAO_DOUBLE: FILL(double ); break;
}
#undef FILL
}
return arr;
}
// Generic shared object methods.
#define TYPE shared_array
#define MAGIC TAO_SHARED_ARRAY
......
......@@ -259,6 +259,21 @@ extern long tao_shared_array_get_dim(
extern void* tao_shared_array_get_data(
const tao_shared_array* arr);
/**
* Fill a shared with a given value.
*
* @param arr Pointer to a shared array attached to the address space of
* the caller.
*
* @param val Value.
*
* @return The argument @a arr. This function leaves the caller's last error
* unchanged.
*/
extern tao_shared_array* tao_shared_array_fill(
tao_shared_array* arr,
double val);
/**
* Get the serial number of a shared array.
*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment