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"

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

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

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

S
func  
Shengliang Guan 已提交
40
FORCE_INLINE void* genericInvoke(tGenericSavedFunc* const pSavedFunc) { return pSavedFunc->func(pSavedFunc->args); }
41

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

FORCE_INLINE void voidInvoke(tVoidSavedFunc* const pSavedFunc) {
S
func  
Shengliang Guan 已提交
45
  if (pSavedFunc) pSavedFunc->func(pSavedFunc->args);
46
}