MCPcopy Index your code
hub / github.com/RT-Thread/rt-thread / rt_object_init

Function rt_object_init

src/object.c:355–432  ·  view source on GitHub ↗

* @brief This function will initialize an object and add it to object system * management. * * @param object The specified object to be initialized. * The object pointer that needs to be initialized must point to * a specific object memory block, not a null pointer or a wild pointer. * * @param type The object type. The type of the object must be a enumera

Source from the content-addressed store, hash-verified

353 * uses '\0' as a terminal symbol.
354 */
355void rt_object_init(struct rt_object *object,
356 enum rt_object_class_type type,
357 const char *name)
358{
359 rt_base_t level;
360 rt_size_t obj_name_len;
361#ifdef RT_DEBUGING_ASSERT
362 struct rt_list_node *node = RT_NULL;
363#endif /* RT_DEBUGING_ASSERT */
364 struct rt_object_information *information;
365#ifdef RT_USING_MODULE
366 struct rt_dlmodule *module = dlmodule_self();
367#endif /* RT_USING_MODULE */
368
369 /* get object information */
370 information = rt_object_get_information(type);
371 RT_ASSERT(information != RT_NULL);
372
373#ifdef RT_DEBUGING_ASSERT
374 /* check object type to avoid re-initialization */
375
376 /* enter critical */
377 level = rt_spin_lock_irqsave(&(information->spinlock));
378 /* try to find object */
379 for (node = information->object_list.next;
380 node != &(information->object_list);
381 node = node->next)
382 {
383 struct rt_object *obj;
384
385 obj = rt_list_entry(node, struct rt_object, list);
386 RT_ASSERT(obj != object);
387 }
388 /* leave critical */
389 rt_spin_unlock_irqrestore(&(information->spinlock), level);
390#endif /* RT_DEBUGING_ASSERT */
391
392 /* initialize object's parameters */
393 /* set object type to static */
394 object->type = type | RT_Object_Class_Static;
395#if RT_NAME_MAX > 0
396 if (name)
397 {
398 obj_name_len = rt_strlen(name);
399 if(obj_name_len > RT_NAME_MAX - 1)
400 {
401 LOG_E("Object name %s exceeds RT_NAME_MAX=%d, consider increasing RT_NAME_MAX.", name, RT_NAME_MAX);
402 RT_ASSERT(obj_name_len <= RT_NAME_MAX - 1);
403 }
404 rt_memcpy(object->name, name, obj_name_len);
405 object->name[obj_name_len] = '\0';
406 }
407 else
408 {
409 object->name[0] = '\0';
410 }
411#else
412 object->name = name;

Callers 15

lwp_session_createFunction · 0.85
lwp_pgrp_createFunction · 0.85
rt_device_registerFunction · 0.85
rt_condvar_initFunction · 0.85
rt_sem_initFunction · 0.85
rt_mutex_initFunction · 0.85
rt_event_initFunction · 0.85
rt_mb_initFunction · 0.85
rt_mq_initFunction · 0.85
rt_mp_initFunction · 0.85
rt_slab_initFunction · 0.85
rt_smem_initFunction · 0.85

Calls 7

dlmodule_selfFunction · 0.85
rt_strlenFunction · 0.85
rt_memcpyFunction · 0.85
rt_list_insert_afterFunction · 0.85
rt_spin_lock_irqsaveFunction · 0.70

Tested by 4