These functions provide some helper for a pseudo Copy On Write mechanism. More...

Macros

#define EINA_COW_WRITE_BEGIN(Cow, Read, Write_Type, Write)
 This macro setup a writable pointer from a const one. More...
 
#define EINA_COW_WRITE_END(Cow, Read, Write)
 This macro close the writable pointer. More...
 

Typedefs

typedef struct _Eina_Cow Eina_Cow
 Type for Eina_Cow pool.
 
typedef void Eina_Cow_Data
 Type of the returned pointer to simplify some reading.
 

Functions

Eina_Coweina_cow_add (const char *name, unsigned int struct_size, unsigned int step, const void *default_value, Eina_Bool gc)
 Instantiate a new Eina_Cow pool. More...
 
void eina_cow_del (Eina_Cow *cow)
 Destroy an Eina_Cow pool and all the allocated memory. More...
 
const Eina_Cow_Dataeina_cow_alloc (Eina_Cow *cow)
 Return an initialized pointer from the pool. More...
 
void eina_cow_free (Eina_Cow *cow, const Eina_Cow_Data **data)
 Free a pointer from the pool. More...
 
void * eina_cow_write (Eina_Cow *cow, const Eina_Cow_Data *const *src)
 Get a writable pointer from a const pointer. More...
 
void eina_cow_done (Eina_Cow *cow, const Eina_Cow_Data *const *dst, const void *data, Eina_Bool needed_gc)
 Set back a pointer into read only. More...
 
void eina_cow_memcpy (Eina_Cow *cow, const Eina_Cow_Data *const *dst, const Eina_Cow_Data *src)
 Make the destination contain the same thing as the source pointer. More...
 
Eina_Bool eina_cow_gc (Eina_Cow *cow)
 Try to find entries that have the same content and update them. More...
 

Detailed Description

These functions provide some helper for a pseudo Copy On Write mechanism.

Eina_Cow will return const memory pointer to some default value that you will be able to change only by requesting a writable pointer. Later on a garbage collector can come online and try to merge back some of those pointer.

Since
1.8.0

Macro Definition Documentation

#define EINA_COW_WRITE_BEGIN (   Cow,
  Read,
  Write_Type,
  Write 
)
Value:
do \
{ \
Write_Type *Write; \
\
Write = eina_cow_write(Cow, ((const Eina_Cow_Data**)&(Read)));
void Eina_Cow_Data
Type of the returned pointer to simplify some reading.
Definition: eina_cow.h:52
void * eina_cow_write(Eina_Cow *cow, const Eina_Cow_Data *const *src)
Get a writable pointer from a const pointer.
Definition: eina_cow.c:453

This macro setup a writable pointer from a const one.

Parameters
CowThe Eina_Cow where the const pointer come from.
ReadThe const pointer to get a writable handler from.
Write_TypeThe type of the pointer you want to write to.
WriteThe name of the variable where to put the writeable pointer to.
Since
1.8.0

Be careful this macro opens a C scope that is expected to be closed by EINA_COW_WRITE_END().

Referenced by evas_image_max_size_get(), evas_map_util_clockwise_get(), evas_object_image_animated_frame_set(), evas_object_image_memfile_set(), evas_object_image_reload(), evas_object_image_size_set(), evas_object_image_source_events_set(), evas_object_image_source_visible_set(), evas_object_map_enable_set(), evas_object_map_set(), evas_obscured_clear(), evas_render_dump(), and evas_render_idle_flush().

#define EINA_COW_WRITE_END (   Cow,
  Read,
  Write 
)
Value:
eina_cow_done(Cow, ((const Eina_Cow_Data**)&(Read)), Write, \
} \
while (0);
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:317
void Eina_Cow_Data
Type of the returned pointer to simplify some reading.
Definition: eina_cow.h:52
void eina_cow_done(Eina_Cow *cow, const Eina_Cow_Data *const *dst, const void *data, Eina_Bool needed_gc)
Set back a pointer into read only.
Definition: eina_cow.c:534

This macro close the writable pointer.

Parameters
CowThe Eina_Cow where the const pointer come from.
ReadThe const pointer to get a writable handler from.
WriteThe name of the variable where to put the writeable pointer to.
Since
1.8.0

Be careful this macro close the scope opened by EINA_COW_WRITE_BEGIN().

Referenced by evas_image_max_size_get(), evas_map_util_clockwise_get(), evas_object_image_animated_frame_set(), evas_object_image_memfile_set(), evas_object_image_reload(), evas_object_image_size_set(), evas_object_image_source_events_set(), evas_object_image_source_visible_set(), evas_object_map_enable_set(), evas_object_map_set(), evas_obscured_clear(), evas_render_dump(), and evas_render_idle_flush().

Function Documentation

Eina_Cow* eina_cow_add ( const char *  name,
unsigned int  struct_size,
unsigned int  step,
const void *  default_value,
Eina_Bool  gc 
)

Instantiate a new Eina_Cow pool.

Parameters
nameThe name of this pool, used for debug.
struct_sizeThe size of the object from this pool.
stepHow many objects to allocate when the pool gets empty.
default_valueThe default value returned by this pool.
gcIs it possible to run garbage collection on this pool.
Returns
a valid new Eina_Cow or NULL on error.

References EAPI, eina_hash_new(), eina_hash_pointer_new(), and EINA_MAGIC_SET.

Referenced by edje_init().

void eina_cow_del ( Eina_Cow cow)

Destroy an Eina_Cow pool and all the allocated memory.

Parameters
cowThe pool to destroy

References EAPI, and eina_hash_free().

Referenced by edje_init(), and evas_shutdown().

const Eina_Cow_Data* eina_cow_alloc ( Eina_Cow cow)

Return an initialized pointer from the pool.

Parameters
cowThe pool to take things from.

References EAPI.

Referenced by edje_file_data_get(), and edje_object_animation_get().

void eina_cow_free ( Eina_Cow cow,
const Eina_Cow_Data **  data 
)

Free a pointer from the pool.

Parameters
cowThe pool to gave back memory to.
dataThe data to give back.
Note
To simplify the caller code *data will point to the default read only state after the call to this function.

References EAPI, EINA_MAGIC_NONE, and EINA_MAGIC_SET.

Referenced by edje_file_data_get(), edje_object_animation_get(), eina_cow_memcpy(), and evas_image_max_size_get().

void* eina_cow_write ( Eina_Cow cow,
const Eina_Cow_Data *const *  src 
)

Get a writable pointer from a const pointer.

Parameters
cowThe pool the pointer come from.
srcThe pointer you want to write to.

NOTE: this function is not thread safe, be careful.

References EAPI, EINA_FALSE, EINA_MAGIC_SET, and EINA_TRUE.

void eina_cow_done ( Eina_Cow cow,
const Eina_Cow_Data *const *  dst,
const void *  data,
Eina_Bool  needed_gc 
)

Set back a pointer into read only.

Parameters
cowThe pool the pointer come from.
dstThe read only version of the pointer.
dataThe pointer to which data was written to.

NOTE: this function is not thread safe, be careful.

References EAPI, and EINA_FALSE.

void eina_cow_memcpy ( Eina_Cow cow,
const Eina_Cow_Data *const *  dst,
const Eina_Cow_Data src 
)

Make the destination contain the same thing as the source pointer.

Parameters
cowThe pool the pointers come from.
dstThe destination to update.
srcThe source of information to copy.

References EAPI, and eina_cow_free().

Referenced by evas_image_max_size_get().

Eina_Bool eina_cow_gc ( Eina_Cow cow)

Try to find entries that have the same content and update them.

Parameters
cowThe cow to try to compact.
Returns
EINA_TRUE if something was compacted, EINA_FALSE if nothing was.

There is no guaranty in the time it will require, but should remain low. It does run a hash function on all possible common structures trying to find the one that match and merge them into one pointer.

References EINA_FALSE, eina_hash_iterator_data_new(), eina_hash_population(), eina_iterator_free(), eina_iterator_next(), and EINA_TRUE.