tfunctional.c 1.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

S
func  
Shengliang Guan 已提交
16
#define _DEFAULT_SOURCE
17 18
#include "tfunctional.h"

A
Alex Duan 已提交
19 20 21
FORCE_INLINE void* genericInvoke(tGenericSavedFunc* const pSavedFunc) { return pSavedFunc->func(pSavedFunc->args); }

#if 0
S
func  
Shengliang Guan 已提交
22
tGenericSavedFunc* genericSavedFuncInit(GenericVaFunc func, int32_t numOfArgs) {
wafwerar's avatar
wafwerar 已提交
23
  tGenericSavedFunc* pSavedFunc = taosMemoryMalloc(sizeof(tGenericSavedFunc) + numOfArgs * (sizeof(void*)));
S
func  
Shengliang Guan 已提交
24
  if (pSavedFunc == NULL) return NULL;
25 26 27 28
  pSavedFunc->func = func;
  return pSavedFunc;
}

S
func  
Shengliang Guan 已提交
29
tI32SavedFunc* i32SavedFuncInit(I32VaFunc func, int32_t numOfArgs) {
wafwerar's avatar
wafwerar 已提交
30
  tI32SavedFunc* pSavedFunc = taosMemoryMalloc(sizeof(tI32SavedFunc) + numOfArgs * sizeof(void*));
S
func  
Shengliang Guan 已提交
31
  if (pSavedFunc == NULL) return NULL;
32 33 34 35
  pSavedFunc->func = func;
  return pSavedFunc;
}

S
func  
Shengliang Guan 已提交
36
tVoidSavedFunc* voidSavedFuncInit(VoidVaFunc func, int32_t numOfArgs) {
wafwerar's avatar
wafwerar 已提交
37
  tVoidSavedFunc* pSavedFunc = taosMemoryMalloc(sizeof(tVoidSavedFunc) + numOfArgs * sizeof(void*));
S
func  
Shengliang Guan 已提交
38
  if (pSavedFunc == NULL) return NULL;
39 40 41 42
  pSavedFunc->func = func;
  return pSavedFunc;
}

S
func  
Shengliang Guan 已提交
43
FORCE_INLINE int32_t i32Invoke(tI32SavedFunc* const pSavedFunc) { return pSavedFunc->func(pSavedFunc->args); }
44 45

FORCE_INLINE void voidInvoke(tVoidSavedFunc* const pSavedFunc) {
S
func  
Shengliang Guan 已提交
46
  if (pSavedFunc) pSavedFunc->func(pSavedFunc->args);
47
}
A
Alex Duan 已提交
48
#endif