METHOD_UNLOCK_STATE, "ss", arr, unlock_cb, -1, NULL);
}
-#define CHECK_RATE_THRESHOLD 100
-#define CHECK_RATE_PERIOD_LEN 5
-static int check_rate()
-{
- static int status;
- static long num_calls;
- static struct timeval prev;
- struct timeval cur;
- int ret;
-
- if (status < 0)
- return status;
-
- ret = gettimeofday(&cur, NULL);
- if (ret < 0) {
- _E("Failed to do gettimeofday() ret=%d", ret);
- return 0;
- }
-
- if (num_calls > 0) {
- long rate;
- struct timeval diff;
- timersub(&cur, &prev, &diff);
-
- if (diff.tv_sec > 0) {
- rate = num_calls / diff.tv_sec;
-
- if (rate > CHECK_RATE_THRESHOLD) {
- status = -1;
- return status;
- }
-
- if (diff.tv_sec > CHECK_RATE_PERIOD_LEN) {
- /* Reset the check period */
- num_calls = 0;
- return 0;
- }
- }
- } else {
- /* Start a new check period */
- prev = cur;
- }
-
- num_calls++;
- return 0;
-}
-
int device_power_request_lock(power_lock_e type, int timeout_ms)
{
int ret;
_I("power_lock_e = %d", type);
- if (check_rate() < 0) {
+ if (check_async_call_rate() < 0) {
_E("Rejected by too frequent calls; %d (calls per sec.) limit is violated."
, CHECK_RATE_THRESHOLD);
return DEVICE_ERROR_OPERATION_FAILED;
_I("power_lock_e = %d", type);
- if (check_rate() < 0) {
+ if (check_async_call_rate() < 0) {
_E("Rejected by too frequent calls; %d (calls per sec.) limit is violated."
, CHECK_RATE_THRESHOLD);
return DEVICE_ERROR_OPERATION_FAILED;