| 57 | |
| 58 | #else |
| 59 | class clsFdMap // million of fd , 1024 * 1024 |
| 60 | { |
| 61 | private: |
| 62 | static const int row_size = 1024; |
| 63 | static const int col_size = 1024; |
| 64 | |
| 65 | void **m_pp[ 1024 ]; |
| 66 | public: |
| 67 | clsFdMap() |
| 68 | { |
| 69 | memset( m_pp,0,sizeof(m_pp) ); |
| 70 | } |
| 71 | ~clsFdMap() |
| 72 | { |
| 73 | for(int i=0;i<sizeof(m_pp)/sizeof(m_pp[0]);i++) |
| 74 | { |
| 75 | if( m_pp[i] ) |
| 76 | { |
| 77 | free( m_pp[i] ); |
| 78 | m_pp[i] = NULL; |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | inline int clear( int fd ) |
| 83 | { |
| 84 | set( fd,NULL ); |
| 85 | return 0; |
| 86 | } |
| 87 | inline int set( int fd,const void * ptr ) |
| 88 | { |
| 89 | int idx = fd / row_size; |
| 90 | if( idx < 0 || idx >= sizeof(m_pp)/sizeof(m_pp[0]) ) |
| 91 | { |
| 92 | assert( __LINE__ == 0 ); |
| 93 | return -__LINE__; |
| 94 | } |
| 95 | if( !m_pp[ idx ] ) |
| 96 | { |
| 97 | m_pp[ idx ] = (void**)calloc( 1,sizeof(void*) * col_size ); |
| 98 | } |
| 99 | m_pp[ idx ][ fd % col_size ] = (void*)ptr; |
| 100 | return 0; |
| 101 | } |
| 102 | inline void *get( int fd ) |
| 103 | { |
| 104 | int idx = fd / row_size; |
| 105 | if( idx < 0 || idx >= sizeof(m_pp)/sizeof(m_pp[0]) ) |
| 106 | { |
| 107 | return NULL; |
| 108 | } |
| 109 | void **lp = m_pp[ idx ]; |
| 110 | if( !lp ) return NULL; |
| 111 | |
| 112 | return lp[ fd % col_size ]; |
| 113 | } |
| 114 | }; |
| 115 | |
| 116 | __thread clsFdMap *s_fd_map = NULL; |
nothing calls this directly
no outgoing calls
no test coverage detected