Add mutext protection for stop flag
This commit is contained in:
parent
45289aefde
commit
84772d1e54
|
@ -36,9 +36,16 @@ static int32_t walInitObj(SWal *pWal);
|
||||||
static void walFreeObj(void *pWal);
|
static void walFreeObj(void *pWal);
|
||||||
|
|
||||||
int32_t walInit() {
|
int32_t walInit() {
|
||||||
|
int32_t code = 0;
|
||||||
tsWal.refId = taosOpenRef(TSDB_MIN_VNODES, walFreeObj);
|
tsWal.refId = taosOpenRef(TSDB_MIN_VNODES, walFreeObj);
|
||||||
|
|
||||||
int32_t code = walCreateThread();
|
code = pthread_mutex_init(&tsWal.mutex, NULL);
|
||||||
|
if (code) {
|
||||||
|
wError("failed to init wal mutex since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = walCreateThread();
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
wError("failed to init wal module since %s", tstrerror(code));
|
wError("failed to init wal module since %s", tstrerror(code));
|
||||||
return code;
|
return code;
|
||||||
|
@ -51,6 +58,7 @@ int32_t walInit() {
|
||||||
void walCleanUp() {
|
void walCleanUp() {
|
||||||
walStopThread();
|
walStopThread();
|
||||||
taosCloseRef(tsWal.refId);
|
taosCloseRef(tsWal.refId);
|
||||||
|
pthread_mutex_destroy(&tsWal.mutex);
|
||||||
wInfo("wal module is cleaned up");
|
wInfo("wal module is cleaned up");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,10 +191,15 @@ static void walFsyncAll() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *walThreadFunc(void *param) {
|
static void *walThreadFunc(void *param) {
|
||||||
|
int stop = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
walUpdateSeq();
|
walUpdateSeq();
|
||||||
walFsyncAll();
|
walFsyncAll();
|
||||||
if (tsWal.stop) break;
|
|
||||||
|
pthread_mutex_lock(&tsWal.mutex);
|
||||||
|
stop = tsWal.stop;
|
||||||
|
pthread_mutex_unlock(&tsWal.mutex);
|
||||||
|
if (stop) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -209,7 +222,10 @@ static int32_t walCreateThread() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void walStopThread() {
|
static void walStopThread() {
|
||||||
|
pthread_mutex_lock(&tsWal.mutex);
|
||||||
tsWal.stop = 1;
|
tsWal.stop = 1;
|
||||||
|
pthread_mutex_unlock(&tsWal.mutex);
|
||||||
|
|
||||||
if (taosCheckPthreadValid(tsWal.thread)) {
|
if (taosCheckPthreadValid(tsWal.thread)) {
|
||||||
pthread_join(tsWal.thread, NULL);
|
pthread_join(tsWal.thread, NULL);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue