Loading libs/libsystempp/src/include/sysinfo.h +10 −9 Original line number Diff line number Diff line namespace libsysinfopp { class SYSInfo { namespace libsystempp { namespace sysinfo { class CPUInfo { public: SYSInfo(); ~SYSInfo(); CPUInfo(); ~CPUInfo(); unsigned getNumberOfProcessors(); int getPid(); private: }; }; }; libs/libsystempp/src/include/thread.h +45 −42 Original line number Diff line number Diff line Loading @@ -25,13 +25,11 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <unistd.h> #define PTHREAD_INHERIT_SCHED 0 #define PTHREAD_EXPLICIT_SCHED 1 #ifndef size_t typedef unsigned int size_t; #endif #ifndef THREAD_H #define THREAD_H Loading @@ -50,10 +48,13 @@ namespace libsystempp { MutexData *_MutexData; }; class Scheduler { public: class Parameter { class ThreadAttribute { public: enum Policy { SCHED_FIFO=0, SCHED_RR=1, SCHED_OTHER=2 }; int getPolicy(); void setPolicy(int policy); int getScope(); Loading @@ -65,8 +66,8 @@ namespace libsystempp { void setGuardSize(size_t guardsize); size_t getGuardSize(); private: Parameter(); ~Parameter(); ThreadAttribute(); ~ThreadAttribute(); int _Policy; int _Scope; void *_StackAddr; Loading @@ -74,33 +75,35 @@ namespace libsystempp { size_t _GuardSize; friend class Scheduler; }; enum Policy { SCHED_FIFO=0, SCHED_RR=1, SCHED_OTHER=2 }; static Scheduler *init(); private: Scheduler(); ~Scheduler(); Scheduler(Scheduler const&); void delParameter(Parameter *param); void addParameter(Parameter **param); static Scheduler *_Instance; friend class Thread; }; class Thread { public: Thread(); Thread(void *method,void *args); Thread(void *args); ~Thread(); void Detach(); int DetachState(); Scheduler::Parameter *getinheritsched(); void setinheritsched(Scheduler::Parameter *param); void Join(void *rval=NULL); bool JoinAble(); ThreadAttribute *getinheritsched(); void setinheritsched(ThreadAttribute *attr); protected: virtual void *Run(void *args); private: Scheduler::Parameter *_Parameter; friend class Mutex; ThreadAttribute *_ThreadAttribute; }; class ThreadPool { public: ThreadPool(size_t size); ~ThreadPool(); void addThread(Thread *thread); private: void _resize(size_t size); Thread **_ThreadPool; size_t _ThreadPoolSize; Mutex *_Mutex; friend class Thread; }; }; Loading libs/libsystempp/src/linux/sysinfo.cpp +3 −7 Original line number Diff line number Diff line Loading @@ -27,14 +27,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../include/sysinfo.h" libsysinfopp::SYSInfo::SYSInfo(){ libsystempp::sysinfo::CPUInfo::CPUInfo(){ } libsysinfopp::SYSInfo::~SYSInfo(){ libsystempp::sysinfo::CPUInfo::~CPUInfo(){ } unsigned libsysinfopp::SYSInfo::getNumberOfProcessors(){ unsigned libsystempp::sysinfo::CPUInfo::getNumberOfProcessors(){ //eax cores //ebx threads //edx actual thread Loading @@ -49,8 +49,4 @@ unsigned libsysinfopp::SYSInfo::getNumberOfProcessors(){ return eax; } int libsysinfopp::SYSInfo::getPid(){ return 0; } libs/libsystempp/src/linux/thread.cpp +44 −22 Original line number Diff line number Diff line Loading @@ -29,7 +29,10 @@ extern "C" { #include "wrapper.h" } #include <algorithm> #include "../include/thread.h" #include "../include/sysinfo.h" extern "C" { __attribute__((weak)) void *__dso_handle; Loading Loading @@ -70,59 +73,78 @@ bool libsystempp::Mutex::isLocked(){ return false; } libsystempp::Scheduler *libsystempp::Scheduler::_Instance = nullptr; int libsystempp::Scheduler::Parameter::getPolicy(){ int libsystempp::ThreadAttribute::getPolicy(){ return _Policy; } void libsystempp::Scheduler::Parameter::setPolicy(int policy){ void libsystempp::ThreadAttribute::setPolicy(int policy){ _Policy=policy; } int libsystempp::Scheduler::Parameter::getScope(){ int libsystempp::ThreadAttribute::getScope(){ return _Scope; } void libsystempp::Scheduler::Parameter::setScope(int scope){ void libsystempp::ThreadAttribute::setScope(int scope){ _Scope=scope; } void *libsystempp::Scheduler::Parameter::getStackAddr(){ void *libsystempp::ThreadAttribute::getStackAddr(){ return _StackAddr; } void libsystempp::Scheduler::Parameter::setStackAddr(void *stackaddr){ void libsystempp::ThreadAttribute::setStackAddr(void *stackaddr){ _StackAddr=stackaddr; } size_t libsystempp::Scheduler::Parameter::getStackSize(){ size_t libsystempp::ThreadAttribute::getStackSize(){ return _StackSize; } void libsystempp::Scheduler::Parameter::setStackSize(size_t stacksize){ void libsystempp::ThreadAttribute::setStackSize(size_t stacksize){ _StackSize=stacksize; } void libsystempp::Scheduler::Parameter::setGuardSize(size_t guardsize){ void libsystempp::ThreadAttribute::setGuardSize(size_t guardsize){ _GuardSize=guardsize; } size_t libsystempp::Scheduler::Parameter::getGuardSize(){ size_t libsystempp::ThreadAttribute::getGuardSize(){ return _GuardSize; } libsystempp::Scheduler *libsystempp::Scheduler::init(){ static Scheduler g; if(!_Instance) _Instance=new Scheduler(); return _Instance; libsystempp::Thread::Thread(void *method,void *args){ if(wrapper_clone2(method,this,sizeof(this), wrapper_clone_get_clone_thread_flag(),args)<0) throw "Clone Failed"; } libsystempp::Thread::Thread(void *args){ Thread((void*)&libsystempp::Thread::Run,args); } libsystempp::Thread::~Thread(){ } bool libsystempp::Thread::JoinAble(){ return true; } void libsystempp::Scheduler::delParameter(Parameter *param){ void *libsystempp::Thread::Run(void *args){ return NULL; } libsystempp::ThreadPool::ThreadPool(size_t size){ _Mutex = new Mutex(); _ThreadPoolSize = size; _ThreadPool = new Thread*[size]; } void libsystempp::Scheduler::addParameter(Parameter **param){ libsystempp::ThreadPool::~ThreadPool(){ delete _Mutex; delete[] _ThreadPool; } void libsystempp::ThreadPool::addThread(Thread *thread){ _Mutex->Lock(); _Mutex->unLock(); } libs/libsystempp/src/linux/wrapper.c +6 −0 Original line number Diff line number Diff line Loading @@ -54,4 +54,10 @@ int wrapper_mutex_is_locked(wrapper_mutex *mymutex){ mutex_is_locked((struct *mutex)mymutex); } int wrapper_clone_get_clone_thread_flag(){ return CLONE_THREAD; } int wrapper_clone2(void *fn,void *child_stack,size_t stack_size,int flags,void *args){ __clone2(fn,child_stack,stack_size,flags,args); } Loading
libs/libsystempp/src/include/sysinfo.h +10 −9 Original line number Diff line number Diff line namespace libsysinfopp { class SYSInfo { namespace libsystempp { namespace sysinfo { class CPUInfo { public: SYSInfo(); ~SYSInfo(); CPUInfo(); ~CPUInfo(); unsigned getNumberOfProcessors(); int getPid(); private: }; }; };
libs/libsystempp/src/include/thread.h +45 −42 Original line number Diff line number Diff line Loading @@ -25,13 +25,11 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <unistd.h> #define PTHREAD_INHERIT_SCHED 0 #define PTHREAD_EXPLICIT_SCHED 1 #ifndef size_t typedef unsigned int size_t; #endif #ifndef THREAD_H #define THREAD_H Loading @@ -50,10 +48,13 @@ namespace libsystempp { MutexData *_MutexData; }; class Scheduler { public: class Parameter { class ThreadAttribute { public: enum Policy { SCHED_FIFO=0, SCHED_RR=1, SCHED_OTHER=2 }; int getPolicy(); void setPolicy(int policy); int getScope(); Loading @@ -65,8 +66,8 @@ namespace libsystempp { void setGuardSize(size_t guardsize); size_t getGuardSize(); private: Parameter(); ~Parameter(); ThreadAttribute(); ~ThreadAttribute(); int _Policy; int _Scope; void *_StackAddr; Loading @@ -74,33 +75,35 @@ namespace libsystempp { size_t _GuardSize; friend class Scheduler; }; enum Policy { SCHED_FIFO=0, SCHED_RR=1, SCHED_OTHER=2 }; static Scheduler *init(); private: Scheduler(); ~Scheduler(); Scheduler(Scheduler const&); void delParameter(Parameter *param); void addParameter(Parameter **param); static Scheduler *_Instance; friend class Thread; }; class Thread { public: Thread(); Thread(void *method,void *args); Thread(void *args); ~Thread(); void Detach(); int DetachState(); Scheduler::Parameter *getinheritsched(); void setinheritsched(Scheduler::Parameter *param); void Join(void *rval=NULL); bool JoinAble(); ThreadAttribute *getinheritsched(); void setinheritsched(ThreadAttribute *attr); protected: virtual void *Run(void *args); private: Scheduler::Parameter *_Parameter; friend class Mutex; ThreadAttribute *_ThreadAttribute; }; class ThreadPool { public: ThreadPool(size_t size); ~ThreadPool(); void addThread(Thread *thread); private: void _resize(size_t size); Thread **_ThreadPool; size_t _ThreadPoolSize; Mutex *_Mutex; friend class Thread; }; }; Loading
libs/libsystempp/src/linux/sysinfo.cpp +3 −7 Original line number Diff line number Diff line Loading @@ -27,14 +27,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../include/sysinfo.h" libsysinfopp::SYSInfo::SYSInfo(){ libsystempp::sysinfo::CPUInfo::CPUInfo(){ } libsysinfopp::SYSInfo::~SYSInfo(){ libsystempp::sysinfo::CPUInfo::~CPUInfo(){ } unsigned libsysinfopp::SYSInfo::getNumberOfProcessors(){ unsigned libsystempp::sysinfo::CPUInfo::getNumberOfProcessors(){ //eax cores //ebx threads //edx actual thread Loading @@ -49,8 +49,4 @@ unsigned libsysinfopp::SYSInfo::getNumberOfProcessors(){ return eax; } int libsysinfopp::SYSInfo::getPid(){ return 0; }
libs/libsystempp/src/linux/thread.cpp +44 −22 Original line number Diff line number Diff line Loading @@ -29,7 +29,10 @@ extern "C" { #include "wrapper.h" } #include <algorithm> #include "../include/thread.h" #include "../include/sysinfo.h" extern "C" { __attribute__((weak)) void *__dso_handle; Loading Loading @@ -70,59 +73,78 @@ bool libsystempp::Mutex::isLocked(){ return false; } libsystempp::Scheduler *libsystempp::Scheduler::_Instance = nullptr; int libsystempp::Scheduler::Parameter::getPolicy(){ int libsystempp::ThreadAttribute::getPolicy(){ return _Policy; } void libsystempp::Scheduler::Parameter::setPolicy(int policy){ void libsystempp::ThreadAttribute::setPolicy(int policy){ _Policy=policy; } int libsystempp::Scheduler::Parameter::getScope(){ int libsystempp::ThreadAttribute::getScope(){ return _Scope; } void libsystempp::Scheduler::Parameter::setScope(int scope){ void libsystempp::ThreadAttribute::setScope(int scope){ _Scope=scope; } void *libsystempp::Scheduler::Parameter::getStackAddr(){ void *libsystempp::ThreadAttribute::getStackAddr(){ return _StackAddr; } void libsystempp::Scheduler::Parameter::setStackAddr(void *stackaddr){ void libsystempp::ThreadAttribute::setStackAddr(void *stackaddr){ _StackAddr=stackaddr; } size_t libsystempp::Scheduler::Parameter::getStackSize(){ size_t libsystempp::ThreadAttribute::getStackSize(){ return _StackSize; } void libsystempp::Scheduler::Parameter::setStackSize(size_t stacksize){ void libsystempp::ThreadAttribute::setStackSize(size_t stacksize){ _StackSize=stacksize; } void libsystempp::Scheduler::Parameter::setGuardSize(size_t guardsize){ void libsystempp::ThreadAttribute::setGuardSize(size_t guardsize){ _GuardSize=guardsize; } size_t libsystempp::Scheduler::Parameter::getGuardSize(){ size_t libsystempp::ThreadAttribute::getGuardSize(){ return _GuardSize; } libsystempp::Scheduler *libsystempp::Scheduler::init(){ static Scheduler g; if(!_Instance) _Instance=new Scheduler(); return _Instance; libsystempp::Thread::Thread(void *method,void *args){ if(wrapper_clone2(method,this,sizeof(this), wrapper_clone_get_clone_thread_flag(),args)<0) throw "Clone Failed"; } libsystempp::Thread::Thread(void *args){ Thread((void*)&libsystempp::Thread::Run,args); } libsystempp::Thread::~Thread(){ } bool libsystempp::Thread::JoinAble(){ return true; } void libsystempp::Scheduler::delParameter(Parameter *param){ void *libsystempp::Thread::Run(void *args){ return NULL; } libsystempp::ThreadPool::ThreadPool(size_t size){ _Mutex = new Mutex(); _ThreadPoolSize = size; _ThreadPool = new Thread*[size]; } void libsystempp::Scheduler::addParameter(Parameter **param){ libsystempp::ThreadPool::~ThreadPool(){ delete _Mutex; delete[] _ThreadPool; } void libsystempp::ThreadPool::addThread(Thread *thread){ _Mutex->Lock(); _Mutex->unLock(); }
libs/libsystempp/src/linux/wrapper.c +6 −0 Original line number Diff line number Diff line Loading @@ -54,4 +54,10 @@ int wrapper_mutex_is_locked(wrapper_mutex *mymutex){ mutex_is_locked((struct *mutex)mymutex); } int wrapper_clone_get_clone_thread_flag(){ return CLONE_THREAD; } int wrapper_clone2(void *fn,void *child_stack,size_t stack_size,int flags,void *args){ __clone2(fn,child_stack,stack_size,flags,args); }