📄 wy__base.h
字号:
/* Copyright is licensed under GNU LGPL. by I.J.Wang 2003 Wy__Base intends to provide the basic support for WyLIb functions. Note: This file is intended to be included in wydefs.h*/#ifndef WY__BASE_H__#define WY__BASE_H__#include <cerrno>#include <pthread.h>#include <sched.h> // for sched_yield#include <exception>namespace Wy__Base { // [Syn] Mark cancellation point // inline void cancel_point(void) { ::pthread_testcancel(); }; // errno is assumed not modified // [Syn] Change cancellation state // // state is one of the value: // PTHREAD_CANCEL_ENABLE // PTHREAD_CANCEL_DISABLE // // [Ret] 0 Ok // errno otherwise // // [Refer] ::pthread_setcancelstate(int,int*) // inline int pthread_setcancelstate(int state, int* oldstate) WY__TSPC() { return ::pthread_setcancelstate(state,oldstate); }; // Convenient class for no cancel // class NoCancel { public: // [Syn] Construct object and disable cancellablity of the calling // thread. // // [Throw] int (errno) // NoCancel(); // [Syn] Destruct *this and recover the previous cancelablity // // [Throw] int (errno) // ~NoCancel(); private: int _oldstate; NoCancel(const NoCancel&); const NoCancel& operator =(const NoCancel&); bool operator ==(const NoCancel&); }; // [Syn] Yield thread execution // // [Ret] 0= ok // otherwise= failure, errno // inline int yield(void) WY__TSPC() { return (::sched_yield()==0)? 0: errno; }; // [Syn] Abort the program // // Note: I had problem with this function inlined. // //void abort(void) throw() __attribute__ ((__noreturn__)); // [Syn] Abort the program // // Note: I had problem with this function inlined. // It seemed senseless to use throw() explicitly // void terminate(void) WY__NOTHROW__ __attribute__ ((__noreturn__)); // [NoCancel] // [Syn] Print abnormal terminate message // // [Ret] errno encountered // int put_abnmsg(const char* expr,const char *file_name, unsigned int lnum) WY__TSPC(); // [NoCancel] // [Syn] Write message to STDERR_FILENO // // [Ret] 0= Ok // otherwise= errno // int put_errmsg(const char* msg) WY__TSPC(); // [Syn] Swap n bytes of the two memory area pointed by p1 and p2 // void memswp(void* p1,void* p2,size_t n) WY__TSPC(); // // [Internal] Swap scalar type (value swap) // template<typename T> void vswap(T& t1,T& t2) WY__TSPC() { const T t0(t1); t1=t2; t2=t0; };}; // End of Wy__Base#define WY__EQU_TYPEID(a,b) (typeid(a)==typeid(b))#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -