blob: 8366ca02017762eccc69252b4075f5bbc3b26c36 [file] [log] [blame]
Roshan Pius091e1c12017-01-30 16:40:50 -08001Vendor HAL Threading Model
2==========================
3The vendor HAL service has two threads:
Gabriel Biren631a8112022-12-01 22:29:32 +000041. HIDL thread: This is the main thread which processes all the incoming HIDL
Roshan Pius091e1c12017-01-30 16:40:50 -08005RPC's.
62. Legacy HAL event loop thread: This is the thread forked off for processing
7the legacy HAL event loop (wifi_event_loop()). This thread is used to process
8any asynchronous netlink events posted by the driver. Any asynchronous
9callbacks passed to the legacy HAL API's are invoked on this thread.
10
11Synchronization Concerns
12========================
13wifi_legacy_hal.cpp has a bunch of global "C" style functions to handle the
Gabriel Biren631a8112022-12-01 22:29:32 +000014legacy callbacks. Each of these "C" style function invokes a corresponding
Roshan Pius091e1c12017-01-30 16:40:50 -080015"std::function" version of the callback which does the actual processing.
Gabriel Biren631a8112022-12-01 22:29:32 +000016The variables holding these "std::function" callbacks are reset from the HIDL
Roshan Pius091e1c12017-01-30 16:40:50 -080017thread when they are no longer used. For example: stopGscan() will reset the
18corresponding "on_gscan_*" callback variables which were set when startGscan()
19was invoked. This is not thread safe since these callback variables are
20accesed from the legacy hal event loop thread as well.
21
22Synchronization Solution
23========================
24Adding a global lock seems to be the most trivial solution to the problem.
25a) All of the asynchronous "C" style callbacks will acquire the global lock
26before invoking the corresponding "std::function" callback variables.
Gabriel Biren631a8112022-12-01 22:29:32 +000027b) All of the HIDL methods will also acquire the global lock before processing
28(in hidl_return_util::validateAndCall()).
Roshan Pius091e1c12017-01-30 16:40:50 -080029
30Note: It's important that we only acquire the global lock for asynchronous
31callbacks, because there is no guarantee (or documentation to clarify) that the
32synchronous callbacks are invoked on the same invocation thread. If that is not
33the case in some implementation, we will end up deadlocking the system since the
Gabriel Biren631a8112022-12-01 22:29:32 +000034HIDL thread would have acquired the global lock which is needed by the
Roshan Pius091e1c12017-01-30 16:40:50 -080035synchronous callback executed on the legacy hal event loop thread.