efl/src/lib/eo/eo_ptr_indirection.h

167 lines
4.3 KiB
C
Raw Normal View History

#ifndef EO_PTR_INDIRECTION_H
#define EO_PTR_INDIRECTION_H
#include "Eo.h"
#include "eo_private.h"
/* Macro used to obtain the object pointer and return if fails. */
#ifdef HAVE_EO_ID
void _eo_pointer_error(const char *msg);
#define _EO_POINTER_ERR(fmt, ptr) \
do { char buf[256]; sprintf(buf, fmt, ptr); _eo_pointer_error(buf); } while (0)
#define EO_OBJ_POINTER(obj_id, obj) \
_Eo_Object *obj; \
do { \
obj = _eo_obj_pointer_get((Eo_Id)obj_id); \
2016-08-26 12:01:52 -07:00
} while (0)
#define EO_OBJ_POINTER_RETURN_VAL(obj_id, obj, ret) \
_Eo_Object *obj; \
do { \
obj = _eo_obj_pointer_get((Eo_Id)obj_id); \
if (!obj) return (ret); \
2016-08-26 12:01:52 -07:00
} while (0)
#define EO_OBJ_POINTER_RETURN(obj_id, obj) \
_Eo_Object *obj; \
do { \
obj = _eo_obj_pointer_get((Eo_Id)obj_id); \
if (!obj) return; \
2016-08-26 12:01:52 -07:00
} while (0)
#define EO_OBJ_POINTER_GOTO(obj_id, obj, label) \
_Eo_Object *obj; \
do { \
obj = _eo_obj_pointer_get((Eo_Id)obj_id); \
if (!obj) goto label; \
} while (0)
#define EO_CLASS_POINTER(klass_id, klass) \
_Efl_Class *klass; \
do { \
klass = _eo_class_pointer_get(klass_id); \
} while (0)
#define EO_CLASS_POINTER_RETURN_VAL(klass_id, klass, ret) \
_Efl_Class *klass; \
do { \
klass = _eo_class_pointer_get(klass_id); \
if (!klass) { \
_EO_POINTER_ERR("Class (%p) is an invalid ref.", klass_id); \
return ret; \
} \
} while (0)
#define EO_CLASS_POINTER_RETURN(klass_id, klass) \
_Efl_Class *klass; \
do { \
klass = _eo_class_pointer_get(klass_id); \
if (!klass) { \
_EO_POINTER_ERR("Class (%p) is an invalid ref.", klass_id); \
return; \
} \
} while (0)
#define EO_CLASS_POINTER_GOTO(klass_id, klass, label) \
_Efl_Class *klass; \
do { \
klass = _eo_class_pointer_get(klass_id); \
if (!klass) goto label; \
} while (0)
#define EO_OBJ_DONE(obj_id) \
_eo_obj_pointer_done((Eo_Id)obj_id)
#else
#define EO_OBJ_POINTER(obj_id, obj) \
_Eo_Object *obj; \
do { \
obj = _eo_obj_pointer_get((Eo_Id)obj_id); \
if (obj && \
!EINA_MAGIC_CHECK((Eo_Header *) obj, EO_EINA_MAGIC)) { \
EINA_MAGIC_FAIL((Eo_Header *) obj, EO_EINA_MAGIC); \
} \
2016-08-26 12:01:52 -07:00
} while (0)
#define EO_OBJ_POINTER_RETURN_VAL(obj_id, obj, ret) \
_Eo_Object *obj; \
do { \
obj = _eo_obj_pointer_get((Eo_Id)obj_id); \
if (!obj) return (ret); \
EO_MAGIC_RETURN_VAL((Eo_Header *) obj, EO_EINA_MAGIC, ret); \
} while (0)
#define EO_OBJ_POINTER_RETURN(obj_id, obj) \
_Eo_Object *obj; \
do { \
obj = _eo_obj_pointer_get((Eo_Id)obj_id); \
if (!obj) return; \
EO_MAGIC_RETURN((Eo_Header *) obj, EO_EINA_MAGIC); \
} while (0)
#define EO_OBJ_POINTER_GOTO(obj_id, obj, label) \
_Eo_Object *obj; \
do { \
obj = _eo_obj_pointer_get((Eo_Id)obj_id); \
if (!obj || \
!EINA_MAGIC_CHECK((Eo_Header *) obj, EO_EINA_MAGIC)) goto label; \
} while (0)
#define EO_CLASS_POINTER(klass_id, klass) \
_Efl_Class *klass; \
do { \
klass = _eo_class_pointer_get(klass_id); \
if (klass && \
!EINA_MAGIC_CHECK((Eo_Header *) klas, EO_CLASS_EINA_MAGIC)) { \
EO_MAGIC_FAIL((Eo_Header *) klass, EO_CLASS_EINA_MAGIC); \
} \
} while (0)
#define EO_CLASS_POINTER_RETURN_VAL(klass_id, klass, ret) \
_Efl_Class *klass; \
do { \
klass = _eo_class_pointer_get(klass_id); \
if (!klass) return (ret); \
EO_MAGIC_RETURN_VAL((Eo_Header *) klass, EO_CLASS_EINA_MAGIC, ret); \
} while (0)
#define EO_CLASS_POINTER_RETURN(klass_id, klass) \
_Efl_Class *klass; \
do { \
klass = _eo_class_pointer_get(klass_id); \
if (!klass) return; \
EO_MAGIC_RETURN((Eo_Header *) klass, EO_CLASS_EINA_MAGIC); \
} while (0)
#define EO_CLASS_POINTER_GOTO(klass_id, klass, label) \
_Efl_Class *klass; \
do { \
klass = _eo_class_pointer_get(klass_id); \
if (!klass) goto label; \
if (klass && \
!EINA_MAGIC_CHECK((Eo_Header *) klas, EO_CLASS_EINA_MAGIC)) { \
} while (0)
#define EO_OBJ_DONE(obj_id)
#endif
#ifdef EFL_DEBUG
void _eo_print();
#endif
eo - make eo id table TLS private data for thread safety and speed This moved all the eoid tables, eoid lookup caches, generation count information ad eo_isa cache into a TLS segment of memory that is thread private. There is also a shared domain for EO objects that all threads can access, but it has an added cost of a lock. This means objects accessed outside the thread they were created in cannot be accessed by another thread unless they are adopted in temporarily, or create4d with the shared domain active at the time of creation. child objects will use their parent object domain if created with a parent object passed in. If you were accessing EO (EFL) objects across threads before then this will actually now cause your code to fail as it was invalid before to do this as no actual objects were threadsafe in EFL, so this will force things to "fail early". ecore_thread_main_loop_begin() and end() still work as this uses the eo domain adoption features to temporarily adopt a domain during this section and then return it when done. This returns speed back to eo brining the overhead in my tests of lookup for the elm genlist autobounce test in elementary from about 5-7% down to 2.5-2.6%. A steep drop. This does not mean everything is perfect. Still to do are: 1. Tests in the test suite 2. Some API's to help for sending objects from thread to thread 3. Make the eo call cache TLS data to make it also safe 4. Look at other locks in eo and probably move them to TLS data 5. Make eo resolve and call wrappers that call the real method func do recursive mutex wrapping of the given object IF it is a shared object to provide threadsafety transparently for shared objects (but adding some overhead as a result) 6. Test test est, and that is why this commit is going in now for wider testing 7. Decide how to make this work with sending IPC (between threads) 8. Deciding what makes an object sendable (a sendable property in base?) 9. Deciding what makes an object shareable (a sharable property in base?)
2016-09-07 01:53:33 -07:00
extern Eina_TLS _eo_table_data;
#include "eo_ptr_indirection.x"
eo - make eo id table TLS private data for thread safety and speed This moved all the eoid tables, eoid lookup caches, generation count information ad eo_isa cache into a TLS segment of memory that is thread private. There is also a shared domain for EO objects that all threads can access, but it has an added cost of a lock. This means objects accessed outside the thread they were created in cannot be accessed by another thread unless they are adopted in temporarily, or create4d with the shared domain active at the time of creation. child objects will use their parent object domain if created with a parent object passed in. If you were accessing EO (EFL) objects across threads before then this will actually now cause your code to fail as it was invalid before to do this as no actual objects were threadsafe in EFL, so this will force things to "fail early". ecore_thread_main_loop_begin() and end() still work as this uses the eo domain adoption features to temporarily adopt a domain during this section and then return it when done. This returns speed back to eo brining the overhead in my tests of lookup for the elm genlist autobounce test in elementary from about 5-7% down to 2.5-2.6%. A steep drop. This does not mean everything is perfect. Still to do are: 1. Tests in the test suite 2. Some API's to help for sending objects from thread to thread 3. Make the eo call cache TLS data to make it also safe 4. Look at other locks in eo and probably move them to TLS data 5. Make eo resolve and call wrappers that call the real method func do recursive mutex wrapping of the given object IF it is a shared object to provide threadsafety transparently for shared objects (but adding some overhead as a result) 6. Test test est, and that is why this commit is going in now for wider testing 7. Decide how to make this work with sending IPC (between threads) 8. Deciding what makes an object sendable (a sendable property in base?) 9. Deciding what makes an object shareable (a sharable property in base?)
2016-09-07 01:53:33 -07:00
extern Eo_Id_Data *_eo_table_data_shared;
extern Eo_Id_Table_Data *_eo_table_data_shared_data;
eo - make eo id table TLS private data for thread safety and speed This moved all the eoid tables, eoid lookup caches, generation count information ad eo_isa cache into a TLS segment of memory that is thread private. There is also a shared domain for EO objects that all threads can access, but it has an added cost of a lock. This means objects accessed outside the thread they were created in cannot be accessed by another thread unless they are adopted in temporarily, or create4d with the shared domain active at the time of creation. child objects will use their parent object domain if created with a parent object passed in. If you were accessing EO (EFL) objects across threads before then this will actually now cause your code to fail as it was invalid before to do this as no actual objects were threadsafe in EFL, so this will force things to "fail early". ecore_thread_main_loop_begin() and end() still work as this uses the eo domain adoption features to temporarily adopt a domain during this section and then return it when done. This returns speed back to eo brining the overhead in my tests of lookup for the elm genlist autobounce test in elementary from about 5-7% down to 2.5-2.6%. A steep drop. This does not mean everything is perfect. Still to do are: 1. Tests in the test suite 2. Some API's to help for sending objects from thread to thread 3. Make the eo call cache TLS data to make it also safe 4. Look at other locks in eo and probably move them to TLS data 5. Make eo resolve and call wrappers that call the real method func do recursive mutex wrapping of the given object IF it is a shared object to provide threadsafety transparently for shared objects (but adding some overhead as a result) 6. Test test est, and that is why this commit is going in now for wider testing 7. Decide how to make this work with sending IPC (between threads) 8. Deciding what makes an object sendable (a sendable property in base?) 9. Deciding what makes an object shareable (a sharable property in base?)
2016-09-07 01:53:33 -07:00
#endif