Fix documentation for mutex.h
This commit is contained in:
parent
24db4eee8c
commit
71a632520b
@ -19,23 +19,35 @@
|
|||||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _MUTEX_H
|
#ifndef __MUTEX_H_
|
||||||
#define _MUTEX_H
|
#define __MUTEX_H_
|
||||||
|
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Mutex structure. Should never be modified by the user.
|
* @brief Mutex structure. Must never be modified by the user.
|
||||||
*/
|
*/
|
||||||
typedef struct mutex_t {
|
typedef struct mutex_t {
|
||||||
/* fields are managed by mutex functions, don't touch */
|
/* fields are managed by mutex functions, don't touch */
|
||||||
unsigned int val; // @internal
|
/**
|
||||||
queue_node_t queue; // @internal
|
* @internal
|
||||||
|
* @brief The value of the mutex; 0 if unlocked, 1 if locked. **Must
|
||||||
|
* never be changed by the user.**
|
||||||
|
*/
|
||||||
|
unsigned int val;
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @brief The process waiting queue of the mutex. **Must never be changed
|
||||||
|
* by the user.**
|
||||||
|
*/
|
||||||
|
queue_node_t queue;
|
||||||
} mutex_t;
|
} mutex_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initializes a mutex object
|
* @brief Initializes a mutex object.
|
||||||
* @param mutex pre-allocated mutex structure.
|
*
|
||||||
|
* @param[out] mutex pre-allocated mutex structure, must not be NULL.
|
||||||
|
*
|
||||||
* @return Always returns 1, always succeeds.
|
* @return Always returns 1, always succeeds.
|
||||||
*/
|
*/
|
||||||
int mutex_init(struct mutex_t *mutex);
|
int mutex_init(struct mutex_t *mutex);
|
||||||
@ -44,7 +56,8 @@ int mutex_init(struct mutex_t *mutex);
|
|||||||
/**
|
/**
|
||||||
* @brief Tries to get a mutex, non-blocking.
|
* @brief Tries to get a mutex, non-blocking.
|
||||||
*
|
*
|
||||||
* @param mutex Mutex-Object to lock. Has to be initialized first.
|
* @param[in] mutex Mutex object to lock. Has to be initialized first. Must not
|
||||||
|
* be NULL.
|
||||||
*
|
*
|
||||||
* @return 1 if mutex was unlocked, now it is locked.
|
* @return 1 if mutex was unlocked, now it is locked.
|
||||||
* @return 0 if the mutex was locked.
|
* @return 0 if the mutex was locked.
|
||||||
@ -54,7 +67,8 @@ int mutex_trylock(struct mutex_t *mutex);
|
|||||||
/**
|
/**
|
||||||
* @brief Tries to get a mutex, blocking.
|
* @brief Tries to get a mutex, blocking.
|
||||||
*
|
*
|
||||||
* @param mutex Mutex-Object to lock. Has to be initialized first.
|
* @param[in] mutex Mutex object to lock. Has to be initialized first. Must not
|
||||||
|
* be NULL.
|
||||||
*
|
*
|
||||||
* @return 1 getting the mutex was successful
|
* @return 1 getting the mutex was successful
|
||||||
* @return <1 there was an error.
|
* @return <1 there was an error.
|
||||||
@ -64,28 +78,16 @@ int mutex_lock(struct mutex_t *mutex);
|
|||||||
/**
|
/**
|
||||||
* @brief Unlocks the mutex.
|
* @brief Unlocks the mutex.
|
||||||
*
|
*
|
||||||
* @param mutex Mutex-Object to unlock.
|
* @param[in] mutex Mutex object to unlock, must not be NULL.
|
||||||
*/
|
*/
|
||||||
void mutex_unlock(struct mutex_t *mutex);
|
void mutex_unlock(struct mutex_t *mutex);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Unlocks the mutex and sends the current thread to sleep
|
* @brief Unlocks the mutex and sends the current thread to sleep
|
||||||
*
|
*
|
||||||
* @param mutex Mutex-Object to unlock.
|
* @param[in] mutex Mutex object to unlock, must not be NULL.
|
||||||
*/
|
*/
|
||||||
void mutex_unlock_and_sleep(struct mutex_t *mutex);
|
void mutex_unlock_and_sleep(struct mutex_t *mutex);
|
||||||
|
|
||||||
#define MUTEX_YIELD 1
|
#endif /* __MUTEX_H_ */
|
||||||
#define MUTEX_INISR 2
|
|
||||||
|
|
||||||
/**********************
|
|
||||||
* internal functions *
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
void mutex_wake_waiters(struct mutex_t *mutex, int yield);
|
|
||||||
void mutex_wait(struct mutex_t *mutex);
|
|
||||||
|
|
||||||
/*struct mutex_entry_t * mutex_create_entry(int prio, struct tcb *proc);*/
|
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
#endif /* _MUTEX_H */
|
|
||||||
|
|||||||
@ -33,6 +33,8 @@
|
|||||||
#define ENABLE_DEBUG (0)
|
#define ENABLE_DEBUG (0)
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
static void mutex_wait(struct mutex_t *mutex);
|
||||||
|
|
||||||
int mutex_init(struct mutex_t *mutex)
|
int mutex_init(struct mutex_t *mutex)
|
||||||
{
|
{
|
||||||
mutex->val = 0;
|
mutex->val = 0;
|
||||||
@ -62,7 +64,7 @@ int mutex_lock(struct mutex_t *mutex)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mutex_wait(struct mutex_t *mutex)
|
static void mutex_wait(struct mutex_t *mutex)
|
||||||
{
|
{
|
||||||
int irqstate = disableIRQ();
|
int irqstate = disableIRQ();
|
||||||
DEBUG("%s: Mutex in use. %u\n", active_thread->name, mutex->val);
|
DEBUG("%s: Mutex in use. %u\n", active_thread->name, mutex->val);
|
||||||
@ -131,6 +133,7 @@ void mutex_unlock_and_sleep(struct mutex_t *mutex)
|
|||||||
mutex->val = 0;
|
mutex->val = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG("%s: going to sleep.\n", active_thread->name);
|
DEBUG("%s: going to sleep.\n", active_thread->name);
|
||||||
sched_set_status((tcb_t *) active_thread, STATUS_SLEEPING);
|
sched_set_status((tcb_t *) active_thread, STATUS_SLEEPING);
|
||||||
restoreIRQ(irqstate);
|
restoreIRQ(irqstate);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user