use atomic operations on server.bio_find_offset_res
#include "redis_oplog.h"
#include "bio.h"
+#include "atomicvar.h"
#include <sys/types.h>
#include <sys/stat.h>
@@ -2606,8 +2607,10 @@ void bioFindOffsetByOpid(client *c, long long opid, uint64_t client_id) {
int argc = 0;
/* produce one item at a time, after that we just sleep */
- while (server.bio_find_offset_res) {
+ atomicGet(server.bio_find_offset_res, offset_result);
+ while (offset_result) {
sleep(1);
+ atomicGet(server.bio_find_offset_res, offset_result);
}
offset_result = (bioFindOffsetRes *)zmalloc(sizeof(bioFindOffsetRes));
@@ -2863,11 +2866,13 @@ void handleBioFindOffsetRes() {
void handleBioFindOffsetResCron(void) {
/* master catch result generated by bio thread */
- if (server.bio_find_offset_res) {
+ bioFindOffsetRes *offset_result = NULL;
+ atomicGet(server.bio_find_offset_res, offset_result);
+ if(offset_result) {
/* consume bio find offset result and save it to a list */
- listAddNodeTail(server.bio_find_offset_results,
- server.bio_find_offset_res);
- server.bio_find_offset_res = NULL;
+ listAddNodeTail(server.bio_find_offset_results, offset_result);
+ offset_result = NULL;
+ atomicSet(server.bio_find_offset_res, offset_result);
}
handleBioFindOffsetRes();
}
