locks.h revision 369f3138f19f7102bf0f98b890ab84c8df633a93
1/*
2 * Copyright (C) 2010 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/** \file locks.h Mutual exclusion and condition variables */
18
19extern void object_lock_exclusive(IObject *this);
20extern void object_unlock_exclusive(IObject *this);
21extern void object_unlock_exclusive_attributes(IObject *this, unsigned attr);
22extern void object_cond_wait(IObject *this);
23extern void object_cond_signal(IObject *this);
24extern void object_cond_broadcast(IObject *this);
25
26// Currently shared locks are implemented as exclusive, but don't count on it
27
28#define object_lock_shared(this)   object_lock_exclusive(this)
29#define object_unlock_shared(this) object_unlock_exclusive(this)
30
31// Currently interface locks are actually on whole object, but don't count on it.
32// These operations are undefined on IObject, as it lacks an mThis.
33// If you have an IObject, then use the object_ functions instead.
34
35#define interface_lock_exclusive(this)   object_lock_exclusive(InterfaceToIObject(this))
36#define interface_unlock_exclusive(this) object_unlock_exclusive(InterfaceToIObject(this))
37#define interface_unlock_exclusive_attributes(this, attr) \
38    object_unlock_exclusive_attributes(InterfaceToIObject(this), (attr))
39#define interface_lock_shared(this)      object_lock_shared(InterfaceToIObject(this))
40#define interface_unlock_shared(this)    object_unlock_shared(InterfaceToIObject(this))
41#define interface_cond_wait(this)        object_cond_wait(InterfaceToIObject(this))
42#define interface_cond_signal(this)      object_cond_signal(InterfaceToIObject(this))
43#define interface_cond_broadcast(this)   object_cond_broadcast(InterfaceToIObject(this))
44
45// Peek and poke are an optimization for small atomic fields that don't "matter"
46
47#define object_lock_peek(this)      /* object_lock_shared(this) */
48#define object_unlock_peek(this)    /* object_unlock_shared(this) */
49#define interface_lock_poke(this)   /* interface_lock_exclusive(this) */
50#define interface_unlock_poke(this) /* interface_unlock_exclusive(this) */
51#define interface_lock_peek(this)   /* interface_lock_shared(this) */
52#define interface_unlock_peek(this) /* interface_unlock_shared(this) */
53