Home | History | Annotate | Download | only in thread
      1 /*
      2  * Copyright (C) 2013 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 #ifndef ANDROID_HWUI_TASK_H
     18 #define ANDROID_HWUI_TASK_H
     19 
     20 #define ATRACE_TAG ATRACE_TAG_VIEW
     21 
     22 #include <utils/RefBase.h>
     23 #include <utils/Trace.h>
     24 
     25 #include "Future.h"
     26 
     27 namespace android {
     28 namespace uirenderer {
     29 
     30 class TaskBase: public RefBase {
     31 public:
     32     TaskBase() { }
     33     virtual ~TaskBase() { }
     34 };
     35 
     36 template<typename T>
     37 class Task: public TaskBase {
     38 public:
     39     Task(): mFuture(new Future<T>()) { }
     40     virtual ~Task() { }
     41 
     42     T getResult() const {
     43         ATRACE_NAME("waitForTask");
     44         return mFuture->get();
     45     }
     46 
     47     void setResult(T result) {
     48         mFuture->produce(result);
     49     }
     50 
     51 protected:
     52     const sp<Future<T> >& future() const {
     53         return mFuture;
     54     }
     55 
     56 private:
     57     sp<Future<T> > mFuture;
     58 };
     59 
     60 }; // namespace uirenderer
     61 }; // namespace android
     62 
     63 #endif // ANDROID_HWUI_TASK_H
     64