2009-12-07 16:26:39 +00:00
|
|
|
/*
|
2009-12-08 15:53:01 +00:00
|
|
|
* Copyright (C) 2008-2009 Tobias Brunner
|
2009-12-07 16:26:39 +00:00
|
|
|
* Copyright (C) 2008 Martin Willi
|
2018-05-23 14:04:50 +00:00
|
|
|
* HSR Hochschule fuer Technik Rapperswil
|
2009-12-07 16:26:39 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
2009-12-08 15:53:01 +00:00
|
|
|
/**
|
|
|
|
* @defgroup rwlock rwlock
|
|
|
|
* @{ @ingroup threading
|
|
|
|
*/
|
|
|
|
|
2009-12-07 16:26:39 +00:00
|
|
|
#ifndef THREADING_RWLOCK_H_
|
|
|
|
#define THREADING_RWLOCK_H_
|
|
|
|
|
2009-12-08 15:53:01 +00:00
|
|
|
typedef struct rwlock_t rwlock_t;
|
|
|
|
typedef enum rwlock_type_t rwlock_type_t;
|
2009-12-07 16:26:39 +00:00
|
|
|
|
|
|
|
/**
|
2009-12-08 15:53:01 +00:00
|
|
|
* Type of read-write lock.
|
2009-12-07 16:26:39 +00:00
|
|
|
*/
|
2009-12-08 15:53:01 +00:00
|
|
|
enum rwlock_type_t {
|
|
|
|
/** default condvar */
|
|
|
|
RWLOCK_TYPE_DEFAULT = 0,
|
|
|
|
};
|
2009-12-08 13:06:11 +00:00
|
|
|
|
2009-12-08 15:53:01 +00:00
|
|
|
/**
|
|
|
|
* Read-Write lock wrapper.
|
|
|
|
*/
|
|
|
|
struct rwlock_t {
|
2009-12-08 13:06:11 +00:00
|
|
|
|
|
|
|
/**
|
2009-12-08 15:53:01 +00:00
|
|
|
* Acquire the read lock.
|
2009-12-08 13:06:11 +00:00
|
|
|
*/
|
2009-12-08 15:53:01 +00:00
|
|
|
void (*read_lock)(rwlock_t *this);
|
2009-12-08 13:06:11 +00:00
|
|
|
|
|
|
|
/**
|
2009-12-08 15:53:01 +00:00
|
|
|
* Acquire the write lock.
|
2009-12-08 13:06:11 +00:00
|
|
|
*/
|
2009-12-08 15:53:01 +00:00
|
|
|
void (*write_lock)(rwlock_t *this);
|
2009-12-08 13:06:11 +00:00
|
|
|
|
|
|
|
/**
|
2009-12-08 15:53:01 +00:00
|
|
|
* Try to acquire the write lock.
|
|
|
|
*
|
|
|
|
* Never blocks, but returns FALSE if the lock was already occupied.
|
|
|
|
*
|
|
|
|
* @return TRUE if lock acquired
|
2009-12-08 13:06:11 +00:00
|
|
|
*/
|
2009-12-08 15:53:01 +00:00
|
|
|
bool (*try_write_lock)(rwlock_t *this);
|
2009-12-08 13:06:11 +00:00
|
|
|
|
|
|
|
/**
|
2009-12-08 15:53:01 +00:00
|
|
|
* Release any acquired lock.
|
2009-12-08 13:06:11 +00:00
|
|
|
*/
|
2009-12-08 15:53:01 +00:00
|
|
|
void (*unlock)(rwlock_t *this);
|
2009-12-08 13:06:11 +00:00
|
|
|
|
2009-12-07 16:26:39 +00:00
|
|
|
/**
|
2009-12-08 15:53:01 +00:00
|
|
|
* Destroy the read-write lock.
|
2009-12-07 16:26:39 +00:00
|
|
|
*/
|
2009-12-08 15:53:01 +00:00
|
|
|
void (*destroy)(rwlock_t *this);
|
2009-12-07 16:26:39 +00:00
|
|
|
};
|
|
|
|
|
2009-12-08 15:53:01 +00:00
|
|
|
/**
|
|
|
|
* Create a read-write lock instance.
|
|
|
|
*
|
|
|
|
* @param type type of rwlock to create
|
|
|
|
* @return unlocked rwlock instance
|
|
|
|
*/
|
|
|
|
rwlock_t *rwlock_create(rwlock_type_t type);
|
|
|
|
|
|
|
|
#endif /** THREADING_RWLOCK_H_ @} */
|
2009-12-07 16:26:39 +00:00
|
|
|
|