diff options
| author | [email protected] <[email protected]> | 2010-11-17 23:35:13 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2010-11-17 23:35:13 +0000 |
| commit | 32f65989126fbe1fb31013c577c11bbaa46a5e72 (patch) | |
| tree | c321bc5fca933c6d181d4d236873e481b0f56218 /components/pthreads/sem.c | |
| parent | 5c148b670581c6b27b184ee28cd17a5b9deaf068 (diff) | |
add semaphore and sched implementation.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1056 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/pthreads/sem.c')
| -rw-r--r-- | components/pthreads/sem.c | 98 |
1 files changed, 0 insertions, 98 deletions
diff --git a/components/pthreads/sem.c b/components/pthreads/sem.c deleted file mode 100644 index e4cecab69a..0000000000 --- a/components/pthreads/sem.c +++ /dev/null @@ -1,98 +0,0 @@ -#include <errno.h> -#include <sys/fcntl.h> - -#include "sem.h" - -int sem_close(sem_t *sem) -{ -} - -int sem_destroy(sem_t *sem) -{ -} - -int sem_unlink(const char *name) -{ - return EACCES; -} - -int sem_getvalue(sem_t *sem, int *sval) -{ - RT_ASSERT(sem != RT_NULL); - if (sval) *sval = sem->value; -} - -int sem_init(sem_t *sem, int pshared, unsigned int value) -{ - RT_ASSERT(sem != RT_NULL); -} - -sem_t *sem_open(const char *name, int oflag, ...) -{ - rt_sem_t sem; - - sem = RT_NULL; - if (oflag == O_CREAT) - { - sem = rt_sem_create(name, 1, RT_IPC_FLAG_FIFO); - if (sem == RT_NULL) - rt_set_errno(ENOSPC); - } - - if (oflag == O_EXCL) - { - rt_enter_critical(); - /* find semaphore object */ - rt_exit_critical(); - - if (sem == RT_NULL) rt_set_errno(ENOENT); - } - - return sem; -} - -int sem_post(sem_t *sem) -{ - rt_sem_release(sem); -} - -int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout) -{ - rt_err_t result; - rt_int32_t tick; - - if (!sem || !abs_timeout) return EINVAL; - - /* calculate os tick */ - tick = abs_timeout->tv_sec/RT_TICK_PER_SECOND + (abs_timeout->tv_nsec/1000) * (1000/RT_TICK_PER_SECOND); - - result = rt_sem_take(sem, tick); - if (result == -RT_ETIMEOUT) return ETIMEDOUT; - if (result == RT_EOK) return 0; - - return EINTR; -} - -int sem_trywait(sem_t *sem) -{ - rt_err_t result; - - if (!sem) return EINVAL; - - result = rt_sem_take(sem, RT_WAITING_FOREVER); - if (result == -RT_ETIMEOUT) return EAGAIN; - if (result == RT_EOK) return 0; - - return EINTR; -} - -int sem_wait(sem_t *sem) -{ - rt_err_t result; - - result = rt_sem_take(sem, RT_WAITING_FOREVER); - if (result == RT_EOK) return 0; - - return EINTR; -} - |
