File: handle_lifetime.cpp.mako

package info (click to toggle)
level-zero 1.26.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,468 kB
  • sloc: cpp: 130,327; ansic: 16,197; python: 9,824; makefile: 4
file content (111 lines) | stat: -rw-r--r-- 4,349 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<%!
import re
from templates import helper as th
%><%
    n=namespace
    N=n.upper()

    x=tags['$x']
    X=x.upper()
%>/*
 * ***THIS FILE IS GENERATED. ***
 * See handle_lifetime.cpp.mako for modifications
 *
 * Copyright (C) 2019-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 * @file ${name}
 *
 */
#include "${x}_validation_layer.h"
#include "${x}_handle_lifetime.h"

namespace validation_layer
{
    %for obj in th.extract_objs(specs, r"function"):
    ## don't genrate function if it has no handles as parameters
    %if th.obj_traits.is_function_with_input_handles(obj):
    ${x}_result_t
    ${N}HandleLifetimeValidation::${th.make_func_name(n, tags, obj)}Prologue(
        %for line in th.make_param_lines(n, tags, obj):
        ${line}
        %endfor
        )
    { 
        <% func_name = th.make_func_name(n, tags, obj)
        %>
        %if re.match(r"\w+Destroy$", func_name):
        %for i, item in enumerate(th.get_loader_prologue(n, tags, obj, meta)):
        if (${item['name']} && context.handleLifetime->isHandleValid( ${item['name']} )){
            if (context.handleLifetime->hasDependents( ${item['name']} )){
                return ${X}_RESULT_ERROR_HANDLE_OBJECT_IN_USE;
            }
            context.handleLifetime->removeDependent( ${item['name']});
            context.handleLifetime->removeHandle( ${item['name']} );
        } else if (!context.handleLifetime->isHandleValid( ${item['name']} )) {
            return ${X}_RESULT_ERROR_INVALID_NULL_HANDLE;
        }
        %endfor
        %else: ## Not Destroy
        %for i, item in enumerate(th.get_loader_prologue(n, tags, obj, meta)):
        %if not 'range' in item:
        ## if item is optional, check if it is not null before checking if it is valid
        %if item['optional']:
        if (${item['name']} && !context.handleLifetime->isHandleValid( ${item['name']} )){
                return ${X}_RESULT_ERROR_INVALID_NULL_HANDLE;
        }
        %else:
        if ( !context.handleLifetime->isHandleValid( ${item['name']} )){
                return ${X}_RESULT_ERROR_INVALID_NULL_HANDLE;
        }
        %endif ## if item['optional']
        %if re.match(r"\w+CommandListAppend\w+$", func_name) and (0 == i) : ## i = 0, first parameter is command list
        if (!context.handleLifetime->isOpen( ${item['name']} )){
            return ${X}_RESULT_ERROR_INVALID_ARGUMENT;
        }
        %endif
        %if re.match(r"\w+CommandListClose$", func_name):
        context.handleLifetime->close( ${item['name']} );
        %endif
        %if re.match(r"\w+CommandListReset$", func_name):
        context.handleLifetime->reset( ${item['name']} );
        %endif
        %else: ## if 'range' in item
        for (size_t i = ${item['range'][0]}; ( nullptr != ${item['name']}) && (i < ${item['range'][1]}); ++i){
            if (!context.handleLifetime->isHandleValid( ${item['name']}[i] )){
                return ${X}_RESULT_ERROR_INVALID_NULL_HANDLE;
            }
        }
        %if re.match(r"\w+ExecuteCommandLists$", func_name) and (1 == i):
        for (size_t i = ${item['range'][0]}; ( nullptr != ${item['name']}) && (i < ${item['range'][1]}); ++i){
            if (context.handleLifetime->isOpen( ${item['name']}[i] )){
                return ${X}_RESULT_ERROR_INVALID_ARGUMENT;
            }
        }
        %endif
        %endif ## if 'range' in item
        %endfor ## for i, item in enumerate(th.get_loader_prologue(n, tags, obj, meta))
        %endif ## if re.match(r"\w+Destroy$", func_name)
        return ${X}_RESULT_SUCCESS;
    }
    %endif
    %endfor
%if n == 'ze':
    ze_result_t ZEHandleLifetimeValidation::zexCounterBasedEventCreate2Prologue(
        ze_context_handle_t hContext,   ///< [in] handle of the context object
        ze_device_handle_t hDevice,     ///< [in] handle of the device
        const void *desc,               ///< [in] pointer to counter-based event descriptor
        ze_event_handle_t *phEvent      ///< [out] pointer to handle of event object created
        )
    {
        if (!context.handleLifetime->isHandleValid(hContext)) {
            return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
        }
        if (!context.handleLifetime->isHandleValid(hDevice)) {
            return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
        }
        return ZE_RESULT_SUCCESS;
    }
%endif
}