wSemphone.c 1.6 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * 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/>.
 */

#define _DEFAULT_SOURCE
17

S
Shengliang Guan 已提交
18
#include "os.h"
S
slguan 已提交
19
#include "taosdef.h"
S
Shengliang Guan 已提交
20
#include "tglobal.h"
S
slguan 已提交
21
#include "ttimer.h"
S
Shengliang Guan 已提交
22
#include "tulog.h"
S
slguan 已提交
23
#include "tutil.h"
24
#include <windows.h>
S
Shengliang Guan 已提交
25

S
slguan 已提交
26 27
bool taosCheckPthreadValid(pthread_t thread) { return thread.p != NULL; }

28
void taosResetPthread(pthread_t* thread) { thread->p = 0; }
S
slguan 已提交
29

S
TD-2616  
Shengliang Guan 已提交
30
int64_t taosGetPthreadId(pthread_t thread) {
S
slguan 已提交
31
#ifdef PTW32_VERSION
S
TD-2616  
Shengliang Guan 已提交
32
  return pthread_getw32threadid_np(thread);
S
slguan 已提交
33
#else
S
TD-2616  
Shengliang Guan 已提交
34
  return (int64_t)thread;
S
slguan 已提交
35 36
#endif
}
37

38
int64_t taosGetSelfPthreadId() { return GetCurrentThreadId(); }
S
TD-2616  
Shengliang Guan 已提交
39

40
bool taosComparePthread(pthread_t first, pthread_t second) { return first.p == second.p; }
H
Haojun Liao 已提交
41

42
int32_t taosGetPId() { return GetCurrentProcessId(); }
H
Haojun Liao 已提交
43

44
int32_t taosGetCurrentAPPName(char* name, int32_t* len) {
H
Haojun Liao 已提交
45 46 47
  char filepath[1024] = {0};

  GetModuleFileName(NULL, filepath, MAX_PATH);
48 49 50 51
  char* sub = strrchr(filepath, '.');
  if (sub != NULL) {
    *sub = '\0';
  }
H
Haojun Liao 已提交
52 53 54
  strcpy(name, filepath);

  if (len != NULL) {
55
    *len = (int32_t)strlen(filepath);
H
Haojun Liao 已提交
56
  }
H
Haojun Liao 已提交
57 58

  return 0;
59
}