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().
Built on top of the new 'postponed' free queue, the short-lived
strings API allows users to return new strings without caring
about freeing them. EFL main loop will do this automatically for
them you at a later point in time (at the end of an iteration).
The APIs provided will either duplicate (copy) or more generally
steal an existing string (char *, stringshare, tmpstr, strbuf),
taking ownership of it and controling its lifetime. Those strings
can then be safely returned by an API. From a user point of view,
those strings must be considered like simple const char *, ie.
no need to free() them and their validity is limited to the
local scope.
There is no function to remove such a string from the freeq.
The short lived strings API is not thread-safe: do not send a
short-lived object from one thread to another.
@feature
Summary:
Since eina_model was dropped some years ago.
Also a few other points where related stuff is just commented out.
Reviewers: iscaro, barbieri
Reviewed By: barbieri
Subscribers: cedric, jpeg
Differential Revision: https://phab.enlightenment.org/D4442
this adds eina_freeq api's for c land for deferring freeing of
pointers and can be used a s a simple copy & paste drop-in for free()
just to "do this later". the pointer will eveentually be freed as
eina_shutdown will free the main free queue and this will in turn free
everything in it. as long as the main lo0op keeps pumping things will
og on the queue and then be freed from it. free queues have limits so
if they get full they will clear out old pointers and free them so it
won't grow without bound. the default max is 1mb of data or 16384
items whichever limit is hit first and at that point the oldest item
will be freed to make room for the newest. the mainloop whenever it
finishes idle enterers will add an idler to spin and free while idle.
the sizes can be tuned and aruged about as to what defaults should be.
this also allows for better memory debugging too by being able to fill
freed memory with patterns if its small enough etc. etc.
@feature
accidentally snukc in commented disables in test suite as i was
hunting why eina test suite crashes while dealing with feedback on my
compare fixes etc.
Summary:
Fixed eina_test_quaternion_conjugate and eina_test_quaternion_matrix which
were failing and also added the quaternion test in eina suite
Signed-off-by: Vivek Ellur <vivek.ellur@samsung.com>
Reviewers: cedric
Reviewed By: cedric
Subscribers: cedric
Differential Revision: https://phab.enlightenment.org/D2775
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Summary:
I added test cases using seed 0xffffffff, I was not
able to get crc value for different seeds online. Checked some of the links, but they are
using entirely different logic and value was not matching for other seed value.
Signed-off-by: vivek <vivek.ellur@samsung.com>
Reviewers: cedric
Subscribers: cedric
Differential Revision: https://phab.enlightenment.org/D2293
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Summary:
Add eina_test_xattr.c file for testing eina xattr functions and added test
cases for eina_xattr_set and eina_xattr_fd_set functions. Those tests need
a directory where the underlying file system allow xattr. Usually /tmp is
running on tmpfs that doesn't support today xattr. This test won't be run
if we are not provided with an existing proper directory.
Signed-off-by: vivek <vivek.ellur@samsung.com>
Reviewers: cedric
Subscribers: cedric
Differential Revision: https://phab.enlightenment.org/D2090
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Summary:
New test case for Eina_Trash was added
Signed-off-by: kabeer khan <kabeer.khan@samsung.com>
Reviewers: raster, cedric
Subscribers: cedric
Differential Revision: https://phab.enlightenment.org/D1460
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>