Esempio n. 1
0
void
mccp_thread_destroy(mccp_thread_t *thdptr) {
  if (thdptr != NULL &&
      *thdptr != NULL) {

    if (s_is_thd(*thdptr) == true) {

      (void)mccp_thread_cancel(thdptr);
      (void)mccp_thread_wait(thdptr, -1);

      s_wait_lock(*thdptr);
      {
        if ((*thdptr)->m_is_destroying == false) {
          (*thdptr)->m_is_destroying = true;
          if ((*thdptr)->m_freeup_proc != NULL) {
            (*thdptr)->m_freeup_proc(thdptr, (*thdptr)->m_arg);
          }
        }
      }
      s_wait_unlock(*thdptr);

      s_destroy(*thdptr);
      *thdptr = NULL;

    }
  }
}
Esempio n. 2
0
void client_proxy(zsock_t *pipe, void *arg) {
    client_proxy_t *self = s_new(pipe);
    assert(self);
    zsock_signal(self->pipe, 0);
    zloop_reader(self->loop, self->pipe, pipe_loop_handler, self);
    zloop_start(self->loop);
    zloop_reader_end(self->loop, self->pipe);
    if (self->rep != NULL)
        zloop_reader_end(self->loop, self->rep);
    s_destroy(&self);
}
Esempio n. 3
0
void ticket_hid_printer(zsock_t *pipe, void *arg) {
    char *device_path = (char *) arg;
    ticket_printer_t *self = s_new(pipe, device_path);
    zsock_signal(self->pipe, 0);

    int main_timer_id = zloop_timer(self->loop, 300, 0, timer_main_loop, self);
    zloop_reader(self->loop, self->pipe, reader_pipe_event, self);
    zloop_start(self->loop);
    zloop_timer_end(self->loop, main_timer_id);
    zloop_reader_end(self->loop, self->pipe);
    s_destroy(&self);
}
Esempio n. 4
0
void ticket_serial_printer(zsock_t *pipe, void *arg) {
    char *port = (char *) arg;
    ticket_printer_t *self = s_new_serial(pipe, port);
    zsock_signal(self->pipe, 0);

    int main_serial_id = zloop_timer(self->loop, 300, 0, timer_main_serial_loop, self);
    zloop_reader(self->loop, self->pipe, reader_pipe_event, self);
    zloop_start(self->loop);
    zloop_reader_end(self->loop, self->pipe);
    zloop_timer_end(self->loop, main_serial_id);
    s_destroy(&self);
}
Esempio n. 5
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;
}