| 19 | #include <rtdbg.h> |
| 20 | |
| 21 | rt_session_t lwp_session_find(pid_t sid) |
| 22 | { |
| 23 | rt_base_t level; |
| 24 | rt_session_t session = RT_NULL; |
| 25 | rt_list_t *node = RT_NULL; |
| 26 | struct rt_object_information *information = RT_NULL; |
| 27 | |
| 28 | information = rt_object_get_information(RT_Object_Class_Session); |
| 29 | |
| 30 | /* parameter check */ |
| 31 | if ((sid < 0) || (information == RT_NULL)) |
| 32 | { |
| 33 | return RT_NULL; |
| 34 | } |
| 35 | |
| 36 | if (sid == 0) |
| 37 | { |
| 38 | sid = lwp_getpid(); |
| 39 | } |
| 40 | |
| 41 | /* enter critical */ |
| 42 | level = rt_spin_lock_irqsave(&(information->spinlock)); |
| 43 | |
| 44 | /* try to find session */ |
| 45 | rt_list_for_each(node, &(information->object_list)) |
| 46 | { |
| 47 | session = (rt_session_t)rt_list_entry(node, struct rt_object, list); |
| 48 | if (session->sid == sid) |
| 49 | { |
| 50 | rt_spin_unlock_irqrestore(&(information->spinlock), level); |
| 51 | |
| 52 | return session; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | rt_spin_unlock_irqrestore(&(information->spinlock), level); |
| 57 | |
| 58 | return RT_NULL; |
| 59 | } |
| 60 | |
| 61 | rt_session_t lwp_session_create(rt_lwp_t leader) |
| 62 | { |
no test coverage detected