未验证 提交 99299937 编写于 作者: O openharmony_ci 提交者: Gitee

!2018 修改timespec初始化

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