1 /*
2 * Copyright (C) 2015-2017 Alibaba Group Holding Limited
3 */
4
5 #include "k_api.h"
6
7 #if (RHINO_CONFIG_TASK_SEM > 0)
krhino_task_sem_create(ktask_t * task,ksem_t * sem,const name_t * name,size_t count)8 kstat_t krhino_task_sem_create(ktask_t *task, ksem_t *sem, const name_t *name,
9 size_t count)
10 {
11 kstat_t ret;
12
13 if (task == NULL) {
14 return RHINO_NULL_PTR;
15 }
16
17 NULL_PARA_CHK(task);
18
19 ret = krhino_sem_create(sem, name, count);
20 if (ret == RHINO_SUCCESS) {
21 task->task_sem_obj = sem;
22 } else {
23 task->task_sem_obj = NULL;
24 }
25
26 return ret;
27 }
28
krhino_task_sem_del(ktask_t * task)29 kstat_t krhino_task_sem_del(ktask_t *task)
30 {
31 NULL_PARA_CHK(task);
32
33 return krhino_sem_del(task->task_sem_obj);
34 }
35
krhino_task_sem_give(ktask_t * task)36 kstat_t krhino_task_sem_give(ktask_t *task)
37 {
38 NULL_PARA_CHK(task);
39
40 return krhino_sem_give(task->task_sem_obj);
41 }
42
krhino_task_sem_take(tick_t ticks)43 kstat_t krhino_task_sem_take(tick_t ticks)
44 {
45 return krhino_sem_take(krhino_cur_task_get()->task_sem_obj, ticks);
46 }
47
krhino_task_sem_count_set(ktask_t * task,sem_count_t count)48 kstat_t krhino_task_sem_count_set(ktask_t *task, sem_count_t count)
49 {
50 NULL_PARA_CHK(task);
51
52 return krhino_sem_count_set(task->task_sem_obj, count);
53 }
54
krhino_task_sem_count_get(ktask_t * task,sem_count_t * count)55 kstat_t krhino_task_sem_count_get(ktask_t *task, sem_count_t *count)
56 {
57 NULL_PARA_CHK(task);
58
59 return krhino_sem_count_get(task->task_sem_obj, count);
60 }
61 #endif
62
63