blob: f408fadee08248a2d9cdffde3fa7ac9eeb20e73b [file] [log] [blame]
Steven Moreland2e87adc2018-08-20 19:47:00 -07001/*
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 Moreland23d058f2020-07-24 22:49:51 +000022#include <android/binder_status.h>
23
Steven Moreland2e87adc2018-08-20 19:47:00 -070024__BEGIN_DECLS
25
26/**
27 * This creates a threadpool for incoming binder transactions if it has not already been created.
Steven Moreland23d058f2020-07-24 22:49:51 +000028 *
29 * When using this, it is expected that ABinderProcess_setupPolling and
30 * ABinderProcess_handlePolledCommands are not used.
Steven Moreland2e87adc2018-08-20 19:47:00 -070031 */
32void ABinderProcess_startThreadPool();
33/**
34 * This sets the maximum number of threads that can be started in the threadpool. By default, after
Steven Moreland21f5f9a2019-07-25 16:46:13 -070035 * startThreadPool is called, this is 15. If it is called additional times, it will only prevent
Steven Moreland2e87adc2018-08-20 19:47:00 -070036 * the kernel from starting new threads and will not delete already existing threads.
37 */
38bool 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 */
43void ABinderProcess_joinThreadPool();
44
Steven Moreland23d058f2020-07-24 22:49:51 +000045/**
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 Moreland2e87adc2018-08-20 19:47:00 -070068__END_DECLS