spinlock.h 1.5 KB

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