• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / taos-tools / 13135713772

04 Feb 2025 12:42PM UTC coverage: 75.074% (-0.03%) from 75.104%
13135713772

Pull #843

github

web-flow
Merge 7e4333581 into 85e3589c2
Pull Request #843: taos-tools Merge 3.0 to Main Branch

433 of 593 new or added lines in 6 files covered. (73.02%)

41 existing lines in 6 files now uncovered.

12457 of 16593 relevant lines covered (75.07%)

327996.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.62
/src/benchLog.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the MIT license as published by the Free Software
6
 * Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12

13
#include "bench.h"
14
#include "benchLog.h"
15

16

17
//
18
// -----------  log -----------
19
//
20

21

22
// --------  OS IMPL
23
#ifdef WINDOWS
24
typedef CRITICAL_SECTION     TdThreadMutex;      // windows api
25
typedef HANDLE               TdThreadMutexAttr;  // windows api
26
#else
27
typedef pthread_mutex_t      TdThreadMutex;
28
typedef pthread_mutexattr_t  TdThreadMutexAttr;
29
#endif
30

31

32
int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr) {
42,201✔
33
#ifdef WINDOWS
34
  /**
35
   * Windows Server 2003 and Windows XP:  In low memory situations, InitializeCriticalSection can raise a
36
   * STATUS_NO_MEMORY exception. Starting with Windows Vista, this exception was eliminated and
37
   * InitializeCriticalSection always succeeds, even in low memory situations.
38
   */
39
  InitializeCriticalSection(mutex);
40
  return 0;
41
#else
42
  int32_t code = pthread_mutex_init(mutex, attr);
42,201✔
43
  if (code) {
42,185✔
44
    terrno = TAOS_SYSTEM_ERROR(code);
64✔
45
    return terrno;
×
46
  }
47
  return code;
42,121✔
48
#endif
49
}
50

51
int32_t taosThreadMutexDestroy(TdThreadMutex *mutex) {
40,009✔
52
#ifdef WINDOWS
53
  DeleteCriticalSection(mutex);
54
  return 0;
55
#else
56
  int32_t code = pthread_mutex_destroy(mutex);
40,009✔
57
  if (code) {
40,013✔
58
    terrno = TAOS_SYSTEM_ERROR(code);
6✔
59
    return terrno;
×
60
  }
61
  return code;
40,007✔
62
#endif
63
}
64

65

66
int32_t taosThreadMutexLock(TdThreadMutex *mutex) {
1,312,061✔
67
#ifdef WINDOWS
68
  EnterCriticalSection(mutex);
69
  return 0;
70
#else
71
  int32_t code = pthread_mutex_lock(mutex);
1,312,061✔
72
  if (code) {
1,312,814✔
UNCOV
73
    terrno = TAOS_SYSTEM_ERROR(code);
×
74
    return terrno;
×
75
  }
76
  return code;
1,312,905✔
77
#endif
78
}
79

80
int32_t taosThreadMutexUnlock(TdThreadMutex *mutex) {
1,312,692✔
81
#ifdef WINDOWS
82
  LeaveCriticalSection(mutex);
83
  return 0;
84
#else
85
  int32_t code = pthread_mutex_unlock(mutex);
1,312,692✔
86
  if (code) {
1,312,854✔
87
    terrno = TAOS_SYSTEM_ERROR(code);
125✔
88
    return terrno;
×
89
  }
90
  return code;
1,312,729✔
91
#endif
92
}
93

94
//  ------- interface api ---------
95
TdThreadMutex mutexs[LOG_COUNT];
96

97
// init log
98
bool initLog() {
208✔
99
    for (int32_t i = 0; i < LOG_COUNT; i++) {
832✔
100
        if (taosThreadMutexInit(&mutexs[i], NULL) != 0) {
624✔
101
            printf("taosThreadMutexInit i=%d failed.\n", i);
×
102
        }
103
    }
104
    return true;
208✔
105
}
106

107
// exit log
108
void exitLog() {
204✔
109
    for (int32_t i = 0; i < LOG_COUNT; i++) {
816✔
110
        taosThreadMutexDestroy(&mutexs[i]);
612✔
111
    }
112
}
204✔
113

114
// lock
115
void lockLog(int8_t idx) {
8,862✔
116
    taosThreadMutexLock(&mutexs[idx]);
8,862✔
117
}
8,862✔
118
// unlock
119
void unlockLog(int8_t idx) {
8,862✔
120
    taosThreadMutexUnlock(&mutexs[idx]);
8,862✔
121
}
8,862✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc