blob: b39441000e4ca7d245eb36c3a980c4a58cb414e1 [file] [log] [blame]
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001/*
2 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
3
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of Code Aurora Forum, Inc. nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef INCLUDE_LIBGENLOCK
31#define INCLUDE_LIBGENLOCK
32
33#include <cutils/native_handle.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/* Genlock lock types */
40typedef enum genlock_lock_type{
41 GENLOCK_READ_LOCK = 1<<0, // Read lock
42 GENLOCK_WRITE_LOCK = 1<<1, // Write lock
43}genlock_lock_type_t;
44
45/* Genlock return values */
46typedef enum genlock_status{
47 GENLOCK_NO_ERROR = 0,
48 GENLOCK_TIMEDOUT,
49 GENLOCK_FAILURE,
50} genlock_status_t;
51
52/* Genlock defines */
53#define GENLOCK_MAX_TIMEOUT 1000 // Max 1s timeout
54
55/*
56 * Create a genlock lock. The genlock lock file descriptor and the lock
57 * handle are stored in the buffer_handle.
58 *
59 * @param: handle of the buffer
60 * @return error status.
61 */
62genlock_status_t genlock_create_lock(native_handle_t *buffer_handle);
63
64
65/*
66 * Release a genlock lock associated with the handle.
67 *
68 * @param: handle of the buffer
69 * @return error status.
70 */
71genlock_status_t genlock_release_lock(native_handle_t *buffer_handle);
72
73/*
74 * Attach a lock to the buffer handle passed via an IPC.
75 *
76 * @param: handle of the buffer
77 * @return error status.
78 */
79genlock_status_t genlock_attach_lock(native_handle_t *buffer_handle);
80
81/*
82 * Lock the buffer specified by the buffer handle. The lock held by the buffer
83 * is specified by the lockType. This function will block if a write lock is
84 * requested on the buffer which has previously been locked for a read or write
85 * operation. A buffer can be locked by multiple clients for read. An optional
86 * timeout value can be specified. By default, there is no timeout.
87 *
88 * @param: handle of the buffer
89 * @param: type of lock to be acquired by the buffer.
90 * @param: timeout value in ms. GENLOCK_MAX_TIMEOUT is the maximum timeout value.
91 * @return error status.
92 */
93genlock_status_t genlock_lock_buffer(native_handle_t *buffer_handle,
94 genlock_lock_type_t lockType,
95 int timeout);
96
97/*
98 * Unlocks a buffer that has previously been locked by the client.
99 *
100 * @param: handle of the buffer to be unlocked.
101 * @return: error status.
102*/
103genlock_status_t genlock_unlock_buffer(native_handle_t *buffer_handle);
104
105/*
106 * Blocks the calling process until the lock held on the handle is unlocked.
107 *
108 * @param: handle of the buffer
109 * @param: timeout value for the wait.
110 * return: error status.
111 */
112genlock_status_t genlock_wait(native_handle_t *buffer_handle, int timeout);
113
114#ifdef __cplusplus
115}
116#endif
117
118#endif