1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright 2017 The Android Open Source Project 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 5bf215546Sopenharmony_ci * you may not use this file except in compliance with the License. 6bf215546Sopenharmony_ci * You may obtain a copy of the License at 7bf215546Sopenharmony_ci * 8bf215546Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 9bf215546Sopenharmony_ci * 10bf215546Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 11bf215546Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 12bf215546Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13bf215546Sopenharmony_ci * See the License for the specific language governing permissions and 14bf215546Sopenharmony_ci * limitations under the License. 15bf215546Sopenharmony_ci */ 16bf215546Sopenharmony_ci 17bf215546Sopenharmony_ci/** 18bf215546Sopenharmony_ci * @addtogroup Sync 19bf215546Sopenharmony_ci * @{ 20bf215546Sopenharmony_ci */ 21bf215546Sopenharmony_ci 22bf215546Sopenharmony_ci/** 23bf215546Sopenharmony_ci * @file sync.h 24bf215546Sopenharmony_ci */ 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#ifndef ANDROID_SYNC_H 27bf215546Sopenharmony_ci#define ANDROID_SYNC_H 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci#include <stdint.h> 30bf215546Sopenharmony_ci#include <sys/cdefs.h> 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#include <linux/sync_file.h> 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_ci__BEGIN_DECLS 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci/* Fences indicate the status of an asynchronous task. They are initially 37bf215546Sopenharmony_ci * in unsignaled state (0), and make a one-time transition to either signaled 38bf215546Sopenharmony_ci * (1) or error (< 0) state. A sync file is a collection of one or more fences; 39bf215546Sopenharmony_ci * the sync file's status is error if any of its fences are in error state, 40bf215546Sopenharmony_ci * signaled if all of the child fences are signaled, or unsignaled otherwise. 41bf215546Sopenharmony_ci * 42bf215546Sopenharmony_ci * Sync files are created by various device APIs in response to submitting 43bf215546Sopenharmony_ci * tasks to the device. Standard file descriptor lifetime syscalls like dup() 44bf215546Sopenharmony_ci * and close() are used to manage sync file lifetime. 45bf215546Sopenharmony_ci * 46bf215546Sopenharmony_ci * The poll(), ppoll(), or select() syscalls can be used to wait for the sync 47bf215546Sopenharmony_ci * file to change status, or (with a timeout of zero) to check its status. 48bf215546Sopenharmony_ci * 49bf215546Sopenharmony_ci * The functions below provide a few additional sync-specific operations. 50bf215546Sopenharmony_ci */ 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_ci/** 53bf215546Sopenharmony_ci * Merge two sync files. 54bf215546Sopenharmony_ci * 55bf215546Sopenharmony_ci * This produces a new sync file with the given name which has the union of the 56bf215546Sopenharmony_ci * two original sync file's fences; redundant fences may be removed. 57bf215546Sopenharmony_ci * 58bf215546Sopenharmony_ci * If one of the input sync files is signaled or invalid, then this function 59bf215546Sopenharmony_ci * may behave like dup(): the new file descriptor refers to the valid/unsignaled 60bf215546Sopenharmony_ci * sync file with its original name, rather than a new sync file. 61bf215546Sopenharmony_ci * 62bf215546Sopenharmony_ci * The original fences remain valid, and the caller is responsible for closing 63bf215546Sopenharmony_ci * them. 64bf215546Sopenharmony_ci * 65bf215546Sopenharmony_ci * Available since API level 26. 66bf215546Sopenharmony_ci */ 67bf215546Sopenharmony_ciint32_t sync_merge(const char* name, int32_t fd1, int32_t fd2) __INTRODUCED_IN(26); 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_ci/** 70bf215546Sopenharmony_ci * Retrieve detailed information about a sync file and its fences. 71bf215546Sopenharmony_ci * 72bf215546Sopenharmony_ci * The returned sync_file_info must be freed by calling sync_file_info_free(). 73bf215546Sopenharmony_ci * 74bf215546Sopenharmony_ci * Available since API level 26. 75bf215546Sopenharmony_ci */ 76bf215546Sopenharmony_cistruct sync_file_info* sync_file_info(int32_t fd) __INTRODUCED_IN(26); 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_ci/** 79bf215546Sopenharmony_ci * Get the array of fence infos from the sync file's info. 80bf215546Sopenharmony_ci * 81bf215546Sopenharmony_ci * The returned array is owned by the parent sync file info, and has 82bf215546Sopenharmony_ci * info->num_fences entries. 83bf215546Sopenharmony_ci * 84bf215546Sopenharmony_ci * Available since API level 26. 85bf215546Sopenharmony_ci */ 86bf215546Sopenharmony_cistatic inline struct sync_fence_info* sync_get_fence_info(const struct sync_file_info* info) { 87bf215546Sopenharmony_ci// This header should compile in C, but some C++ projects enable 88bf215546Sopenharmony_ci// warnings-as-error for C-style casts. 89bf215546Sopenharmony_ci#pragma GCC diagnostic push 90bf215546Sopenharmony_ci#pragma GCC diagnostic ignored "-Wold-style-cast" 91bf215546Sopenharmony_ci return (struct sync_fence_info *)(uintptr_t)(info->sync_fence_info); 92bf215546Sopenharmony_ci#pragma GCC diagnostic pop 93bf215546Sopenharmony_ci} 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_ci/** 96bf215546Sopenharmony_ci * Free a struct sync_file_info structure 97bf215546Sopenharmony_ci * 98bf215546Sopenharmony_ci * Available since API level 26. 99bf215546Sopenharmony_ci */ 100bf215546Sopenharmony_civoid sync_file_info_free(struct sync_file_info* info) __INTRODUCED_IN(26); 101bf215546Sopenharmony_ci 102bf215546Sopenharmony_ci__END_DECLS 103bf215546Sopenharmony_ci 104bf215546Sopenharmony_ci#endif /* ANDROID_SYNC_H */ 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_ci/** @} */ 107