GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_host_stack_class_instance_create.c Lines: 9 9 100.0 %
Date: 2026-03-06 18:57:10 Branches: 4 4 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** USBX Component                                                        */
17
/**                                                                       */
18
/**   Host Stack                                                          */
19
/**                                                                       */
20
/**************************************************************************/
21
/**************************************************************************/
22
23
24
/* Include necessary system files.  */
25
26
#define UX_SOURCE_CODE
27
28
#include "ux_api.h"
29
#include "ux_host_stack.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _ux_host_stack_class_instance_create                PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function creates a new class instance for a class container.   */
45
/*    The instance of a class is not contained in the class code to       */
46
/*    reduce the class driver complexity. Rather, each class instance is  */
47
/*    attached to class container.                                        */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    class                                 Pointer to class              */
52
/*    class_instance                        Pointer to class instance     */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    Completion Status                                                   */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    None                                                                */
61
/*                                                                        */
62
/*  CALLED BY                                                             */
63
/*                                                                        */
64
/*    Application                                                         */
65
/*    USBX Components                                                     */
66
/*                                                                        */
67
/**************************************************************************/
68
991
UINT  _ux_host_stack_class_instance_create(UX_HOST_CLASS *host_class, VOID *class_instance)
69
{
70
71
VOID    **current_class_instance;
72
73
    /* If trace is enabled, insert this event into the trace buffer.  */
74
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_CLASS_INSTANCE_CREATE, host_class, class_instance, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
75
76
    /* If trace is enabled, register this object.  */
77
    UX_TRACE_OBJECT_REGISTER(UX_TRACE_HOST_OBJECT_TYPE_CLASS_INSTANCE, class_instance, 0, 0, 0)
78
79
    /* Start with the first class instance attached to the class container.  */
80
991
    current_class_instance =  host_class -> ux_host_class_first_instance;
81
82
    /* Check if there are any instances attached.  */
83
991
    if (current_class_instance == UX_NULL)
84
    {
85
86
        /* Since it is the first class, attach it to the class container.  */
87
767
        host_class -> ux_host_class_first_instance =  class_instance;
88
89
        /* Return successful completion.  */
90
767
        return(UX_SUCCESS);
91
    }
92
93
    /* Traverse the list of the class instances until we find the last class.  */
94
291
    while (*current_class_instance != UX_NULL)
95
    {
96
97
        /* Point to the next class instance.  */
98
67
        current_class_instance =  *current_class_instance;
99
    }
100
101
    /* We have reached the last class, hook the new class to the end. This way, we preserve
102
       the chronological order of the class instances.  */
103
224
    *current_class_instance =  class_instance;
104
105
    /* Return successful completion to caller.  */
106
224
    return(UX_SUCCESS);
107
}
108