Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <stdint.h> |
| 20 | #include <sys/cdefs.h> |
| 21 | |
Steven Moreland | 23d058f | 2020-07-24 22:49:51 +0000 | [diff] [blame] | 22 | #include <android/binder_status.h> |
| 23 | |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 24 | __BEGIN_DECLS |
| 25 | |
| 26 | /** |
| 27 | * This creates a threadpool for incoming binder transactions if it has not already been created. |
Steven Moreland | 23d058f | 2020-07-24 22:49:51 +0000 | [diff] [blame] | 28 | * |
| 29 | * When using this, it is expected that ABinderProcess_setupPolling and |
| 30 | * ABinderProcess_handlePolledCommands are not used. |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 31 | */ |
| 32 | void ABinderProcess_startThreadPool(); |
| 33 | /** |
| 34 | * This sets the maximum number of threads that can be started in the threadpool. By default, after |
Steven Moreland | 21f5f9a | 2019-07-25 16:46:13 -0700 | [diff] [blame] | 35 | * startThreadPool is called, this is 15. If it is called additional times, it will only prevent |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 36 | * the kernel from starting new threads and will not delete already existing threads. |
| 37 | */ |
| 38 | bool ABinderProcess_setThreadPoolMaxThreadCount(uint32_t numThreads); |
| 39 | /** |
| 40 | * This adds the current thread to the threadpool. This may cause the threadpool to exceed the |
| 41 | * maximum size. |
| 42 | */ |
| 43 | void ABinderProcess_joinThreadPool(); |
| 44 | |
Steven Moreland | 23d058f | 2020-07-24 22:49:51 +0000 | [diff] [blame] | 45 | /** |
| 46 | * This gives you an fd to wait on. Whenever data is available on the fd, |
| 47 | * ABinderProcess_handlePolledCommands can be called to handle binder queries. |
| 48 | * This is expected to be used in a single threaded process which waits on |
| 49 | * events from multiple different fds. |
| 50 | * |
| 51 | * When using this, it is expected ABinderProcess_startThreadPool and |
| 52 | * ABinderProcess_joinThreadPool are not used. |
| 53 | * |
| 54 | * \param fd out param corresponding to the binder domain opened in this |
| 55 | * process. |
| 56 | * \return STATUS_OK on success |
| 57 | */ |
| 58 | __attribute__((weak)) binder_status_t ABinderProcess_setupPolling(int* fd) __INTRODUCED_IN(31); |
| 59 | |
| 60 | /** |
| 61 | * This will handle all queued binder commands in this process and then return. |
| 62 | * It is expected to be called whenever there is data on the fd. |
| 63 | * |
| 64 | * \return STATUS_OK on success |
| 65 | */ |
| 66 | __attribute__((weak)) binder_status_t ABinderProcess_handlePolledCommands() __INTRODUCED_IN(31); |
| 67 | |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 68 | __END_DECLS |