Commit Graph
40 Commits
Author SHA1 Message Date
Martin Willi 1897dd730f processor: remove the now unused get_threads() method again 2013-07-18 16:00:31 +02:00
Martin Willi ea009869e9 watcher: use processors new execute_job() to notify FDs
Just queueing is problematic, as all threads might be busy waiting for events
that the queued (but never executed) job delivers.
2013-07-18 16:00:31 +02:00
Martin Willi 6653e6c13e processor: add an execute_job() method to directly execute an important job
If all worker threads are busy and waiting for an event, we must ensure that
a job delivering that event gets executed. This new method has this property
for CRITICAL jobs, using a worker if we have one, but executing the job directly
if not.
2013-07-18 16:00:31 +02:00
Martin Willi 55240835b0 watcher: properly support multiple watch callback types for the same FD 2013-07-18 16:00:31 +02:00
Martin Willi d0c25a3f23 watcher: read multiple notifications if available
Use non-blocking I/O on the read end of the notify pipe. This also makes sure
the read does not block should select() signal data while there is none.
2013-07-18 16:00:31 +02:00
Martin Willi 58d0dadddc watcher: add some debugging statements 2013-07-18 16:00:29 +02:00
Martin Willi 91a2ae644c watcher: if the processor has no threads, execute the job with watcher thread
This is important during shutdown, where we might need to signal some FDs while
all idle threads are gone already.
2013-07-18 16:00:29 +02:00
Martin Willi 50720d7ce9 processor: add a getter for the threads passed to set_threads() 2013-07-18 16:00:29 +02:00
Martin Willi a0e3a7363f watcher: unregister a watcher FD if its thread gets cancelled 2013-07-18 16:00:29 +02:00
Martin Willi a558ba16f3 watcher: release threads waiting in remove() when watcher thread gets cancelled
During daemon shutdown, users might call remove() after processor.set_threads(0)
has been called. This gets problematic, as a watch event might be unable
to signal completion when no threads are available anymore. Work around this
issue by cancelling waiters once processor.cancel() has been called.
2013-07-18 16:00:29 +02:00
Martin Willi 32b2a5e04b watcher: add a centralized an generic facility to monitor file descriptors 2013-07-18 16:00:27 +02:00
Tobias Brunner b1b0cce396 processor: Simplified the main loop 2013-06-28 17:02:06 +02:00
Tobias Brunner 6ca25ccc04 processor: Don't hold the lock while destroying jobs
If a lock is held when queue_job() is called and the same lock is
required during the destruction of a job, holding the internal lock
in the processor while calling destroy() could result in a deadlock.
2013-06-28 17:02:05 +02:00
Tobias Brunner f05b427265 Moved debug.[ch] to utils folder 2012-10-24 16:00:51 +02:00
Tobias Brunner 12642a6831 Moved data structures to new collections subfolder 2012-10-24 16:00:49 +02:00
Tobias Brunner e0efd7c121 Make rescheduling a job more predictable
This avoids race conditions between calls to cancel() and jobs that like
to be rescheduled.  If jobs were able to reschedule themselves it would
theoretically be possible that two worker threads have the same job
assigned (the one currently executing the job and the one executing the
same but rescheduled job if it already is time to execute it), this means
that cancel() could be called twice for that job.

Creating a new job based on the current one and reschedule that is also
OK, but rescheduling itself is more efficient for jobs that need to be
executed often.
2012-06-25 17:49:12 +02:00
Tobias Brunner 26d77eb3e6 Centralized thread cancellation in processor_t
This ensures that no threads are active when plugins and the rest of the
daemon are unloaded.

callback_job_t was simplified a lot in the process as its main
functionality is now contained in processor_t.  The parent-child
relationships were abandoned as these were only needed to simplify job
cancellation.
2012-06-25 17:38:59 +02:00
Tobias Brunner 7fec83af28 Give processor_t more control over the lifecycle of a job
Jobs are now destroyed by the processor, but they are allowed to
reschedule themselves.  That is, parts of the reschedule functionality
already provided by callback_job_t is moved to the processor.  Not yet
fully supported is JOB_REQUEUE_DIRECT and canceling jobs.

Note: job_t.destroy() is now called not only for queued jobs but also
after execution or cancellation of jobs.  job_t.status can be used to
decide what to do in said method.
2012-06-25 17:10:28 +02:00
Tobias Brunner 052e0a17b8 Use wrapped semaphore in callback_job_t. 2012-05-02 14:45:38 +02:00
Tobias Brunner b24287c269 Log worker thread ID with two digits. 2011-12-16 16:44:38 +01:00
Tobias Brunner edad908792 Fixed compiler warnings regarding enum comparison.
Warnings like

  comparison of unsigned expression < 0 is always false

are reported with -Wextra when enum types that are compiled to an
unsigned type (which is up to the compiler) are checked for negativity.
2011-11-25 09:40:30 +01:00
Tobias Brunner f3bb1bd039 Fixed common misspellings.
Mostly found by 'codespell'.
2011-07-20 16:14:10 +02:00
Tobias Brunner dcc1ad6a23 Prevent deadlock while shutting down thread pool.
During destruction the main thread locks the mutex in processor_t and
waits on a condvar for threads to have terminated.  Because the mutex
has also to be locked to decrement the thread count the condvar cannot
be signaled before doing that as otherwise the main thread might already
be waiting to join the threads while locking the mutex and thus causing
a deadlock.
2011-06-08 11:44:42 +02:00
Tobias Brunner 92abe2bd68 Update working thread count without allocation. 2011-05-16 18:28:03 +02:00
Tobias Brunner 21692169b9 Make sure working thread count is correctly updated 2011-05-16 15:24:16 +02:00
Martin Willi 14bf2f689d Use CRITICAL job priority class for long running dispatcher jobs 2011-05-16 15:24:15 +02:00
Martin Willi 1c8f58adb9 Introduce a highest priority job for critical thread services 2011-05-16 15:24:15 +02:00
Martin Willi c6089e252d Added a callback_job constructor supporting custom priorities 2011-05-16 15:24:15 +02:00
Martin Willi 877fdcf0b8 Count number of threads active in each class, and reserve threads only if none active 2011-05-16 15:24:14 +02:00
Martin Willi 68f56418cd Reserve threads for job priority classes based on strongswan.conf options 2011-05-16 15:24:13 +02:00
Martin Willi 2959ea6f84 Added job priority enum names 2011-05-16 15:24:13 +02:00
Martin Willi c73d4f53f5 Processor job scheduling respects job priority classes 2011-05-16 15:24:13 +02:00
Martin Willi f77203bbfb Introduce priority classes for jobs 2011-05-16 15:24:12 +02:00
Martin Willi e7643c92d3 Migrated scheduler_t to INIT/METHOD macros 2011-05-05 11:14:51 +02:00
Martin Willi cda46be72a Migrated callback_job to INIT/METHOD macros 2011-05-05 11:14:51 +02:00
Martin Willi 3316742969 Migrated processor to INIT/METHOD macros 2011-05-05 11:14:50 +02:00
Martin Willi 11f89bc948 Do not invoke processor restart() if not required
Doing so might result in a deadlock during shutdown if a delayed
restart is locked on the bus during the debug statement.
2011-03-15 11:48:19 +01:00
Martin Willi d93060759e Remove obsolete pool_size argument in processor_create() 2010-11-16 09:39:06 +01:00
Tobias Brunner bb381e26c6 Refer to scheduler and processor via lib and not hydra. 2010-09-02 19:04:18 +02:00
Tobias Brunner e18556e9e9 Moved scheduler and thread pool to libstrongswan. 2010-09-02 19:04:18 +02:00