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 22 #include <android/binder_status.h> 23 24 __BEGIN_DECLS 25 26 /** 27 * This creates a threadpool for incoming binder transactions if it has not already been created. 28 * 29 * When using this, it is expected that ABinderProcess_setupPolling and 30 * ABinderProcess_handlePolledCommands are not used. 31 * 32 * Do not use this from a library. Apps setup their own threadpools, and otherwise, the main 33 * function should be responsible for configuring the threadpool for the entire application. 34 */ 35 void ABinderProcess_startThreadPool(void); 36 /** 37 * This sets the maximum number of threads that can be started in the threadpool. By default, after 38 * startThreadPool is called, this is 15. If it is called additional times, it will only prevent 39 * the kernel from starting new threads and will not delete already existing threads. 40 * 41 * Do not use this from a library. Apps setup their own threadpools, and otherwise, the main 42 * function should be responsible for configuring the threadpool for the entire application. 43 */ 44 bool ABinderProcess_setThreadPoolMaxThreadCount(uint32_t numThreads); 45 /** 46 * Check if the threadpool has already been started. 47 * This tells whether someone in the process has called ABinderProcess_startThreadPool. Usually, 48 * you should use this in a library to abort if the threadpool is not started. 49 * Programs should configure binder threadpools once at the beginning. 50 */ 51 bool ABinderProcess_isThreadPoolStarted(void); 52 /** 53 * This adds the current thread to the threadpool. This may cause the threadpool to exceed the 54 * maximum size. 55 * 56 * Do not use this from a library. Apps setup their own threadpools, and otherwise, the main 57 * function should be responsible for configuring the threadpool for the entire application. 58 */ 59 void ABinderProcess_joinThreadPool(void); 60 61 /** 62 * This gives you an fd to wait on. Whenever data is available on the fd, 63 * ABinderProcess_handlePolledCommands can be called to handle binder queries. 64 * This is expected to be used in a single threaded process which waits on 65 * events from multiple different fds. 66 * 67 * When using this, it is expected ABinderProcess_startThreadPool and 68 * ABinderProcess_joinThreadPool are not used. 69 * 70 * \param fd out param corresponding to the binder domain opened in this 71 * process. 72 * \return STATUS_OK on success 73 */ 74 __attribute__((weak)) binder_status_t ABinderProcess_setupPolling(int* fd) __INTRODUCED_IN(31); 75 76 /** 77 * This will handle all queued binder commands in this process and then return. 78 * It is expected to be called whenever there is data on the fd. 79 * 80 * \return STATUS_OK on success 81 */ 82 __attribute__((weak)) binder_status_t ABinderProcess_handlePolledCommands(void) __INTRODUCED_IN(31); 83 84 __END_DECLS 85