1/* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include <binder/IServiceManager.h> 18#include <utils/Mutex.h> 19#include "ISchedulingPolicyService.h" 20#include "SchedulingPolicyService.h" 21 22namespace android { 23 24static sp<ISchedulingPolicyService> sSchedulingPolicyService; 25static const String16 _scheduling_policy("scheduling_policy"); 26static Mutex sMutex; 27 28int requestPriority(pid_t pid, pid_t tid, int32_t prio) 29{ 30 // FIXME merge duplicated code related to service lookup, caching, and error recovery 31 sp<ISchedulingPolicyService> sps; 32 for (;;) { 33 sMutex.lock(); 34 sps = sSchedulingPolicyService; 35 sMutex.unlock(); 36 if (sps != 0) { 37 break; 38 } 39 sp<IBinder> binder = defaultServiceManager()->checkService(_scheduling_policy); 40 if (binder != 0) { 41 sps = interface_cast<ISchedulingPolicyService>(binder); 42 sMutex.lock(); 43 sSchedulingPolicyService = sps; 44 sMutex.unlock(); 45 break; 46 } 47 sleep(1); 48 } 49 return sps->requestPriority(pid, tid, prio); 50} 51 52} // namespace android 53