wangzhengquan
2021-01-25 3a5e5ca9bce4bd4956e59e76a95f0ec207d711ff
解决kill -9问题
5个文件已修改
63 ■■■■■ 已修改文件
src/futex_sem.cpp 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/queue/array_lock_free_sem_queue.h 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/queue/lock_free_queue.h 42 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test_net_socket/heart_beat.sh 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test_net_socket/test_net_mod_socket.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/futex_sem.cpp
@@ -1,8 +1,10 @@
#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);
}
src/queue/array_lock_free_sem_queue.h
@@ -241,8 +241,8 @@
      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;
@@ -320,8 +320,7 @@
        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);
src/queue/lock_free_queue.h
@@ -210,28 +210,37 @@
      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;
}
@@ -239,30 +248,39 @@
        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,
test_net_socket/heart_beat.sh
@@ -1,7 +1,7 @@
#! /bin/bash
PROCESSES=4
function clean() {
function close() {
    ipcrm -a
    ps -ef | grep "heart_beat" | awk  '{print $2}' | xargs -i kill -9 {}
     
@@ -44,8 +44,8 @@
  ;;
  "clean")
  clean
  "close")
  close
  ;;
  "")
test_net_socket/test_net_mod_socket.cpp
@@ -269,7 +269,7 @@
    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,