* Most of these functions abort the process with an error message on any
* error. ovs_mutex_trylock() is an exception: it passes through a 0 or EBUSY
* return value to the caller and aborts on any other error. */
-void ovs_mutex_init(const struct ovs_mutex *);
-void ovs_mutex_init_recursive(const struct ovs_mutex *);
-void ovs_mutex_init_adaptive(const struct ovs_mutex *);
-void ovs_mutex_destroy(const struct ovs_mutex *);
+void ovs_mutex_init(struct ovs_mutex *);
+void ovs_mutex_init_recursive(struct ovs_mutex *);
+void ovs_mutex_init_adaptive(struct ovs_mutex *);
+void ovs_mutex_destroy(struct ovs_mutex *);
void ovs_mutex_unlock(const struct ovs_mutex *mutex) OVS_RELEASES(mutex);
void ovs_mutex_lock_at(const struct ovs_mutex *mutex, const char *where)
OVS_ACQUIRES(mutex);
OVS_REQUIRES(mutex);
#ifdef HAVE_PTHREAD_SPIN_LOCK
-void ovs_spin_init(const struct ovs_spin *);
-void ovs_spin_destroy(const struct ovs_spin *);
+void ovs_spin_init(struct ovs_spin *);
+void ovs_spin_destroy(struct ovs_spin *);
void ovs_spin_unlock(const struct ovs_spin *spin) OVS_RELEASES(spin);
void ovs_spin_lock_at(const struct ovs_spin *spin, const char *where)
OVS_ACQUIRES(spin);
TRY_LOCK_FUNCTION(spin, trylock);
#endif
-#define UNLOCK_FUNCTION(TYPE, FUN, WHERE) \
+#define UNLOCK_FUNCTION(TYPE, FUN, WHERE, CONST) \
void \
- ovs_##TYPE##_##FUN(const struct ovs_##TYPE *l_) \
+ ovs_##TYPE##_##FUN(CONST struct ovs_##TYPE *l_) \
OVS_NO_THREAD_SAFETY_ANALYSIS \
{ \
struct ovs_##TYPE *l = CONST_CAST(struct ovs_##TYPE *, l_); \
ovs_strerror(error)); \
} \
}
-UNLOCK_FUNCTION(mutex, unlock, "<unlocked>");
-UNLOCK_FUNCTION(mutex, destroy, NULL);
-UNLOCK_FUNCTION(rwlock, unlock, "<unlocked>");
-UNLOCK_FUNCTION(rwlock, destroy, NULL);
+UNLOCK_FUNCTION(mutex, unlock, "<unlocked>", const);
+UNLOCK_FUNCTION(mutex, destroy, NULL, /* non-const */);
+UNLOCK_FUNCTION(rwlock, unlock, "<unlocked>", const);
+UNLOCK_FUNCTION(rwlock, destroy, NULL, /* non-const */);
#ifdef HAVE_PTHREAD_SPIN_LOCK
-UNLOCK_FUNCTION(spin, unlock, "<unlocked>");
-UNLOCK_FUNCTION(spin, destroy, NULL);
+UNLOCK_FUNCTION(spin, unlock, "<unlocked>", const);
+UNLOCK_FUNCTION(spin, destroy, NULL, /* non-const */);
#endif
#define XPTHREAD_FUNC1(FUNCTION, PARAM1) \
#endif
static void
-ovs_mutex_init__(const struct ovs_mutex *l_, int type)
+ovs_mutex_init__(struct ovs_mutex *l, int type)
{
- struct ovs_mutex *l = CONST_CAST(struct ovs_mutex *, l_);
pthread_mutexattr_t attr;
int error;
/* Initializes 'mutex' as a normal (non-recursive) mutex. */
void
-ovs_mutex_init(const struct ovs_mutex *mutex)
+ovs_mutex_init(struct ovs_mutex *mutex)
{
ovs_mutex_init__(mutex, PTHREAD_MUTEX_ERRORCHECK);
}
/* Initializes 'mutex' as a recursive mutex. */
void
-ovs_mutex_init_recursive(const struct ovs_mutex *mutex)
+ovs_mutex_init_recursive(struct ovs_mutex *mutex)
{
ovs_mutex_init__(mutex, PTHREAD_MUTEX_RECURSIVE);
}
/* Initializes 'mutex' as a recursive mutex. */
void
-ovs_mutex_init_adaptive(const struct ovs_mutex *mutex)
+ovs_mutex_init_adaptive(struct ovs_mutex *mutex)
{
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
ovs_mutex_init__(mutex, PTHREAD_MUTEX_ADAPTIVE_NP);
}
void
-ovs_rwlock_init(const struct ovs_rwlock *l_)
+ovs_rwlock_init(struct ovs_rwlock *l)
{
- struct ovs_rwlock *l = CONST_CAST(struct ovs_rwlock *, l_);
int error;
l->where = "<unlocked>";
#ifdef HAVE_PTHREAD_SPIN_LOCK
static void
-ovs_spin_init__(const struct ovs_spin *l_, int pshared)
+ovs_spin_init__(struct ovs_spin *l, int pshared)
{
- struct ovs_spin *l = CONST_CAST(struct ovs_spin *, l_);
int error;
l->where = "<unlocked>";
}
void
-ovs_spin_init(const struct ovs_spin *spin)
+ovs_spin_init(struct ovs_spin *spin)
{
ovs_spin_init__(spin, PTHREAD_PROCESS_PRIVATE);
}