lock.h (1335B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * This file contains locking definitions internal to the BCM library. 8 */ 9 10 #ifndef _BCM_INT_LOCK_H 11 #define _BCM_INT_LOCK_H 12 13 #include <bcm/types.h> 14 15 #include <sal/core/sync.h> 16 17 /* 18 * BCM Locking 19 * 20 * (1) BCM calls that need to perform multiple operations on a resource 21 * atomically, such as read/modify/write a table entry, should lock 22 * the resource. 23 * 24 * (2) Module routines that call outside their module must be very 25 * careful to avoid deadlocks. Deadlocks result from two or more 26 * threads trying to take the same locks but in a different order. 27 * 28 * (3) BCM_LOCK should be taken during all major configuration changes 29 * to prevent corruption that could result if two tasks (like a CLI 30 * and a SNMP server) try to alter configuration simultaneously. 31 * 32 * (4) BCM_LOCK may also be useful in avoiding deadlocks if multiple 33 * resources are needed. 34 */ 35 36 extern sal_mutex_t _bcm_lock[BCM_MAX_NUM_UNITS]; 37 38 #define BCM_LOCK(unit) \ 39 sal_mutex_take(_bcm_lock[unit], sal_mutex_FOREVER) 40 41 #define BCM_UNLOCK(unit) \ 42 sal_mutex_give(_bcm_lock[unit]) 43 44 #endif /* !_BCM_INT_LOCK_H */