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

taosdata / taos-tools / 12592211147

03 Jan 2025 03:18AM UTC coverage: 75.271% (-0.06%) from 75.33%
12592211147

Pull #834

github

web-flow
Merge 9a6503594 into 2e83b2dae
Pull Request #834: enh: taosBenchmark remove stmt2 retry function

12096 of 16070 relevant lines covered (75.27%)

335669.8 hits per line

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

82.05
/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) {
38,716✔
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);
38,716✔
43
  if (code) {
38,719✔
44
    terrno = TAOS_SYSTEM_ERROR(code);
138✔
45
    return terrno;
×
46
  }
47
  return code;
38,581✔
48
#endif
49
}
50

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

65

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

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

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

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

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

114
// lock
115
void lockLog(int8_t idx) {
8,696✔
116
    taosThreadMutexLock(&mutexs[idx]);
8,696✔
117
}
8,696✔
118
// unlock
119
void unlockLog(int8_t idx) {
8,696✔
120
    taosThreadMutexUnlock(&mutexs[idx]);
8,696✔
121
}
8,696✔
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

© 2025 Coveralls, Inc