| | |
| | | #include "futex_sem.h" |
| | | |
| | | #include "time_util.h" |
| | | |
| | | int futex(int *uaddr, int futex_op, int val, |
| | | const struct timespec *timeout, int *uaddr2, int val3) |
| | | { |
| | | return syscall(SYS_futex, uaddr, futex_op, val, timeout, uaddr, val3); |
| | | |
| | | const struct timespec ts = TimeUtil::trim_time(timeout); |
| | | return syscall(SYS_futex, uaddr, futex_op, val, &ts, uaddr, val3); |
| | | } |
| | |
| | | if( (flag & BUS_NOWAIT_FLAG) == BUS_NOWAIT_FLAG) |
| | | return errno; |
| | | else if( (flag & BUS_TIMEOUT_FLAG) == BUS_TIMEOUT_FLAG && timeout != NULL) { |
| | | const struct timespec ts = TimeUtil::trim_time(timeout); |
| | | s = futex((int *)&m_readIndex, FUTEX_WAIT, tmpIndex, &ts, NULL, 0); |
| | | |
| | | s = futex((int *)&m_readIndex, FUTEX_WAIT, tmpIndex, timeout, NULL, 0); |
| | | if (s == -1 && errno != EAGAIN && errno != EINTR) { |
| | | // err_exit("ArrayLockFreeSemQueue<ELEM_T, Allocator>::push futex-FUTEX_WAIT"); |
| | | return errno; |
| | |
| | | return errno; |
| | | } |
| | | else if( (flag & BUS_TIMEOUT_FLAG) == BUS_TIMEOUT_FLAG && timeout != NULL) { |
| | | const struct timespec ts = TimeUtil::trim_time(timeout); |
| | | s = futex((int *)&m_count, FUTEX_WAIT, 0, &ts, NULL, 0); |
| | | s = futex((int *)&m_count, FUTEX_WAIT, 0, timeout, NULL, 0); |
| | | if (s == -1 && errno != EAGAIN && errno != EINTR) { |
| | | // err_exit("ArrayLockFreeSemQueue<ELEM_T, Allocator>::push futex-FUTEX_WAIT"); |
| | | // sigprocmask(SIG_SETMASK, &pre, NULL); |
| | |
| | | typename Allocator, |
| | | template<typename T, typename AT> class Q_TYPE> |
| | | int LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::push(const ELEM_T &a_data, const struct timespec *timeout, int flag) { |
| | | LoggerFactory::getLogger()->debug("==================LockFreeQueue push before\n"); |
| | | // LoggerFactory::getLogger()->debug("==================LockFreeQueue push before\n"); |
| | | sigset_t mask_all, pre; |
| | | sigfillset(&mask_all); |
| | | |
| | | sigprocmask(SIG_BLOCK, &mask_all, &pre); |
| | | |
| | | if ((flag & BUS_NOWAIT_FLAG) == BUS_NOWAIT_FLAG) { |
| | | if (psem_trywait(&slots) == -1) { |
| | | return errno; |
| | | goto LABEL_FAILTURE; |
| | | } |
| | | } else if ((flag & BUS_TIMEOUT_FLAG) == BUS_TIMEOUT_FLAG && timeout != NULL) { |
| | | if (psem_timedwait(&slots, timeout) == -1) { |
| | | return errno; |
| | | goto LABEL_FAILTURE; |
| | | } |
| | | } else { |
| | | if (psem_wait(&slots) == -1) { |
| | | return errno; |
| | | goto LABEL_FAILTURE; |
| | | } |
| | | } |
| | | |
| | | |
| | | if (m_qImpl.push(a_data)) { |
| | | psem_post(&items); |
| | | sigprocmask(SIG_SETMASK, &pre, NULL); |
| | | LoggerFactory::getLogger()->debug("==================LockFreeQueue push after\n"); |
| | | return 0; |
| | | } |
| | | return -1; |
| | | |
| | | LABEL_FAILTURE: |
| | | sigprocmask(SIG_SETMASK, &pre, NULL); |
| | | return errno; |
| | | |
| | | } |
| | | |
| | |
| | | typename Allocator, |
| | | template<typename T, typename AT> class Q_TYPE> |
| | | int LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::pop(ELEM_T &a_data, const struct timespec *timeout, int flag) { |
| | | LoggerFactory::getLogger()->debug("==================LockFreeQueue pop before...."); |
| | | // LoggerFactory::getLogger()->debug("==================LockFreeQueue pop before...."); |
| | | |
| | | sigset_t mask_all, pre; |
| | | sigfillset(&mask_all); |
| | | |
| | | sigprocmask(SIG_BLOCK, &mask_all, &pre); |
| | | |
| | | if ((flag & BUS_NOWAIT_FLAG) == BUS_NOWAIT_FLAG) { |
| | | if (psem_trywait(&items) == -1) { |
| | | return errno; |
| | | goto LABEL_FAILTURE; |
| | | } |
| | | } else if ((flag & BUS_TIMEOUT_FLAG) == BUS_TIMEOUT_FLAG && timeout != NULL) { |
| | | LoggerFactory::getLogger()->debug("==================LockFreeQueue pop before. flag=%d , %d\n", flag, timeout->tv_sec); |
| | | // LoggerFactory::getLogger()->debug("==================LockFreeQueue pop before. flag=%d , %d\n", flag, timeout->tv_sec); |
| | | if (psem_timedwait(&items, timeout) == -1) { |
| | | return errno; |
| | | goto LABEL_FAILTURE; |
| | | } |
| | | } else { |
| | | if (psem_wait(&items) == -1) { |
| | | return errno; |
| | | goto LABEL_FAILTURE; |
| | | } |
| | | } |
| | | |
| | | |
| | | if (m_qImpl.pop(a_data)) { |
| | | psem_post(&slots); |
| | | LoggerFactory::getLogger()->debug("==================LockFreeQueue pop after\n"); |
| | | sigprocmask(SIG_SETMASK, &pre, NULL); |
| | | // LoggerFactory::getLogger()->debug("==================LockFreeQueue pop after\n"); |
| | | return 0; |
| | | } |
| | | return -1; |
| | | |
| | | LABEL_FAILTURE: |
| | | sigprocmask(SIG_SETMASK, &pre, NULL); |
| | | return errno; |
| | | } |
| | | |
| | | template<typename ELEM_T, |
| | |
| | | #! /bin/bash |
| | | |
| | | PROCESSES=4 |
| | | function clean() { |
| | | function close() { |
| | | ipcrm -a |
| | | ps -ef | grep "heart_beat" | awk '{print $2}' | xargs -i kill -9 {} |
| | | |
| | |
| | | ;; |
| | | |
| | | |
| | | "clean") |
| | | clean |
| | | "close") |
| | | close |
| | | ;; |
| | | |
| | | "") |
| | |
| | | fprintf(fp, "requst:%s\n", sendbuf); |
| | | // n = net_mod_socket_sendandrecv(client, node_arr, node_arr_size, sendbuf, strlen(sendbuf) + 1, &recv_arr, &recv_arr_size); |
| | | n = net_mod_socket_sendandrecv_timeout(client, node_arr, node_arr_size, sendbuf, strlen(sendbuf) + 1, &recv_arr, &recv_arr_size, 1000); |
| | | printf("send %d nodes\n", n); |
| | | printf("%d: send %d nodes\n", i, n); |
| | | for(j=0; j < recv_arr_size; j++) { |
| | | fprintf(fp, "reply: host:%s, port: %d, key:%d, content: %s\n", |
| | | recv_arr[j].host, |