Home | History | Annotate | Download | only in soft
      1 /*
      2  * soft_worker.h - soft worker class
      3  *
      4  *  Copyright (c) 2017 Intel Corporation
      5  *
      6  * Licensed under the Apache License, Version 2.0 (the "License");
      7  * you may not use this file except in compliance with the License.
      8  * You may obtain a copy of the License at
      9  *
     10  *      http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  * Unless required by applicable law or agreed to in writing, software
     13  * distributed under the License is distributed on an "AS IS" BASIS,
     14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15  * See the License for the specific language governing permissions and
     16  * limitations under the License.
     17  *
     18  * Author: Wind Yuan <feng.yuan (at) intel.com>
     19  */
     20 
     21 #ifndef XCAM_SOFT_WORKER_H
     22 #define XCAM_SOFT_WORKER_H
     23 
     24 #include <xcam_std.h>
     25 #include <worker.h>
     26 
     27 #define SOFT_MAX_DIM 3
     28 
     29 namespace XCam {
     30 
     31 class ThreadPool;
     32 
     33 struct WorkRange {
     34     uint32_t pos[SOFT_MAX_DIM];
     35     uint32_t pos_len[SOFT_MAX_DIM];
     36 
     37     WorkRange () {
     38         xcam_mem_clear (pos);
     39         xcam_mem_clear (pos_len);
     40     }
     41 };
     42 
     43 struct WorkSize {
     44     uint32_t value[SOFT_MAX_DIM];
     45     WorkSize (uint32_t x = 1, uint32_t y = 1, uint32_t z = 1) {
     46         value[0] = x;
     47         value[1] = y;
     48         value[2] = z;
     49     }
     50 };
     51 
     52 //multi-thread worker
     53 class SoftWorker
     54     : public Worker
     55 {
     56     friend class WorkItem;
     57 
     58 public:
     59     explicit SoftWorker (const char *name, const SmartPtr<Callback> &cb = NULL);
     60     virtual ~SoftWorker ();
     61 
     62     bool set_work_uint (uint32_t x, uint32_t y, uint32_t z = 1);
     63     const WorkSize &get_work_uint () const {
     64         return _work_unit;
     65     }
     66 
     67     bool set_threads (const SmartPtr<ThreadPool> &threads);
     68     bool set_global_size (const WorkSize &size);
     69     const WorkSize &get_global_size () const {
     70         return _global;
     71     }
     72     bool set_local_size (const WorkSize &size);
     73     const WorkSize &get_local_size () const {
     74         return _local;
     75     }
     76 
     77     // derived from Worker
     78     virtual XCamReturn work (const SmartPtr<Arguments> &args);
     79     virtual XCamReturn stop ();
     80 
     81 private:
     82     //new virtual functions
     83     virtual XCamReturn work_range (const SmartPtr<Arguments> &args, const WorkRange &range);
     84     virtual WorkRange get_range (const WorkSize &item);
     85     virtual XCamReturn work_unit (const SmartPtr<Arguments> &args, const WorkSize &unit);
     86 
     87     XCamReturn work_impl (const SmartPtr<Arguments> &args, const WorkSize &item);
     88     void all_items_done (const SmartPtr<Arguments> &args, XCamReturn error);
     89 
     90     XCAM_DEAD_COPY (SoftWorker);
     91 
     92 private:
     93     SmartPtr<ThreadPool>    _threads;
     94     WorkSize                _global;
     95     WorkSize                _local;
     96     WorkSize                _work_unit;
     97 };
     98 
     99 }
    100 #endif //XCAM_SOFT_WORKER_H
    101