mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-26 06:08:20 +00:00
libtest: Add support to seize/surrender objects
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
|
||||
#ifdef __rtems__
|
||||
#include <rtems/score/cpu.h>
|
||||
#include <rtems/rtems/status.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -2512,6 +2513,10 @@ typedef enum {
|
||||
} T_thread_timer_state;
|
||||
|
||||
T_thread_timer_state T_get_thread_timer_state(uint32_t);
|
||||
|
||||
void *T_seize_objects(rtems_status_code (*)(void *, uint32_t *), void *);
|
||||
|
||||
void T_surrender_objects(void **, rtems_status_code (*)(uint32_t));
|
||||
#endif /* __rtems__ */
|
||||
|
||||
/**
|
||||
|
||||
@@ -410,3 +410,57 @@ T_check_rtems_timers(T_event event, const char *name)
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
void *
|
||||
T_seize_objects(rtems_status_code (*create)(void *, uint32_t *), void *arg)
|
||||
{
|
||||
void *objects;
|
||||
|
||||
objects = NULL;
|
||||
|
||||
while (true) {
|
||||
rtems_status_code sc;
|
||||
rtems_id id;
|
||||
|
||||
id = 0;
|
||||
sc = (*create)(arg, &id);
|
||||
|
||||
if (sc == RTEMS_SUCCESSFUL) {
|
||||
const Objects_Information *info;
|
||||
Objects_Control *obj;
|
||||
|
||||
info = _Objects_Get_information_id(id);
|
||||
T_quiet_assert_not_null(info);
|
||||
obj = _Objects_Get_no_protection(id, info);
|
||||
T_quiet_assert_not_null(obj);
|
||||
obj->Node.next = objects;
|
||||
objects = obj;
|
||||
} else {
|
||||
T_quiet_rsc(sc, RTEMS_TOO_MANY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return objects;
|
||||
}
|
||||
|
||||
void
|
||||
T_surrender_objects(void **objects_p, rtems_status_code (*delete)(uint32_t))
|
||||
{
|
||||
void *objects;
|
||||
|
||||
objects = *objects_p;
|
||||
*objects_p = NULL;
|
||||
|
||||
while (objects != NULL) {
|
||||
Objects_Control *obj;
|
||||
rtems_status_code sc;
|
||||
|
||||
obj = objects;
|
||||
objects = _Chain_Next(&obj->Node);
|
||||
_Chain_Set_off_chain(&obj->Node);
|
||||
|
||||
sc = (*delete)(obj->id);
|
||||
T_quiet_rsc_success(sc);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user