| | |
| | | template<typename ELEM_T, typename Allocator> |
| | | ArrayLockFreeQueue<ELEM_T, Allocator>::~ArrayLockFreeQueue() { |
| | | // std::cout << "destroy ArrayLockFreeQueue\n"; |
| | | |
| | | Allocator::deallocate(m_theQueue); |
| | | |
| | | } |
| | |
| | | sem_t slots; |
| | | sem_t items; |
| | | |
| | | time_t createTime; |
| | | time_t closeTime; |
| | | int status; |
| | | // time_t createTime; |
| | | // time_t closeTime; |
| | | // int status; |
| | | |
| | | public: |
| | | |
| | |
| | | /// template |
| | | ~LockFreeQueue(); |
| | | |
| | | inline void close(); |
| | | // inline void close(); |
| | | |
| | | // std::atomic_uint reference; |
| | | /// @brief constructor of the class |
| | |
| | | |
| | | |
| | | |
| | | time_t getCreateTime() { |
| | | return createTime; |
| | | } |
| | | // time_t getCreateTime() { |
| | | // return createTime; |
| | | // } |
| | | |
| | | time_t getCloseTime() { |
| | | return closeTime; |
| | | } |
| | | // time_t getCloseTime() { |
| | | // return closeTime; |
| | | // } |
| | | |
| | | int getStatus() { |
| | | return status; |
| | | } |
| | | // int getStatus() { |
| | | // return status; |
| | | // } |
| | | |
| | | /// @brief push an element at the tail of the queue |
| | | /// @param the element to insert in the queue |
| | |
| | | if (sem_init(&items, 1, 0) == -1) |
| | | err_exit(errno, "LockFreeQueue sem_init"); |
| | | |
| | | createTime = time(NULL); |
| | | status = LOCK_FREE_Q_ST_OPENED; |
| | | // createTime = time(NULL); |
| | | // status = LOCK_FREE_Q_ST_OPENED; |
| | | |
| | | } |
| | | |
| | | |
| | | template< |
| | | typename ELEM_T, |
| | | typename Allocator, |
| | | template<typename T, typename AT> class Q_TYPE> |
| | | inline void LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::close() { |
| | | status = LOCK_FREE_Q_ST_CLOSED; |
| | | closeTime = time(NULL); |
| | | } |
| | | // template< |
| | | // typename ELEM_T, |
| | | // typename Allocator, |
| | | // template<typename T, typename AT> class Q_TYPE> |
| | | // inline void LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::close() { |
| | | // // status = LOCK_FREE_Q_ST_CLOSED; |
| | | // // closeTime = time(NULL); |
| | | // } |
| | | |
| | | |
| | | template< |
| | |
| | | |
| | | static int _shm_socket_close_(shm_socket_t *sockt) { |
| | | |
| | | int rv; |
| | | int rv, i; |
| | | logger->debug("shm_socket_close\n"); |
| | | // hashtable_remove(hashtable, mkey); |
| | | // if(sockt->queue != NULL) { |
| | | // sockt->queue = NULL; |
| | | // } |
| | | |
| | | |
| | | if(sockt->key != 0) { |
| | | auto it = shmQueueStMap->find(sockt->key); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | printf("====sockt->queue addr = %p\n", sockt->queue); |
| | | |
| | | if(sockt->queue != NULL) { |
| | | for( i = 0; i < sockt->queue->size(); i++) { |
| | | mm_free((*(sockt->queue))[i].buf); |
| | | logger->info("======= %d free queue element buf\n", sockt->key); |
| | | } |
| | | |
| | | // hashtable_remove(hashtable, mkey); |
| | | // sockt->queue = NULL; |
| | | } |
| | | |
| | | |
| | | // hashtable_remove(hashtable, mkey); |
| | | // if(sockt->queue != NULL) { |
| | | // sockt->queue = NULL; |
| | | // } |
| | | |
| | | |
| | | pthread_mutex_destroy(&(sockt->mutex) ); |
| | |
| | | int shm_socket_get_key(shm_socket_t *sockt){ |
| | | return sockt->key; |
| | | } |
| | | |
| | | |
| | | |
| | | // 短连接方式发送 |
| | | int shm_sendto(shm_socket_t *sockt, const void *buf, const int size, |