2012-01-14 02:45:44 +08:00
|
|
|
#ifndef __ASM_SEMAPHORE_H__
|
|
|
|
#define __ASM_SEMAPHORE_H__
|
|
|
|
|
2012-03-10 22:41:11 +08:00
|
|
|
#define CONFIG_JFFS2_SEMAPHORE 0 // no mutex, 1 use static, 2 use dynamic
|
2012-03-06 22:50:19 +08:00
|
|
|
#if CONFIG_JFFS2_SEMAPHORE == 0
|
2012-03-10 22:41:11 +08:00
|
|
|
//#include <cyg/hal/drv_api.h>
|
2012-03-06 22:50:19 +08:00
|
|
|
|
|
|
|
struct semaphore {
|
2012-03-10 22:41:11 +08:00
|
|
|
int x;
|
2012-03-06 22:50:19 +08:00
|
|
|
};
|
|
|
|
|
2012-03-10 22:41:11 +08:00
|
|
|
#define DECLARE_MUTEX(x)
|
|
|
|
#define DECLARE_MUTEX_LOCKED(x)
|
2012-03-06 22:50:19 +08:00
|
|
|
|
2012-03-10 22:41:11 +08:00
|
|
|
#define init_MUTEX(sem)
|
|
|
|
#define init_MUTEX_LOCKED(sem)
|
|
|
|
#define down(sem)
|
|
|
|
#define down_interruptible(sem) 0
|
|
|
|
#define down_trylock(sem)
|
|
|
|
#define up(sem)
|
2012-03-06 22:50:19 +08:00
|
|
|
|
|
|
|
#elif CONFIG_JFFS2_SEMAPHORE == 1
|
|
|
|
#include <rtthread.h>
|
|
|
|
|
|
|
|
struct semaphore {
|
|
|
|
struct rt_mutex mutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DECLARE_MUTEX(x)
|
|
|
|
#define DECLARE_MUTEX_LOCKED(x)
|
|
|
|
rt_inline void init_MUTEX(struct semaphore * sem)
|
|
|
|
{
|
|
|
|
if (rt_mutex_init((rt_mutex_t)sem, "mutex", RT_IPC_FLAG_FIFO) == RT_EOK)
|
|
|
|
{
|
|
|
|
/* detach the object from system object container */
|
|
|
|
rt_object_detach(&(((rt_mutex_t)sem)->parent.parent));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rt_kprintf("get an error at %s:%d \n", __FUNCTION__, __LINE__);
|
|
|
|
RT_ASSERT(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
rt_inline void init_MUTEX_LOCKED(struct semaphore * sem)
|
|
|
|
{
|
2012-03-10 22:41:11 +08:00
|
|
|
rt_enter_critical();
|
2012-03-06 22:50:19 +08:00
|
|
|
if (rt_mutex_init((rt_mutex_t)sem, "mutex", RT_IPC_FLAG_FIFO) == RT_EOK)
|
|
|
|
{
|
|
|
|
/* detach the object from system object container */
|
|
|
|
rt_object_detach(&(((rt_mutex_t)sem)->parent.parent));
|
2012-03-10 22:41:11 +08:00
|
|
|
rt_exit_critical();
|
2012-03-06 22:50:19 +08:00
|
|
|
rt_mutex_take((rt_mutex_t)sem, RT_WAITING_FOREVER);
|
|
|
|
return;
|
|
|
|
}
|
2012-03-10 22:41:11 +08:00
|
|
|
rt_exit_critical();
|
|
|
|
|
2012-03-06 22:50:19 +08:00
|
|
|
rt_kprintf("get an error at %s:%d \n", __FUNCTION__, __LINE__);
|
|
|
|
RT_ASSERT(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
rt_inline down(struct semaphore * sem)
|
|
|
|
{
|
|
|
|
rt_mutex_take((rt_mutex_t)sem, RT_WAITING_FOREVER);
|
|
|
|
}
|
|
|
|
rt_inline int down_interruptible(struct semaphore* sem)
|
|
|
|
{
|
|
|
|
rt_mutex_take((rt_mutex_t)sem, RT_WAITING_FOREVER);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rt_inline up(struct semaphore * sem)
|
|
|
|
{
|
|
|
|
rt_mutex_release((rt_mutex_t)sem);
|
|
|
|
}
|
|
|
|
#elif CONFIG_JFFS2_SEMAPHORE == 2
|
2012-01-14 02:45:44 +08:00
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
|
|
|
|
struct semaphore {
|
2012-03-06 22:50:19 +08:00
|
|
|
rt_mutex_t mutex;
|
2012-01-14 02:45:44 +08:00
|
|
|
};
|
2012-03-06 22:50:19 +08:00
|
|
|
|
|
|
|
#define DECLARE_MUTEX(x)
|
|
|
|
#define DECLARE_MUTEX_LOCKED(x)
|
|
|
|
|
|
|
|
rt_inline void init_MUTEX(struct semaphore * sem)
|
|
|
|
{
|
|
|
|
sem->mutex = rt_mutex_create("mutex", RT_IPC_FLAG_FIFO);
|
|
|
|
}
|
|
|
|
rt_inline init_MUTEX_LOCKED(struct semaphore * sem)
|
|
|
|
{
|
|
|
|
sem->mutex = rt_mutex_create("mutex", RT_IPC_FLAG_FIFO);
|
|
|
|
rt_mutex_take(sem->mutex, RT_WAITING_FOREVER);
|
|
|
|
}
|
|
|
|
rt_inline down(struct semaphore * sem)
|
|
|
|
{
|
|
|
|
rt_mutex_take(sem->mutex, RT_WAITING_FOREVER);
|
|
|
|
}
|
|
|
|
rt_inline int down_interruptible(struct semaphore* sem)
|
|
|
|
{
|
|
|
|
rt_mutex_take(sem->mutex, RT_WAITING_FOREVER);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-01-14 02:45:44 +08:00
|
|
|
/*
|
|
|
|
Attempt to lock the mutex pointed to by the mutex argument without waiting.
|
|
|
|
If the mutex is already locked by some other thread then this function
|
|
|
|
returns FALSE. If the function can lock the mutex without waiting, then
|
|
|
|
TRUE is returned.
|
|
|
|
void cyg_drv_mutex_unlock( cyg_drv_mutex *mutex )
|
|
|
|
*/
|
|
|
|
|
2012-03-06 22:50:19 +08:00
|
|
|
//#define down_trylock(struct semaphore * sem) rt_mutex_take((rt_mutex_t)sem, RT_WAITING_NO)
|
|
|
|
rt_inline up(struct semaphore * sem)
|
|
|
|
{
|
|
|
|
rt_mutex_release(sem->mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
#error "CONFIG_JFFS2_SEMAPHORE should be 0, 1 or 2"
|
|
|
|
#endif
|
|
|
|
|
2012-01-14 02:45:44 +08:00
|
|
|
#endif /* __ASM_SEMAPHORE_H__ */
|