示例#1
0
static inline bool
test_thread_create(test_thread_t *ttptr,
                   lagopus_mutex_t start_lock,
                   lagopus_bbq_t bbq,
                   ssize_t n,
                   const char *name) {
  bool ret = false;

  if (ttptr != NULL) {
    test_thread_t tt;
    if (*ttptr == NULL) {
      tt = (test_thread_t)malloc(sizeof(*tt));
      if (tt == NULL) {
        goto done;
      }
    } else {
      tt = *ttptr;
    }
    ret = s_initialize(tt, start_lock, bbq, n, name);
    if (*ttptr == NULL) {
      *ttptr = tt;
    }
  }

done:
  return ret;
}
示例#2
0
mccp_result_t
mccp_thread_create(mccp_thread_t *thdptr,
                   mccp_thread_main_proc_t mainproc,
                   mccp_thread_finalize_proc_t finalproc,
                   mccp_thread_freeup_proc_t freeproc,
                   const char *name,
                   void *arg) {
  mccp_result_t ret = MCCP_RESULT_ANY_FAILURES;

  if (thdptr != NULL &&
      mainproc != NULL) {
    mccp_thread_t thd;

    if (*thdptr != NULL) {
      thd = *thdptr;
    } else {
      thd = (mccp_thread_t)malloc(sizeof(*thd));
      if (thd == NULL) {
        *thdptr = NULL;
        ret = MCCP_RESULT_NO_MEMORY;
        goto done;
      }
      s_alloc_mark_thd(thd);
    }
    ret = s_initialize(thd, mainproc, finalproc, freeproc, name, arg);
    if (ret != MCCP_RESULT_OK) {
      s_destroy(thd);
      thd = NULL;
    }
    if (*thdptr == NULL) {
      *thdptr = thd;
    }
  } else {
    ret = MCCP_RESULT_INVALID_ARGS;
  }

done:
  return ret;
}
示例#3
0
static inline bool
test_thread_create(test_thread_t *ttptr, size_t n) {
  bool ret = false;

  if (ttptr != NULL) {
    test_thread_t tt;
    if (*ttptr == NULL) {
      tt = (test_thread_t)malloc(sizeof(*tt));
      if (tt == NULL) {
        goto done;
      }
    } else {
      tt = *ttptr;
    }
    ret = s_initialize(tt, n);
    if (*ttptr == NULL && ret == true) {
      *ttptr = tt;
      (void)lagopus_thread_free_when_destroy((lagopus_thread_t *)&tt);
    }
  }

done:
  return ret;
}