]>
Commit | Line | Data |
---|---|---|
b8e67377 BP |
1 | /* |
2 | * Copyright (c) 2013, 2014 Nicira, Inc. | |
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 | #ifndef FAT_RWLOCK_H | |
18 | #define FAT_RWLOCK_H 1 | |
19 | ||
20 | #include "compiler.h" | |
b19bab5b | 21 | #include "openvswitch/list.h" |
b8e67377 BP |
22 | #include "ovs-thread.h" |
23 | ||
24 | /* "Fat rwlock". | |
25 | * | |
26 | * This implements a reader-writer lock that uses a lot of memory (128 to 192 | |
27 | * bytes per thread that takes the lock) but avoids cache line bouncing when | |
28 | * taking the read side. Thus, a fat_rwlock is a good choice for rwlocks taken | |
29 | * frequently by readers. | |
30 | */ | |
31 | struct OVS_LOCKABLE fat_rwlock { | |
32 | ovsthread_key_t key; | |
33 | ||
34 | /* Contains "struct fat_rwlock_slot"s, one for each thread that has taken | |
35 | * this lock. Guarded by 'mutex'. */ | |
ca6ba700 | 36 | struct ovs_list threads OVS_GUARDED; |
b8e67377 BP |
37 | struct ovs_mutex mutex; |
38 | }; | |
39 | ||
40 | void fat_rwlock_init(struct fat_rwlock *); | |
41 | void fat_rwlock_destroy(struct fat_rwlock *); | |
42 | ||
43 | void fat_rwlock_rdlock(const struct fat_rwlock *rwlock) OVS_ACQ_RDLOCK(rwlock); | |
44 | int fat_rwlock_tryrdlock(const struct fat_rwlock *rwlock) | |
45 | OVS_TRY_RDLOCK(0, rwlock); | |
46 | void fat_rwlock_wrlock(const struct fat_rwlock *rwlock) OVS_ACQ_WRLOCK(rwlock); | |
47 | void fat_rwlock_unlock(const struct fat_rwlock *rwlock) OVS_RELEASES(rwlock); | |
48 | ||
49 | #endif /* fat-rwlock.h */ |