2 * Copyright (c) 2013, 2014 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #define FAT_RWLOCK_H 1
21 #include "openvswitch/list.h"
22 #include "ovs-thread.h"
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.
31 struct OVS_LOCKABLE fat_rwlock
{
34 /* Contains "struct fat_rwlock_slot"s, one for each thread that has taken
35 * this lock. Guarded by 'mutex'. */
36 struct ovs_list threads OVS_GUARDED
;
37 struct ovs_mutex mutex
;
40 void fat_rwlock_init(struct fat_rwlock
*);
41 void fat_rwlock_destroy(struct fat_rwlock
*);
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
);
49 #endif /* fat-rwlock.h */