mirror of
https://gitee.com/openharmony/commonlibrary_memory_utils
synced 2024-11-23 07:20:25 +00:00
commit
abb204a705
3
OAT.xml
3
OAT.xml
@ -22,8 +22,7 @@
|
||||
<filefilterlist>
|
||||
<filefilter name="defaultFilter" desc="Files not to check">
|
||||
<filteritem type="filename" name="*.png" desc="desc files"/>
|
||||
<filteritem type="filename" name="sync.c" desc="Waiting for refactoring"/>
|
||||
</filefilter>
|
||||
</filefilterlist>
|
||||
</oatconfig>
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
@ -15,6 +15,6 @@
|
||||
#ifndef COMM_UTILS_SYNC_H
|
||||
#define COMM_UTILS_SYNC_H
|
||||
|
||||
int SyncWait(int num, int time);
|
||||
int SyncWait(int fileDescriptor, int timeout);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012 Google, Inc
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -17,32 +17,31 @@
|
||||
#include <poll.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int SyncWait(int num, int time)
|
||||
int SyncWait(int fileDescriptor, int timeout)
|
||||
{
|
||||
struct pollfd work;
|
||||
int result;
|
||||
|
||||
if (num < 0) {
|
||||
if (fileDescriptor < 0) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
work.fd = num;
|
||||
work.events = POLLIN;
|
||||
struct pollfd pfd = { .fd = fileDescriptor, .events = POLLIN };
|
||||
int pollResult;
|
||||
|
||||
while (1) {
|
||||
pollResult = poll(&pfd, 1, timeout);
|
||||
|
||||
do {
|
||||
result = poll(&work, 1, time);
|
||||
if (result > 0) {
|
||||
if (work.revents & (POLLERR | POLLNVAL)) {
|
||||
if (pollResult > 0) {
|
||||
if (pfd.revents & (POLLERR | POLLNVAL)) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
} else if (result == 0) {
|
||||
} else if (pollResult == 0) {
|
||||
errno = ETIME;
|
||||
return -1;
|
||||
} else if (pollResult != -1 || (errno != EINTR && errno != EAGAIN)) {
|
||||
break;
|
||||
}
|
||||
} while (result == -1 && (errno == EINTR || errno == EAGAIN));
|
||||
|
||||
return result;
|
||||
}
|
||||
return pollResult;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user