| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
|
| 4 |
trivial database library |
| 5 |
|
| 6 |
Copyright (C) Anton Blanchard 2001 |
| 7 |
|
| 8 |
** NOTE! The following LGPL license applies to the tdb |
| 9 |
** library. This does NOT imply that all of Samba is released |
| 10 |
** under the LGPL |
| 11 |
|
| 12 |
This library is free software; you can redistribute it and/or |
| 13 |
modify it under the terms of the GNU Lesser General Public |
| 14 |
License as published by the Free Software Foundation; either |
| 15 |
version 2 of the License, or (at your option) any later version. |
| 16 |
|
| 17 |
This library is distributed in the hope that it will be useful, |
| 18 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 |
Lesser General Public License for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU Lesser General Public |
| 23 |
License along with this library; if not, write to the Free Software |
| 24 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
*/ |
| 26 |
|
| 27 |
#ifndef PPP_SPINLOCK_H |
| 28 |
#define PPP_SPINLOCK_H |
| 29 |
|
| 30 |
#include "pppdconf.h" |
| 31 |
|
| 32 |
#include "tdb.h" |
| 33 |
|
| 34 |
#ifdef USE_SPINLOCKS |
| 35 |
|
| 36 |
#define RWLOCK_BIAS 0x1000UL |
| 37 |
|
| 38 |
/* OS SPECIFIC */ |
| 39 |
#define MAX_BUSY_LOOPS 1000 |
| 40 |
#undef USE_SCHED_YIELD |
| 41 |
|
| 42 |
/* ARCH SPECIFIC */ |
| 43 |
/* We should make sure these are padded to a cache line */ |
| 44 |
#if defined(SPARC_SPINLOCKS) |
| 45 |
typedef volatile char spinlock_t; |
| 46 |
#elif defined(POWERPC_SPINLOCKS) |
| 47 |
typedef volatile unsigned long spinlock_t; |
| 48 |
#elif defined(INTEL_SPINLOCKS) |
| 49 |
typedef volatile int spinlock_t; |
| 50 |
#elif defined(MIPS_SPINLOCKS) |
| 51 |
typedef volatile unsigned long spinlock_t; |
| 52 |
#else |
| 53 |
#error Need to implement spinlock code in spinlock.h |
| 54 |
#endif |
| 55 |
|
| 56 |
typedef struct { |
| 57 |
spinlock_t lock; |
| 58 |
volatile int count; |
| 59 |
} tdb_rwlock_t; |
| 60 |
|
| 61 |
int tdb_spinlock(TDB_CONTEXT *tdb, int list, int rw_type); |
| 62 |
int tdb_spinunlock(TDB_CONTEXT *tdb, int list, int rw_type); |
| 63 |
int tdb_create_rwlocks(int fd, unsigned int hash_size); |
| 64 |
int tdb_clear_spinlocks(TDB_CONTEXT *tdb); |
| 65 |
|
| 66 |
#define TDB_SPINLOCK_SIZE(hash_size) (((hash_size) + 1) * sizeof(tdb_rwlock_t)) |
| 67 |
|
| 68 |
#else /* !USE_SPINLOCKS */ |
| 69 |
#if 0 |
| 70 |
#define tdb_create_rwlocks(fd, hash_size) 0 |
| 71 |
#define tdb_spinlock(tdb, list, rw_type) (-1) |
| 72 |
#define tdb_spinunlock(tdb, list, rw_type) (-1) |
| 73 |
#else |
| 74 |
int tdb_spinlock(TDB_CONTEXT *tdb, int list, int rw_type); |
| 75 |
int tdb_spinunlock(TDB_CONTEXT *tdb, int list, int rw_type); |
| 76 |
int tdb_create_rwlocks(int fd, unsigned int hash_size); |
| 77 |
#endif |
| 78 |
int tdb_clear_spinlocks(TDB_CONTEXT *tdb); |
| 79 |
#define TDB_SPINLOCK_SIZE(hash_size) 0 |
| 80 |
|
| 81 |
#endif |
| 82 |
|
| 83 |
#endif // PPP_SPINLOCK_H |