00001 #ifndef MallocOpts_h
00002 #define MallocOpts_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <string>
00030 #include <ostream>
00031
00032 namespace edm
00033 {
00034 struct MallocOpts
00035 {
00036 typedef int opt_type;
00037
00038 MallocOpts():
00039 mmap_max_(),trim_thr_(),top_pad_(),mmap_thr_()
00040 {}
00041 MallocOpts(opt_type max,opt_type trim,opt_type pad,opt_type mmap_thr):
00042 mmap_max_(max),trim_thr_(trim),top_pad_(pad),mmap_thr_(mmap_thr)
00043 {}
00044
00045 opt_type mmap_max_;
00046 opt_type trim_thr_;
00047 opt_type top_pad_;
00048 opt_type mmap_thr_;
00049
00050 bool operator==(const MallocOpts& opts) const
00051 {
00052 return
00053 mmap_max_ == opts.mmap_max_ &&
00054 trim_thr_ == opts.trim_thr_ &&
00055 top_pad_ == opts.top_pad_ &&
00056 mmap_thr_ == opts.mmap_thr_;
00057 }
00058 bool operator!=(const MallocOpts& opts) const
00059 { return !operator==(opts); }
00060 };
00061
00062 std::ostream& operator<<(std::ostream& ost,const MallocOpts&);
00063
00064 class MallocOptionSetter
00065 {
00066 public:
00067 typedef MallocOpts::opt_type opt_type;
00068 MallocOptionSetter();
00069
00070 bool retrieveFromCpuType();
00071 bool retrieveFromEnv();
00072 void adjustMallocParams();
00073 bool hasErrors() const { return !error_message_.empty(); }
00074 std::string error_message() const { return error_message_; }
00075
00076 void set_mmap_max(opt_type mmap_max)
00077 { values_.mmap_max_=mmap_max; changed_=true; }
00078 void set_trim_thr(opt_type trim_thr)
00079 { values_.trim_thr_=trim_thr; changed_=true; }
00080 void set_top_pad(opt_type top_pad)
00081 { values_.top_pad_=top_pad; changed_=true; }
00082 void set_mmap_thr(opt_type mmap_thr)
00083 { values_.mmap_thr_=mmap_thr; changed_=true; }
00084
00085 MallocOpts get() const { return values_; }
00086
00087 private:
00088 bool changed_;
00089 MallocOpts values_;
00090
00091 std::string error_message_;
00092 };
00093
00094 MallocOptionSetter& getGlobalOptionSetter();
00095
00096 }
00097
00098
00099
00100 #endif