1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #include <taihe/object.abi.h> 16 tobj_init(struct DataBlockHead * data_ptr,struct TypeInfo const * rtti_ptr)17void tobj_init(struct DataBlockHead *data_ptr, struct TypeInfo const *rtti_ptr) 18 { 19 data_ptr->rtti_ptr = rtti_ptr; 20 tref_set(&data_ptr->m_count, 1); 21 } 22 tobj_dup(struct DataBlockHead * data_ptr)23struct DataBlockHead *tobj_dup(struct DataBlockHead *data_ptr) 24 { 25 if (!data_ptr) { 26 return nullptr; 27 } 28 tref_inc(&data_ptr->m_count); 29 return data_ptr; 30 } 31 tobj_drop(struct DataBlockHead * data_ptr)32void tobj_drop(struct DataBlockHead *data_ptr) 33 { 34 if (!data_ptr) { 35 return; 36 } 37 if (tref_dec(&data_ptr->m_count)) { 38 data_ptr->rtti_ptr->free_fptr(data_ptr); 39 } 40 }