minor changes
This commit is contained in:
parent
cb71affec5
commit
17dfbffb41
|
@ -16,12 +16,12 @@
|
|||
#ifndef _TD_UTIL_JSON_H_
|
||||
#define _TD_UTIL_JSON_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
|
||||
typedef void SJson;
|
||||
|
||||
SJson* tjsonCreateObject();
|
||||
|
|
|
@ -12,8 +12,9 @@
|
|||
* 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/>.
|
||||
*/
|
||||
#ifndef _TD_UTIL_LOCK_FREE_H
|
||||
#define _TD_UTIL_LOCK_FREE_H
|
||||
|
||||
#ifndef _TD_UTIL_LOCK_FREE_H_
|
||||
#define _TD_UTIL_LOCK_FREE_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
|
@ -67,8 +68,6 @@ typedef void (*_ref_fn_t)(const void* pObj);
|
|||
|
||||
#define T_REF_VAL_GET(x) (x)->_ref.val
|
||||
|
||||
|
||||
|
||||
// single writer multiple reader lock
|
||||
typedef volatile int32_t SRWLatch;
|
||||
|
||||
|
@ -78,10 +77,9 @@ void taosWUnLockLatch(SRWLatch *pLatch);
|
|||
void taosRLockLatch(SRWLatch *pLatch);
|
||||
void taosRUnLockLatch(SRWLatch *pLatch);
|
||||
|
||||
|
||||
|
||||
// copy on read
|
||||
#define taosCorBeginRead(x) for (uint32_t i_ = 1; 1; ++i_) { \
|
||||
#define taosCorBeginRead(x) \
|
||||
for (uint32_t i_ = 1; 1; ++i_) { \
|
||||
int32_t old_ = atomic_add_fetch_32((x), 0); \
|
||||
if (old_ & 0x00000001) { \
|
||||
if (i_ % 1000 == 0) { \
|
||||
|
@ -96,12 +94,11 @@ void taosRUnLockLatch(SRWLatch *pLatch);
|
|||
} \
|
||||
}
|
||||
|
||||
#define taosCorBeginWrite(x) taosCorBeginRead(x) \
|
||||
if (atomic_val_compare_exchange_32((x), old_, old_ + 1) != old_) { \
|
||||
continue; \
|
||||
}
|
||||
#define taosCorBeginWrite(x) \
|
||||
taosCorBeginRead(x) if (atomic_val_compare_exchange_32((x), old_, old_ + 1) != old_) { continue; }
|
||||
|
||||
#define taosCorEndWrite(x) atomic_add_fetch_32((x), 1); \
|
||||
#define taosCorEndWrite(x) \
|
||||
atomic_add_fetch_32((x), 1); \
|
||||
break; \
|
||||
}
|
||||
|
||||
|
@ -109,4 +106,4 @@ void taosRUnLockLatch(SRWLatch *pLatch);
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_UTIL_LOCK_FREE_H*/
|
||||
#endif /*_TD_UTIL_LOCK_FREE_H_*/
|
||||
|
|
|
@ -13,18 +13,14 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "tjson.h"
|
||||
|
||||
#include "taoserror.h"
|
||||
#include "cJSON.h"
|
||||
#include "taoserror.h"
|
||||
|
||||
SJson* tjsonCreateObject() {
|
||||
return cJSON_CreateObject();
|
||||
}
|
||||
SJson* tjsonCreateObject() { return cJSON_CreateObject(); }
|
||||
|
||||
void tjsonDelete(SJson* pJson) {
|
||||
cJSON_Delete((cJSON*)pJson);
|
||||
}
|
||||
void tjsonDelete(SJson* pJson) { cJSON_Delete((cJSON*)pJson); }
|
||||
|
||||
int32_t tjsonAddIntegerToObject(SJson* pJson, const char* pName, const uint64_t number) {
|
||||
char tmp[40] = {0};
|
||||
|
@ -44,9 +40,7 @@ int32_t tjsonAddStringToObject(SJson* pJson, const char* pName, const char* pVal
|
|||
return (NULL == cJSON_AddStringToObject((cJSON*)pJson, pName, pVal) ? TSDB_CODE_FAILED : TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
SJson* tjsonAddArrayToObject(SJson* pJson, const char* pName) {
|
||||
return cJSON_AddArrayToObject((cJSON*)pJson, pName);
|
||||
}
|
||||
SJson* tjsonAddArrayToObject(SJson* pJson, const char* pName) { return cJSON_AddArrayToObject((cJSON*)pJson, pName); }
|
||||
|
||||
int32_t tjsonAddItemToObject(SJson* pJson, const char* pName, SJson* pItem) {
|
||||
return (cJSON_AddItemToObject((cJSON*)pJson, pName, pItem) ? TSDB_CODE_SUCCESS : TSDB_CODE_FAILED);
|
||||
|
@ -79,18 +73,11 @@ int32_t tjsonAddItem(SJson* pJson, FToJson func, const void* pObj) {
|
|||
return tjsonAddItemToArray(pJson, pJobj);
|
||||
}
|
||||
|
||||
char* tjsonToString(const SJson* pJson) {
|
||||
return cJSON_Print((cJSON*)pJson);
|
||||
}
|
||||
char* tjsonToString(const SJson* pJson) { return cJSON_Print((cJSON*)pJson); }
|
||||
|
||||
char* tjsonToUnformattedString(const SJson* pJson) {
|
||||
return cJSON_PrintUnformatted((cJSON*)pJson);
|
||||
}
|
||||
char* tjsonToUnformattedString(const SJson* pJson) { return cJSON_PrintUnformatted((cJSON*)pJson); }
|
||||
|
||||
|
||||
SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName) {
|
||||
return cJSON_GetObjectItem(pJson, pName);
|
||||
}
|
||||
SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName) { return cJSON_GetObjectItem(pJson, pName); }
|
||||
|
||||
int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal) {
|
||||
char* p = cJSON_GetStringValue(tjsonGetObjectItem((cJSON*)pJson, pName));
|
||||
|
@ -176,13 +163,9 @@ int32_t tjsonGetDoubleValue(const SJson* pJson, const char* pName, double* pVal)
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tjsonGetArraySize(const SJson* pJson) {
|
||||
return cJSON_GetArraySize(pJson);
|
||||
}
|
||||
int32_t tjsonGetArraySize(const SJson* pJson) { return cJSON_GetArraySize(pJson); }
|
||||
|
||||
SJson* tjsonGetArrayItem(const SJson* pJson, int32_t index) {
|
||||
return cJSON_GetArrayItem(pJson, index);
|
||||
}
|
||||
SJson* tjsonGetArrayItem(const SJson* pJson, int32_t index) { return cJSON_GetArrayItem(pJson, index); }
|
||||
|
||||
int32_t tjsonToObject(const SJson* pJson, const char* pName, FToObject func, void* pObj) {
|
||||
SJson* pJsonObj = tjsonGetObjectItem(pJson, pName);
|
||||
|
@ -192,6 +175,4 @@ int32_t tjsonToObject(const SJson* pJson, const char* pName, FToObject func, voi
|
|||
return func(pJsonObj, pObj);
|
||||
}
|
||||
|
||||
SJson* tjsonParse(const char* pStr) {
|
||||
return cJSON_Parse(pStr);
|
||||
}
|
||||
SJson* tjsonParse(const char* pStr) { return cJSON_Parse(pStr); }
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "os.h"
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "tlockfree.h"
|
||||
|
||||
#define TD_RWLATCH_WRITE_FLAG 0x40000000
|
||||
|
@ -22,7 +22,7 @@ void taosInitRWLatch(SRWLatch *pLatch) { *pLatch = 0; }
|
|||
|
||||
void taosWLockLatch(SRWLatch *pLatch) {
|
||||
SRWLatch oLatch, nLatch;
|
||||
int nLoops = 0;
|
||||
int32_t nLoops = 0;
|
||||
|
||||
// Set write flag
|
||||
while (1) {
|
||||
|
@ -57,7 +57,7 @@ void taosWUnLockLatch(SRWLatch *pLatch) { atomic_store_32(pLatch, 0); }
|
|||
|
||||
void taosRLockLatch(SRWLatch *pLatch) {
|
||||
SRWLatch oLatch, nLatch;
|
||||
int nLoops = 0;
|
||||
int32_t nLoops = 0;
|
||||
|
||||
while (1) {
|
||||
oLatch = atomic_load_32(pLatch);
|
||||
|
|
Loading…
Reference in New Issue