Home | History | Annotate | Download | only in pppd
      1 #ifndef __SPINLOCK_H__
      2 #define __SPINLOCK_H__
      3 
      4 #ifdef HAVE_CONFIG_H
      5 #include <config.h>
      6 #endif
      7 
      8 #include "tdb.h"
      9 
     10 #ifdef USE_SPINLOCKS
     11 
     12 #define RWLOCK_BIAS 0x1000UL
     13 
     14 /* OS SPECIFIC */
     15 #define MAX_BUSY_LOOPS 1000
     16 #undef USE_SCHED_YIELD
     17 
     18 /* ARCH SPECIFIC */
     19 /* We should make sure these are padded to a cache line */
     20 #if defined(SPARC_SPINLOCKS)
     21 typedef volatile char spinlock_t;
     22 #elif defined(POWERPC_SPINLOCKS)
     23 typedef volatile unsigned long spinlock_t;
     24 #elif defined(INTEL_SPINLOCKS)
     25 typedef volatile int spinlock_t;
     26 #elif defined(MIPS_SPINLOCKS)
     27 typedef volatile unsigned long spinlock_t;
     28 #else
     29 #error Need to implement spinlock code in spinlock.h
     30 #endif
     31 
     32 typedef struct {
     33 	spinlock_t lock;
     34 	volatile int count;
     35 } tdb_rwlock_t;
     36 
     37 int tdb_spinlock(TDB_CONTEXT *tdb, int list, int rw_type);
     38 int tdb_spinunlock(TDB_CONTEXT *tdb, int list, int rw_type);
     39 int tdb_create_rwlocks(int fd, unsigned int hash_size);
     40 int tdb_clear_spinlocks(TDB_CONTEXT *tdb);
     41 
     42 #define TDB_SPINLOCK_SIZE(hash_size) (((hash_size) + 1) * sizeof(tdb_rwlock_t))
     43 
     44 #else /* !USE_SPINLOCKS */
     45 #if 0
     46 #define tdb_create_rwlocks(fd, hash_size) 0
     47 #define tdb_spinlock(tdb, list, rw_type) (-1)
     48 #define tdb_spinunlock(tdb, list, rw_type) (-1)
     49 #else
     50 int tdb_spinlock(TDB_CONTEXT *tdb, int list, int rw_type);
     51 int tdb_spinunlock(TDB_CONTEXT *tdb, int list, int rw_type);
     52 int tdb_create_rwlocks(int fd, unsigned int hash_size);
     53 #endif
     54 int tdb_clear_spinlocks(TDB_CONTEXT *tdb);
     55 #define TDB_SPINLOCK_SIZE(hash_size) 0
     56 
     57 #endif
     58 
     59 #endif
     60