aboutsummaryrefslogtreecommitdiffstats
path: root/src/jobs.c
AgeCommit message (Collapse)AuthorFilesLines
2019-04-02jobs: Refactor exiting jobsJosé Bollo1-67/+48
The new termination function can allow the restart because it doesn't abort the waiting jobs. So after calling 'jobs_exit', all threads stop. The function 'job_start' returns. The threads that are in blocking state, i.e. in a call to 'jobs_enter' or 'jobs_call' are stopped. An error status -1 with errno=EINTR is returned in that case. But before returning, that function calls the exit handler if any. Change-Id: I85a4b1976b09b18804eb681af940531ae5ace6c3 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2019-03-27evmgr: Isolate the event loop from jobsJosé Bollo1-152/+30
The event loop is renamed evmgr for "event manager" with the intention (1) still use evloop in jobs (2) to provide an abstract event manager/handler/loop abstraction. Change-Id: Ib1955f661f98df80e1c7be99e9fe26a1e06d78f6 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2019-03-27system & jobs: Reverse link and acquiring eventsJosé Bollo1-11/+7
- The new version of 'systemd_get_event_loop' dont depends anymore on jobs but returns a unique systemd event loop for any threads. - The event loop of jobs now use system.h function instead of the opposite. - The function 'jobs_get_sd_event' is removed - The function 'jobs_acquire_event_manager' is introduced. It is designed to that the current thread can manipulate the single event manager Change-Id: I31fe48dfe0f2cfa4d468e49338d36fea6e7e8081 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2019-03-27watchdog: Isolate the watchdog from jobsJosé Bollo1-15/+0
Change-Id: Iaa7f71dc7e5d8d525463619b4da980c827722909 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2019-03-27jobs: Clean unneeded codeJosé Bollo1-2/+0
Minor cleanup Change-Id: Iddcaf85cdc30f74e54016ce300380b33662fbc04 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2019-03-22jobs: Ensure validy of event loopFrederic Marec1-0/+3
In rare circumstances during intialization threads should wait instead of using a null event loop. This is because no one has needed event loop at this stage of initialization. Change-Id: I05b6ddbc05bec50958d0981213219b1d641401a5 Signed-off-by: Frederic Marec <frederic.marec@iot.bzh>
2019-02-06Update copyright datehalibut_7.90.0halibut/7.90.07.90.0José Bollo1-1/+1
Change-Id: I3aaa92b2bfb01699ee8ae609272e93032b6f1a9d Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2019-02-06jobs: Ensure releasing event loopJose Bollo1-1/+2
The internal functions blocking threads for implementing call_sync were not releasing the event loop, leading to deafness of the binder. Include a tuto-4 that reproduce the issue on a binder with the bug and that also shows interesting usages of the binder. Bug-AGL: SPEC-2161 Change-Id: I83ad4d55d721a6046e798a5e06967df4dd5a7284 Signed-off-by: Jose Bollo <jose.bollo@iot.bzh>
2019-01-16jobs: Remove conditionnal REMOVE_SYSTEMD_EVENTJose Bollo1-108/+0
The removal of the systemd event loop will be made in later changes. Change-Id: Ia6c52feb4969f360c31cbfc50ae991f1767f007d Signed-off-by: Jose Bollo <jose.bollo@iot.bzh>
2019-01-16jobs: Separate internal threads from othersJosé Bollo1-61/+92
Foreign threads, that are not started by jobs, are allowed to use synchronous jobs_call/job_leave (directly or indirectly). This commit ensure that those foreign thread will neither acquire the eventloop nor execute jobs. Includes a tiny cleanup of remain usage. Bug-AGL: SPEC-2089 Change-Id: I2ad7fcfe2c276e34bdc4ec0c2aa3a4207bea1854 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2019-01-16jobs: Refactor event loop handlingJosé Bollo1-125/+177
This improves the arbitration of the single event loop across threads. Before introduction of using 'evenfd' there was several event loop. At the current time, there is only one. At the end, there will probably remain only one. Bug-AGL: SPEC-2089 Change-Id: Iac9db7cbe15b4c9c76e6e9a8f6e641ed2a9039e0 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2018-12-31jobs: Fix a lock of call syncJose Bollo1-24/+59
Sometime the function jobs_leave missed to wake up the process that expected the result. It happened when that waiting thread was locked in the epoll. That commit unlock it. Bug-AGL: SPEC-2089 Change-Id: I6ab6a60a8c9ea3639143f282f90c7b77ed16853a Signed-off-by: Jose Bollo <jose.bollo@iot.bzh> Signed-off-by: Clément Bénier <clement.benier@iot.bzh>
2018-09-05main-afb-daemon: Export API after initializationJose Bollo1-1/+1
Exporting API after initialization is a simple technic to avoid interleaving of incoming foreign calls during initialisation. Also a tiny fix in jobs.c and afb-socket.c. Bug-AGL: SPEC-1724 Change-Id: I59596256481c8afcd88755ec303bf7f881b55c12 Signed-off-by: Jose Bollo <jose.bollo@iot.bzh>
2018-08-28Allow choice to trap or not program faultsJosé Bollo1-13/+0
The binder traps faults by default to recover as much as possible from unexpected errors. Developers may need to remove that behaviour to get core file. This introduces 2 ways to set or remove the trapping of faults: - the environment variable AFB_TRAP_FAULTS - the command line option --trap-faults Both take a boolean value set using on of the following words: 1 yes true on -- enable trapping of faults (the default) 0 no false off -- disable trapping of faults Bug-AGL: SPEC-1702 Change-Id: I6c6a3b933dbda9922a6079c390a601c533d49e55 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2018-08-23jobs: Abort when systemd's event loop lostflounder_5.99.4flounder/5.99.45.99.4José Bollo1-1/+2
When sd_event_prepare returns an error there is currently no way to restore the event loop working. It happens when a callback of an sd_event is faulty (ex: SIGSEGV). In that case the monitoring of signals (sig-monitor) interfer badly with systemd. But at the the application firstly has error. To avoid flooding the journal with messages, aborting is the best solution. Bug-AGL: SPEC-1681 Change-Id: If01295f07b3c3fc8c8ec1ac5bf04840d42ee9774 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2018-07-25Tune dependency to fdev-epollJose Bollo1-6/+13
The dependency to fdev-epoll is not real at the moment because afb-daemon still uses systemd event loop mechanisms. At the end use of it will depend on the conditional compilation flag as REMOVE_SYSTEMD_EVENT here. Change-Id: I46e65cddafef05a9418cd4cf4d5cbf596ebeda49 Signed-off-by: Jose Bollo <jose.bollo@iot.bzh>
2018-06-15api-v3: First draftJosé Bollo1-1/+1
This commit introduces the bindings v3 API for bindings. The documentation has still to be improved and will come very soon. Change-Id: I8f9007370e29f671fdfd1da87fff7372a17db7af Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2018-06-13jobs: Switch back to sd_eventjobol1-2/+46
Change-Id: I8c9de83d857844b1c5d0d2d26385dbf19fcae228 Signed-off-by: jobol <jose.bollo@iot.bzh>
2018-06-13jobs: Fix minor errorsJosé Bollo1-4/+4
Change-Id: I78aeb16fb1cf5b029fb24704d16c42152f9cc909 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2018-06-13jobs: Switch to fdev_epoll instead of sd_eventJosé Bollo1-25/+89
Use by default an epoll of jobs for handling HTTP and websockets. The sd_event loop remains available (to be checked). Change-Id: Iaaad005c9880ba1818936a93c8626490666c9eec Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2018-06-13jobs: Cosmetic changesJosé Bollo1-4/+10
Change-Id: I7505c3c5bcec9e2b7af645a59a3716cf9bfec552 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2018-02-27Update date of copyright noticesJosé Bollo1-1/+1
Change-Id: If9d7e7728df086fbb7214f1de5cbec35cd2f1d9b Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2018-02-06jobs: Add argument to startJosé Bollo1-2/+2
Change-Id: I89a75a036c60097fb898ab8723007ca6ebfc7f39 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2018-01-18jobs: Integrate systemd watchdog by defaultJosé Bollo1-0/+9
Change-Id: Iaa3ce3ee9188e3ddaf6ee70964963d29df78689f Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2018-01-18jobs: Split jobs_get_sd_eventJosé Bollo1-5/+16
Provide a mutex locked internal function for getting the event loop: get_sd_event_locked Change-Id: I2635f901b3ec0fcf2c52f569f4c57cfd046601af Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-12-01jobs: Fix locks in event loopsJosé Bollo1-11/+17
Change-Id: Ie07a9bc4f930a0ecd2102a94e7f5f7b0daa705ef Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-11-30jobs: Fix possible race conditionJosé Bollo1-2/+4
Sending the signal while not being sure that is is expected could be a race condition. Taking the mutex avoids it. In the same time, switch to broadcasting. Change-Id: I3f43d0d860cccc61ec140ceef223f572f806872c Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-11-29jobs: rewrite of the event loop handlingJosé Bollo1-106/+108
This new version use an eventfd to unlock the event loop when needed. This reduce the count of sd_event needed. Bug-AGL: SPEC-1091 Change-Id: I9bc273e89ab1a70ccc2187c2571e68c9c771ee25 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-11-17fix build errorJosé Bollo1-1/+1
Change-Id: I6ff16055597d36290f50b40d6dfe960aea691652 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-11-17afb-proto-ws: Fix autolock in proto-wsJosé Bollo1-1/+3
Because a systemd event loop can not be reentered while evaluating an event callback, the event loop was removed from the threads. It had the effect to enter in deadlock when calling a synchronous call while in an event callback. Queueing a job solves the issue. But because using queued job has implications on libafbws, a fake job manager is added for libafbws. Change-Id: Id793bea55743790082eaab48cd4cc87f7993772a Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-11-03jobs: Improve event loop integrationJosé Bollo1-58/+64
The previous implmentation was buggy. This changes make the event loop a thread global variable. A thread now refuses to run an event loop if it is in dispatching state. Change-Id: Ic29792b87c1cae201958feb96d93678f6d37ac8d Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-10-09jobs: add const qualifier for groupsJosé Bollo1-8/+8
Change-Id: I34faa8e5da4321da53beb323559399d1460562c1 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-10-09Remove tailing spaces and TODO fileJosé Bollo1-1/+1
Change-Id: Id7cdad4e24c6ab62bf9c325b542e1605b17223f4 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-08-31jobs: optimized version of fix starveJosé Bollo1-28/+19
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-08-30jobs: fix starveJosé Bollo1-13/+33
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-06-02Fix error on initialisationJosé Bollo1-1/+1
Change-Id: If6a988359b4d2747cefdd683b6328f5b36e37548 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-04-13Simplification and optimisation of jobsJosé Bollo1-148/+80
It comes from the use of this module that it can be simplified to only get 1 argument. It reduces either the complexity of the code and the time spent in job management. It optimise how normal jobs are called (not intermediate function). Also factorisation and simplification of synchronous enter/call. Change-Id: Id60dd2363fee2b007b4557430659faf733d2179d Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-04-12reduce verbosityJosé Bollo1-3/+0
Change-Id: I625dd517912461bb55f298a11a5eb37adc92293b Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-04-06Add an easy function for synchronous callsJosé Bollo1-4/+68
The added function, 'jobs_call', allows to call a job with 'group' sequencing and 'timeout' handling synchronously. The difference with 'jobs_enter' is that the function 'jobs_call' assert that the job is terminated when 'callback' returns. Change-Id: I8c01d1cd017787ca0448b03a899305a9069ebb6c Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-04-06Avoid to stick on event loopJosé Bollo1-1/+10
When working synchronously, waiting continuously to an event can make deadlocks. This commit enforce threads that wait for some job completion to wait for a fixed amount of time. An alternative management with signals should be studied in future. Change-Id: Idcfadc60f8c14d73d7fa32e937c6ea0f552cc09b Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-04-04Avoid to count child threadsJosé Bollo1-7/+9
The count of allowed threads must be the real count of threads started. Change-Id: Iaefc9fa4368042d6db45ed3333f9591da027b2f0 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-04-03Rework the jobsJosé Bollo1-272/+154
Enforce starting jobs with acquiring the calling thread. Removes invoke methods in favour of enter/leave synchronisation. Change-Id: I7086f7f53b919b43ddafd2355316abc0d3516f49 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-03-30Start to implement the bindings V2José Bollo1-5/+10
More work has to be done for merging common code. Change-Id: I72b01901f978854843967c12bfcb3cc59cc10310 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-03-30Overall integration of job initialisationJosé Bollo1-0/+31
Move the job initialisation from main to jobs. Change-Id: I8f5b54adb62e60592884ff1e3fad9811b5934d47 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-03-30Fix concurrency issues on event managerJosé Bollo1-132/+133
Having only one event manager is not possible in multithreading due to the way that systemd has to manage timer events. We observed that timers were not armed when set in a thread because event was polling in an other thread. This patch provides more than one event manager and at most as many as the number of threads avalaible to start. Change-Id: Iaeab353b7bc79ce61361ab73c7b197a9e69a6109 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-03-29Add commentsJosé Bollo1-156/+440
Improves the comments of the module jobs Change-Id: Id99e9c6d6c9572d68ae9cca0f13e2498348de91d Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-03-28Refactor job to allow synchronous callsJosé Bollo1-136/+300
The family of methods "jobs_invoke" make synchronous job activation. It waits for the completion of the job while still dispatching it internally and providing the calling thread for processing any job queued. Change-Id: Id36a30789cc51245a7bbfca42f0122cf4ea623b2 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-03-28Fix bug in recycling jobsJosé Bollo1-2/+4
The bug was creating an infinite loop starving the system (or other possible horrific stuff). Also updated the test. Change-Id: Id71dd112d2ed4651ac8aa56d2c57b088d69b8655 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-03-27Make main thread used for common jobsJosé Bollo1-87/+205
This commit make the main thread behaving like any other threads. The main loop is shared across threads, the first one without job taking it. The main event loop now have the lowest priority. It is activated only when no job is queued. This has the good effect to not try to overfill the queue of jobs. Change-Id: I07cecc9d94a02134c63bc2a814db56e171ab719e Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2017-03-22Refactor of threading and signal monitorJosé Bollo1-0/+344
The goal is to allow use of this facilities for things that are not 'afb_req'. Change-Id: I0d99c227934ed45136477bf6235bd1541d5f05cf Signed-off-by: José Bollo <jose.bollo@iot.bzh>