openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

sync.h (2966B)


      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  * File: 	sync.h
      8  * Purpose: 	SAL thread definitions
      9  *
     10  * Note: the SAL mutex abstraction is required to allow the same mutex
     11  * to be taken recursively by the same thread without deadlock.
     12  */
     13 
     14 #ifndef _SAL_SYNC_H
     15 #define _SAL_SYNC_H
     16 
     17 typedef struct sal_mutex_s{
     18     char mutex_opaque_type;
     19 } *sal_mutex_t;
     20 
     21 typedef struct sal_sem_s{
     22     char sal_opaque_type;
     23 } *sal_sem_t;
     24 
     25 typedef struct sal_spinlock_s {
     26     char spinlock_opaque_type;
     27 } *sal_spinlock_t;
     28 
     29 #define sal_mutex_FOREVER	(-1)
     30 #define sal_mutex_NOWAIT	0
     31 
     32 #define sal_sem_FOREVER		(-1)
     33 #define sal_sem_BINARY		1
     34 #define sal_sem_COUNTING	0
     35 
     36 extern sal_mutex_t sal_mutex_create(char *desc);
     37 extern void sal_mutex_destroy(sal_mutex_t m);
     38 
     39 /*#define BROADCOM_DEBUG_MUTEX*/
     40 
     41 #ifndef BROADCOM_DEBUG_MUTEX
     42 extern int sal_mutex_take(sal_mutex_t m, int usec);
     43 extern int sal_mutex_give(sal_mutex_t m);
     44 #endif
     45 
     46 extern sal_sem_t sal_sem_create(char *desc, int binary, int initial_count);
     47 extern void sal_sem_destroy(sal_sem_t b);
     48 extern int sal_sem_take(sal_sem_t b, int usec);
     49 extern int sal_sem_give(sal_sem_t b);
     50 #ifdef BROADCOM_DEBUG
     51 #ifdef INCLUDE_BCM_SAL_PROFILE
     52 extern void
     53 sal_sem_resource_usage_get(unsigned int *sem_curr, unsigned int *sem_max);
     54 extern void
     55 sal_mutex_resource_usage_get(unsigned int *mutex_curr, unsigned int *mutex_max);
     56 #endif
     57 #endif
     58 
     59 
     60 
     61 #ifdef BROADCOM_DEBUG_MUTEX
     62 extern void sal_mutex_dbg_dump(void);
     63 
     64 extern int sal_mutex_take_bcm_debug(sal_mutex_t m, int usec, const char *take_loc, int line);
     65 extern int sal_mutex_give_bcm_debug(sal_mutex_t m, const char *give_loc, int line);
     66 
     67 
     68 #define sal_mutex_take(MUTEX, WAIT_TIME) sal_mutex_take_bcm_debug(MUTEX, WAIT_TIME, __FILE__, __LINE__)
     69 #define sal_mutex_give(MUTEX) sal_mutex_give_bcm_debug(MUTEX, __FILE__ , __LINE__)
     70 
     71 
     72 /*
     73 extern int sal_mutex_take_bcm_debug(sal_mutex_t m, int usec, const char *take_loc);
     74 extern int sal_mutex_give_bcm_debug(sal_mutex_t m, const char *);
     75 
     76 
     77 #define sal_mutex_take(MUTEX, WAIT_TIME) sal_mtx_take_bcm_debug(MUTEX, WAIT_TIME, __FILE__)
     78 
     79 #define sal_mutex_give(MUTEX) sal_mutex_give_bcm_debug(MUTEX, __LINE__ )
     80 */
     81 
     82 #endif
     83 
     84 /* SAL Global Lock - SDK internal use only */
     85 extern sal_mutex_t         sal_global_lock;
     86 int sal_global_lock_init(void);
     87 #define SAL_GLOBAL_LOCK \
     88     do { \
     89         if (sal_global_lock) { \
     90             sal_mutex_take(sal_global_lock, sal_mutex_FOREVER);\
     91         } \
     92     } while (0)
     93 #define SAL_GLOBAL_UNLOCK \
     94     do { \
     95         if (sal_global_lock) { \
     96             sal_mutex_give(sal_global_lock);\
     97         } \
     98     } while (0)
     99 
    100 extern sal_spinlock_t sal_spinlock_create(char *desc);
    101 extern int sal_spinlock_destroy(sal_spinlock_t lock);
    102 extern int sal_spinlock_lock(sal_spinlock_t lock);
    103 extern int sal_spinlock_unlock(sal_spinlock_t lock);
    104 
    105 #endif	/* !_SAL_SYNC_H */