resource.h 997 字节
Newer Older
W
wangguibao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#ifndef BAIDU_PADDLE_SERVING_PREDICTOR_RESOURCE_H
#define BAIDU_PADDLE_SERVING_PREDICTOR_RESOURCE_H

#include "common/inner_common.h"
#include "framework/memory.h"

namespace baidu {
namespace paddle_serving {
namespace predictor {

class BaseRdDict;
struct DynamicResource {
    DynamicResource();
    
    ~DynamicResource();
    
    int initialize();
    
    int clear();
};

class Resource {
public:

W
wangguibao 已提交
25
    Resource() {}
W
wangguibao 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

    ~Resource() { finalize(); }

    static Resource& instance() {
        static Resource ins;
        return ins;
    }

    int initialize(const std::string& path, const std::string& file);

    int thread_initialize();

    int thread_clear();

    int reload();

    int finalize();

    DynamicResource* get_dynamic_resource() {
        return (DynamicResource*) THREAD_GETSPECIFIC(_tls_bspec_key);
    }

private:
    int thread_finalize() {
        return 0; 
    }

    THREAD_KEY_T _tls_bspec_key;
    
};

} // predictor
} // paddle_serving
} // baidu

#endif