efl/src/tests/eina
Gustavo Sverzut Barbieri d10a35628c eina: add Eina_Coro - coroutine support.
Coroutines are cooperative tasks, in the sense that the caller will
stop until the target function runs. The target function must either
yield control back to the caller (main thread), or exit. There is no
preemption of the two tasks, thus no special care needs to be taken
regarding shared data.

If the target coroutine yields control using eina_coro_yield(), then
it will be paused until it's manually ran again by caller (main
thread), which is executed with eina_coro_run().

Another common usage is to await for another task to be completed,
this can be done by waiting for a future to be resolved. It will
automatically yield and inform the caller of the future so it can
schedule properly instead of keep calling the task. Waiting for many
tasks can be achieved by using eina_future_all() or
eina_future_race(). This is done with eina_coro_await().

Due portability it was implemented using Eina_Thread, Eina_Lock and
Eina_Condition. Regular threads will ensure that the state is fully
preserved (stack, registers) in a platform independent way. Each
thread will wait on its own turn using the Eina_Lock and
Eina_Condition, thus it's guaranteed that only one is being executed
at the same time.

The API is small and should allow different implementations shall we
need them, like manually saving the stack and registers, then
restoring those -- problem is doing that in a portable way,
setjmp()/longjmp() won't save the stack, makecontext()/swapcontext()
doesn't work right on MacOS...

Hooks can be used to be informed when the main routine exits and then
enters, likewise when the coroutine enters and exits. These will be
used, for instance, to automatically get, adopt and return
Efl_Domain_Data needed to make Efl_Object work in such
environment. The flow is simple:

  - main exit (called from main thread)
  - coroutine enter (called from worker thread)
  - coroutine exit (called from worker thread)
  - main enter (called from main thead)

Performance may not be optimal, however this is meant as easy-to-use
and it shouldn't be an issue in real life. It will be mostly exposed
in two layers:

 - Efl.Loop.coro: will wrap eina_coro and and schedule using its main
   loop instance, returns an Eina_Future so it's easy to chain.

 - Eina_Promise/Eina_Future "async/await"-like behavior: will allow to
   write "synchronous" code that can wait for promises to be
   resolved. When eina_future_await(), it will actually register a new
   Eina_Future in the chain and then eina_coro_yield(). Once the
   future is called back it will call eina_coro_run() and allow the
   coroutine to resume. This is done on top fo eina_coro_await().
2017-08-27 11:47:55 -03:00
..
.gitignore
CMakeLists.txt build: PACKAGE_BUILD_DIR is now defined for everyone 2017-01-23 18:23:40 +01:00
cxx_compile_test.cxx
eina_suite.c eina: add Eina_Coro - coroutine support. 2017-08-27 11:47:55 -03:00
eina_suite.h eina: add Eina_Coro - coroutine support. 2017-08-27 11:47:55 -03:00
eina_suite.x eina: add test for all float/double util function. 2017-01-06 15:58:46 -08:00
eina_test_abi.c
eina_test_accessor.c
eina_test_array.c
eina_test_barrier.c tests: Remove CPU affinity from all threads 2017-03-06 17:03:47 +09:00
eina_test_benchmark.c
eina_test_bezier.c
eina_test_binbuf.c eina_binbuf: allow expand & usage of extra bytes. 2016-12-20 10:18:32 -02:00
eina_test_binshare.c
eina_test_clist.c
eina_test_convert.c
eina_test_coro.c eina: add Eina_Coro - coroutine support. 2017-08-27 11:47:55 -03:00
eina_test_counter.c
eina_test_cow.c
eina_test_crc.c
eina_test_error.c
eina_test_file.c tests: Remove CPU affinity from all threads 2017-03-06 17:03:47 +09:00
eina_test_fp.c
eina_test_freeq.c eina: Remove EAPI eina_freeq_main_set() 2017-01-17 14:21:17 +09:00
eina_test_hash.c
eina_test_inarray.c
eina_test_inlist.c
eina_test_iterator.c eina: add free cb to eina_iterator_filter_new 2016-12-09 10:16:08 +01:00
eina_test_lalloc.c
eina_test_list.c
eina_test_lock.c tests: Remove CPU affinity from all threads 2017-03-06 17:03:47 +09:00
eina_test_log.c
eina_test_magic.c
eina_test_main.c
eina_test_matrix.c eina: rename EINA_{FLT,DBL}_CMP to EINA_{FLT,DBL}_EQ. 2017-01-06 15:58:46 -08:00
eina_test_matrixsparse.c
eina_test_mempool.c eina: remove tests and benchmark for long dead mempool. 2017-08-15 13:46:38 -07:00
eina_test_module.c
eina_test_module_dummy.c
eina_test_quad.c eina: rename EINA_{FLT,DBL}_CMP to EINA_{FLT,DBL}_EQ. 2017-01-06 15:58:46 -08:00
eina_test_quadtree.c
eina_test_quaternion.c eina: rename EINA_{FLT,DBL}_CMP to EINA_{FLT,DBL}_EQ. 2017-01-06 15:58:46 -08:00
eina_test_rbtree.c
eina_test_rectangle.c eina: add api for assessing the relative position of two rectangles 2016-12-20 16:39:30 -08:00
eina_test_safepointer.c tests: Remove CPU affinity from all threads 2017-03-06 17:03:47 +09:00
eina_test_sched.c
eina_test_simple_xml_parser.c
eina_test_slice.c
eina_test_slstr.c eina: Introduce Eina_Slstr for short-lived strings 2017-01-17 14:20:55 +09:00
eina_test_str.c eina: fix for escapable charachters not getting escaped if it comes after '\t' or '\n' 2017-05-09 10:37:16 -07:00
eina_test_strbuf.c eina_buf: replace eina_strbuf_free_return with eina_xXxbuf_release 2017-01-06 12:45:27 +01:00
eina_test_stringshare.c eina: try slight improvement of eina tests suite. 2016-12-21 16:40:22 -08:00
eina_test_tiler.c eina: make tiler test compare tilers which are not equal 2017-07-14 18:43:00 -04:00
eina_test_tmpstr.c
eina_test_trash.c
eina_test_ustr.c
eina_test_ustringshare.c
eina_test_util.c eina: add test for all float/double util function. 2017-01-06 15:58:46 -08:00
eina_test_value.c Eina_Value type EINA_value. 2017-08-23 18:32:13 -03:00
eina_test_vector.c
eina_test_xattr.c eina: rename EINA_{FLT,DBL}_CMP to EINA_{FLT,DBL}_EQ. 2017-01-06 15:58:46 -08:00
sample.gpx