summaryrefslogtreecommitdiff
path: root/src/libcamera/timer.cpp
AgeCommit message (Collapse)Author
2020-11-15libcamera: Move EventDispatcher to internal APILaurent Pinchart
There's no user of the EventDispatcher (and the related EventNotifier and Timer classes) outside of libcamera. Move those classes to the internal API. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-05-16libcamera: Move internal headers to include/libcamera/internal/Laurent Pinchart
The libcamera internal headers are located in src/libcamera/include/. The directory is added to the compiler headers search path with a meson include_directories() directive, and internal headers are included with (e.g. for the internal semaphore.h header) #include "semaphore.h" All was well, until libcxx decided to implement the C++20 synchronization library. The __threading_support header gained a #include <semaphore.h> to include the pthread's semaphore support. As include_directories() adds src/libcamera/include/ to the compiler search path with -I, the internal semaphore.h is included instead of the pthread version. Needless to say, the compiler isn't happy. Three options have been considered to fix this issue: - Use -iquote instead of -I. The -iquote option instructs gcc to only consider the header search path for headers included with the "" version. Meson unfortunately doesn't support this option. - Rename the internal semaphore.h header. This was deemed to be the beginning of a long whack-a-mole game, where namespace clashes with system libraries would appear over time (possibly dependent on particular system configurations) and would need to be constantly fixed. - Move the internal headers to another directory to create a unique namespace through path components. This causes lots of churn in all the existing source files through the all project. The first option would be best, but isn't available to us due to missing support in meson. Even if -iquote support was added, we would need to fix the problem before a new version of meson containing the required support would be released. The third option is thus the only practical solution available. Bite the bullet, and do it, moving headers to include/libcamera/internal/. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Jacopo Mondi <jacopo@jmondi.org>
2020-02-13libcamera: Document thread-safety attributes of core classesLaurent Pinchart
Define the thread-safety attributes of the classes and methods that are either thread-safe or thread-bound. The CameraManager, Camera and PipelineHandler will be addressed separately. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-10-29libcamera: object: Add connection type parameter to invokeMethod()Jacopo Mondi
Allow specifying a different connection type than ConnectionTypeQueued for Object::invokeMethod(). Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-10-07libcamera: timer: Add start() method with absolute deadlineLaurent Pinchart
The Timer class is started using a timer duration. To help callers that require waiting for an absolute deadline, add a start() overload that takes a std::chrono::steady_clock::time_point value. This will be used by IPAs. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-10-07libcamera: timer: Forbid starting or stopping timer from another threadLaurent Pinchart
Starting or stopping a timer from a different thread than the one it belongs to is inherently racy. Disallow it. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-10-07libcamera: timer: Allow restarting a timer before expirationLaurent Pinchart
The Timer API allows restarting a timer before expiration. This isn't correctly implemented, fix it. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-10-07libcamera: timer: Don't reset deadline after time outLaurent Pinchart
Users of the Timer class may benefit from retrieving the timer deadline after it times out. This is currently not possible as the deadline is reset to 0 when the timer times out or is stopped. Fix this by not resetting the deadline, and adding a new running_ field to the Timer class to implement isRunning(). Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-10-07libcamera: timer: Remove the interval() methodLaurent Pinchart
The libcamera timers are single-shot timers. They are started with a duration, but fire once only, not based on an interval. Remove the interval concept by removing the interval() method, and rename other occurences of interval to duration. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-09-14libcamera: Switch to the std::chrono APILaurent Pinchart
Replace the clock_gettime()-based API with durations expressed as integers with the std::chrono API. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-08-17libcamera: Add parent argument to constructors of Object-derived classesLaurent Pinchart
Now that the Object class implements parent-child relationships, make it possible to create EventNotifier and Timer instances with a parent by adding a parent argument to their constructors. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-08-17libcamera: timer: Bind timers to threadsLaurent Pinchart
The Timer instances are registered with the event dispatcher instance of the CameraManager. This makes it impossible to use timers in other threads. Fix this by inheriting from Object, which allows binding instances to a thread, and register them with the event dispatcher for the thread they are bound to. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-01libcamera: timer: Stop timer when it is deletedNiklas Söderlund
If a timer is running while it's deleted it is still register with the event dispatcher. This causes a segmentation fault when the timer time-out and its signal is emitted. Fix this my stopping the timer when it's deleted. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-04-19libcamera: Include header related to source file firstLaurent Pinchart
Include the header file corresponding to the source file in the very first position. This complies with the Google C++ coding style guideliens, and helps ensuring that the headers are self-contained. Three bugs are already caught by this change (missing includes or forward declarations) in device_enumerator.h, event_dispatcher_poll.h and pipeline_handler.h. Fix them. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-04-19libcamera: Document documentation style and update the code accordinglyLaurent Pinchart
The documentation style for the Doxygen comment blocks is inconsistent in the library. Document the expectations and update all existing comment blocks to match. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-21libcamera: Use log categoriesLaurent Pinchart
Use log categories in the whole existing code base. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-01-17libcamera: timer: Fix 32 bit wrapKieran Bingham
The msec parameter was multiplied as a 32 bit value when converting to nanosecond resolution. This wraps at 4.2949 seconds, and causes timers longer than this to fail. Fix the multiplication to upcast to 64 bit using an unsigned long long specifier on the multiplier. While we're here, initialise the two integer class members in the constructor initialiser list. Fixes: 1a57bcb8d1a7 ("libcamera: Add event notification infrastructure") Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-08libcamera: Add event notification infrastructureLaurent Pinchart
Add three new classes, EventDispatcher, EventNotifier and Timer, that define APIs for file descriptor event notification and timers. The implementation of the EventDispatcher is meant to be provided to libcamera by the application. The event dispatcher is integrated twith the camera manager to implement automatic registration of timers and events. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>