提交 005905b7 编写于 作者: C cheng_jinsong

修改time初始化方式

Signed-off-by: Ncheng_jinsong <chengjinsong2@huawei.com>
上级 d7d82247
...@@ -52,7 +52,7 @@ static void UnloadDeviceInfoSa(int signo) ...@@ -52,7 +52,7 @@ static void UnloadDeviceInfoSa(int signo)
{ {
{ {
std::unique_lock<std::mutex> lock(g_lock); std::unique_lock<std::mutex> lock(g_lock);
struct timespec currTimer = {}; struct timespec currTimer = {0};
(void)clock_gettime(CLOCK_MONOTONIC, &currTimer); (void)clock_gettime(CLOCK_MONOTONIC, &currTimer);
if (IntervalTime(&g_lastTime, &currTimer) < DEVICE_INFO_EXIT_TIMEOUT_S) { if (IntervalTime(&g_lastTime, &currTimer) < DEVICE_INFO_EXIT_TIMEOUT_S) {
alarm(DEVICE_INFO_EXIT_TIMEOUT_S / 3); // 3 half alarm(DEVICE_INFO_EXIT_TIMEOUT_S / 3); // 3 half
......
...@@ -573,7 +573,7 @@ static bool CalculateCrashTime(Service *service, int crashTimeLimit, int crashCo ...@@ -573,7 +573,7 @@ static bool CalculateCrashTime(Service *service, int crashTimeLimit, int crashCo
{ {
INIT_ERROR_CHECK(service != NULL && crashTimeLimit > 0 && crashCountLimit > 0, INIT_ERROR_CHECK(service != NULL && crashTimeLimit > 0 && crashCountLimit > 0,
return false, "input params error."); return false, "input params error.");
struct timespec curTime = {}; struct timespec curTime = {0};
(void)clock_gettime(CLOCK_MONOTONIC, &curTime); (void)clock_gettime(CLOCK_MONOTONIC, &curTime);
struct timespec crashTime = {service->firstCrashTime, 0}; struct timespec crashTime = {service->firstCrashTime, 0};
if (service->crashCnt == 0) { if (service->crashCnt == 0) {
......
...@@ -41,7 +41,7 @@ static InitLogLevel g_logLevel = INIT_INFO; ...@@ -41,7 +41,7 @@ static InitLogLevel g_logLevel = INIT_INFO;
#ifdef INIT_FILE #ifdef INIT_FILE
static void LogToFile(const char *logFile, const char *tag, const char *info) static void LogToFile(const char *logFile, const char *tag, const char *info)
{ {
struct timespec curr; struct timespec curr = {0};
if (clock_gettime(CLOCK_REALTIME, &curr) != 0) { if (clock_gettime(CLOCK_REALTIME, &curr) != 0) {
return; return;
} }
......
...@@ -25,8 +25,8 @@ static void DoAsyncEvent_(const LoopHandle loopHandle, AsyncEventTask *asyncTask ...@@ -25,8 +25,8 @@ static void DoAsyncEvent_(const LoopHandle loopHandle, AsyncEventTask *asyncTask
{ {
LE_CHECK(loopHandle != NULL && asyncTask != NULL, return, "Invalid parameters"); LE_CHECK(loopHandle != NULL && asyncTask != NULL, return, "Invalid parameters");
#ifdef LOOP_DEBUG #ifdef LOOP_DEBUG
struct timespec startTime; struct timespec startTime = {0};
struct timespec endTime; struct timespec endTime = {0};
long long diff; long long diff;
clock_gettime(CLOCK_MONOTONIC, &(startTime)); clock_gettime(CLOCK_MONOTONIC, &(startTime));
#endif #endif
......
...@@ -174,8 +174,8 @@ BOOTCHART_STATIC void *BootchartThreadMain(void *data) ...@@ -174,8 +174,8 @@ BOOTCHART_STATIC void *BootchartThreadMain(void *data)
BootchartLogHeader(); BootchartLogHeader();
while (1) { while (1) {
pthread_mutex_lock(&(g_bootchartCtrl->mutex)); pthread_mutex_lock(&(g_bootchartCtrl->mutex));
struct timespec abstime = {}; struct timespec abstime = {0};
struct timeval now = {}; struct timeval now = {0};
const long timeout = 200; // wait time 200ms const long timeout = 200; // wait time 200ms
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
long nsec = now.tv_usec * 1000 + (timeout % 1000) * 1000000; // 1000 unit 1000000 unit nsec long nsec = now.tv_usec * 1000 + (timeout % 1000) * 1000000; // 1000 unit 1000000 unit nsec
......
...@@ -73,7 +73,7 @@ static int TraversalEvent(ListNode *node, void *root) ...@@ -73,7 +73,7 @@ static int TraversalEvent(ListNode *node, void *root)
PLUGIN_STATIC void ReportBootEventComplete(ListNode *events) PLUGIN_STATIC void ReportBootEventComplete(ListNode *events)
{ {
PLUGIN_CHECK(events != NULL, return, "Invalid events"); PLUGIN_CHECK(events != NULL, return, "Invalid events");
struct timespec curr; struct timespec curr = {0};
if (clock_gettime(CLOCK_MONOTONIC, &curr) != 0) { if (clock_gettime(CLOCK_MONOTONIC, &curr) != 0) {
return; return;
} }
......
...@@ -816,7 +816,7 @@ void CachedParameterDestroy(CachedHandle handle) ...@@ -816,7 +816,7 @@ void CachedParameterDestroy(CachedHandle handle)
#define MAX_TEST 10000 #define MAX_TEST 10000
STATIC_INLINE long long DiffLocalTime(struct timespec *startTime) STATIC_INLINE long long DiffLocalTime(struct timespec *startTime)
{ {
struct timespec endTime; struct timespec endTime = {0};
clock_gettime(CLOCK_MONOTONIC, &(endTime)); clock_gettime(CLOCK_MONOTONIC, &(endTime));
long long diff = (long long)((endTime.tv_sec - startTime->tv_sec) * 1000000); // 1000000 1000ms long long diff = (long long)((endTime.tv_sec - startTime->tv_sec) * 1000000); // 1000000 1000ms
if (endTime.tv_nsec > startTime->tv_nsec) { if (endTime.tv_nsec > startTime->tv_nsec) {
...@@ -829,7 +829,7 @@ STATIC_INLINE long long DiffLocalTime(struct timespec *startTime) ...@@ -829,7 +829,7 @@ STATIC_INLINE long long DiffLocalTime(struct timespec *startTime)
static void TestPermissionCheck(const char *testParamName) static void TestPermissionCheck(const char *testParamName)
{ {
struct timespec startTime; struct timespec startTime = {0};
clock_gettime(CLOCK_MONOTONIC, &(startTime)); clock_gettime(CLOCK_MONOTONIC, &(startTime));
ParamSecurityLabel *label = &(GetParamWorkSpace()->securityLabel); ParamSecurityLabel *label = &(GetParamWorkSpace()->securityLabel);
ParamLabelIndex labelIndex = {0}; ParamLabelIndex labelIndex = {0};
...@@ -879,7 +879,7 @@ static void TestPermissionCheck(const char *testParamName) ...@@ -879,7 +879,7 @@ static void TestPermissionCheck(const char *testParamName)
void TestParameterReaderPerformance(void) void TestParameterReaderPerformance(void)
{ {
struct timespec startTime; struct timespec startTime = {0};
const char *testParamName = "persist.appspawn.randrom.read"; const char *testParamName = "persist.appspawn.randrom.read";
const uint32_t buffSize = PARAM_VALUE_LEN_MAX; const uint32_t buffSize = PARAM_VALUE_LEN_MAX;
char buffer[PARAM_VALUE_LEN_MAX] = {0}; char buffer[PARAM_VALUE_LEN_MAX] = {0};
......
...@@ -93,14 +93,14 @@ static int ReadMessage(int fd, char *buffer, uint32_t timeout) ...@@ -93,14 +93,14 @@ static int ReadMessage(int fd, char *buffer, uint32_t timeout)
{ {
int ret = 0; int ret = 0;
uint32_t diff = 0; uint32_t diff = 0;
struct timespec startTime = {}; struct timespec startTime = {0};
(void)clock_gettime(CLOCK_MONOTONIC, &startTime); (void)clock_gettime(CLOCK_MONOTONIC, &startTime);
do { do {
ssize_t recvLen = recv(fd, (char *)buffer, RECV_BUFFER_MAX, 0); ssize_t recvLen = recv(fd, (char *)buffer, RECV_BUFFER_MAX, 0);
if (recvLen > 0) { if (recvLen > 0) {
break; break;
} }
struct timespec finishTime = {}; struct timespec finishTime = {0};
(void)clock_gettime(CLOCK_MONOTONIC, &finishTime); (void)clock_gettime(CLOCK_MONOTONIC, &finishTime);
diff = IntervalTime(&finishTime, &startTime); diff = IntervalTime(&finishTime, &startTime);
if (diff >= timeout) { if (diff >= timeout) {
...@@ -120,7 +120,7 @@ static int ReadMessage(int fd, char *buffer, uint32_t timeout) ...@@ -120,7 +120,7 @@ static int ReadMessage(int fd, char *buffer, uint32_t timeout)
static int GetClientSocket(int timeout) static int GetClientSocket(int timeout)
{ {
struct timeval time; struct timeval time = {0};
time.tv_sec = timeout; time.tv_sec = timeout;
time.tv_usec = 0; time.tv_usec = 0;
int clientFd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); int clientFd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
......
...@@ -71,7 +71,7 @@ int SystemWaitParameter(const char *name, const char *value, int32_t timeout) ...@@ -71,7 +71,7 @@ int SystemWaitParameter(const char *name, const char *value, int32_t timeout)
int ret = CheckParamPermission(GetParamSecurityLabel(), name, DAC_READ); int ret = CheckParamPermission(GetParamSecurityLabel(), name, DAC_READ);
PARAM_CHECK(ret == 0, return ret, "Forbid to wait parameter %s", name); PARAM_CHECK(ret == 0, return ret, "Forbid to wait parameter %s", name);
uint32_t diff = 0; uint32_t diff = 0;
struct timespec startTime = {}; struct timespec startTime = {0};
if (timeout <= 0) { if (timeout <= 0) {
timeout = DEFAULT_PARAM_WAIT_TIMEOUT; timeout = DEFAULT_PARAM_WAIT_TIMEOUT;
} }
...@@ -88,7 +88,7 @@ int SystemWaitParameter(const char *name, const char *value, int32_t timeout) ...@@ -88,7 +88,7 @@ int SystemWaitParameter(const char *name, const char *value, int32_t timeout)
globalCommit = commit; globalCommit = commit;
usleep(MIN_SLEEP); usleep(MIN_SLEEP);
struct timespec finishTime = {}; struct timespec finishTime = {0};
(void)clock_gettime(CLOCK_MONOTONIC, &finishTime); (void)clock_gettime(CLOCK_MONOTONIC, &finishTime);
diff = IntervalTime(&finishTime, &startTime); diff = IntervalTime(&finishTime, &startTime);
if (diff >= timeout) { if (diff >= timeout) {
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "param_osadp.h" #include "param_osadp.h"
#include "securec.h" #include "securec.h"
static ParamPersistWorkSpace g_persistWorkSpace = {0, 0, NULL, {}, {0}}; static ParamPersistWorkSpace g_persistWorkSpace = {0, 0, NULL, {0}, {0}};
static int IsNeedToSave(const char *name) static int IsNeedToSave(const char *name)
{ {
#if defined(__LITEOS_M__) || defined(__LITEOS_A__) #if defined(__LITEOS_M__) || defined(__LITEOS_A__)
...@@ -194,7 +194,7 @@ INIT_LOCAL_API int WritePersistParam(const char *name, const char *value) ...@@ -194,7 +194,7 @@ INIT_LOCAL_API int WritePersistParam(const char *name, const char *value)
} }
// check timer for save all // check timer for save all
struct timespec currTimer = {}; struct timespec currTimer = {0};
(void)clock_gettime(CLOCK_MONOTONIC, &currTimer); (void)clock_gettime(CLOCK_MONOTONIC, &currTimer);
uint32_t diff = IntervalTime(&g_persistWorkSpace.lastSaveTimer, &currTimer); uint32_t diff = IntervalTime(&g_persistWorkSpace.lastSaveTimer, &currTimer);
if (diff > PARAM_MUST_SAVE_PARAM_DIFF) { if (diff > PARAM_MUST_SAVE_PARAM_DIFF) {
......
...@@ -95,7 +95,7 @@ HWTEST_F(SysEventUnitTest, SysEventTest_003, TestSize.Level1) ...@@ -95,7 +95,7 @@ HWTEST_F(SysEventUnitTest, SysEventTest_003, TestSize.Level1)
HWTEST_F(SysEventUnitTest, SysEventTest_004, TestSize.Level1) HWTEST_F(SysEventUnitTest, SysEventTest_004, TestSize.Level1)
{ {
struct timespec curr; struct timespec curr = {0};
if (clock_gettime(CLOCK_MONOTONIC, &curr) != 0) { if (clock_gettime(CLOCK_MONOTONIC, &curr) != 0) {
return; return;
} }
...@@ -112,7 +112,7 @@ HWTEST_F(SysEventUnitTest, SysEventTest_004, TestSize.Level1) ...@@ -112,7 +112,7 @@ HWTEST_F(SysEventUnitTest, SysEventTest_004, TestSize.Level1)
HWTEST_F(SysEventUnitTest, SysEventTest_005, TestSize.Level1) HWTEST_F(SysEventUnitTest, SysEventTest_005, TestSize.Level1)
{ {
struct timespec curr; struct timespec curr = {0};
if (clock_gettime(CLOCK_MONOTONIC, &curr) != 0) { if (clock_gettime(CLOCK_MONOTONIC, &curr) != 0) {
return; return;
} }
......
...@@ -68,8 +68,8 @@ static void *ThreadRun(void *data) ...@@ -68,8 +68,8 @@ static void *ThreadRun(void *data)
while (1) { while (1) {
pthread_mutex_lock(&(parameterCtrl->lock)); pthread_mutex_lock(&(parameterCtrl->lock));
if (parameterCtrl->empty) { if (parameterCtrl->empty) {
struct timespec abstime = {}; struct timespec abstime = {0};
struct timeval now = {}; struct timeval now = {0};
const long timeout = 5000; // wait time 5000ms const long timeout = 5000; // wait time 5000ms
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
long nsec = now.tv_usec * 1000 + (timeout % 1000) * 1000000; // 1000 unit 1000000 unit nsec long nsec = now.tv_usec * 1000 + (timeout % 1000) * 1000000; // 1000 unit 1000000 unit nsec
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册