Пример #1
0
void dnx_mutex_uninit(dnx_mutex_t *mutex)
{
  DNX_ASSERT(NULL != mutex);
  DNX_ASSERT(TRUE == mutex->created);

  _dnx_mutex_uninit(mutex);
}
Пример #2
0
static void dnx_mutex_operation(dnx_mutex_t *mutex, int lock)
{ 
  int rc = 0;

  DNX_ASSERT(NULL != mutex);

  rc = lock ? pthread_mutex_lock(&mutex->os_mutex) : 
    pthread_mutex_unlock(&mutex->os_mutex);
  DNX_ASSERT (0 == rc);
}
Пример #3
0
void dnx_thread_exit(dnx_thread_t *thread)
{ 
  dnx_status_t rc = DNX_ERR_OK;
  DNX_ASSERT(NULL != thread);
  DNX_ASSERT(FALSE == thread->should_exit);

  thread->should_exit = TRUE;

  rc = dnx_event_wait(&thread->event, DNX_WAIT_FOREVER);

  DNX_ASSERT(DNX_ERR_OK == rc);

  dnx_event_uninit(&thread->event);
}
Пример #4
0
void dnx_event_set(dnx_event_t *event)
{
  DNX_ASSERT(NULL != event);

  event->wait_flag = 1;
  wake_up(&event->wait_queue);
}
Пример #5
0
void dnx_rmlock_uninit(dnx_rmlock_t *lock)
{
  DNX_ASSERT(NULL != lock);

  if (TRUE == lock->event_initialized)
    dnx_event_uninit(&lock->event);
}
Пример #6
0
dnx_status_t dnx_rmlock_add_ex(dnx_rmlock_t *lock, uint32_t count)
{
  DNX_ASSERT(NULL != lock);

  dnx_atomic32_add(&lock->cnt, count);
  return DNX_ERR_OK;
}
Пример #7
0
void dnx_thread_exit(dnx_thread_t *thread)
{
  DNX_ASSERT(NULL != thread);

  thread->should_exit = TRUE;

  WaitForSingleObject(thread->hthread, INFINITE);
}
Пример #8
0
void dnx_log(const char *func, uint32_t line,
  dnx_log_level_t level, const char *fmt, ...)
{
  char buff[DNX_MAX_LOG_BUFF] = {0};
  int n = 0, offset = 0;
  va_list va;

  if (log_flags & DNX_LOG_FLAG_TIMESTAMP)
  {
    n = dnx_snprintf(buff + offset, DNX_MAX_LOG_BUFF - offset, "[%010u] ",
      dnx_timestamp());
    if (n >= DNX_MAX_LOG_BUFF - offset)
    {
      goto Exit;
    }
    offset += n;
  }

  switch (level) {
  case DNX_LOG_LEVEL_ERROR:
    n = dnx_snprintf(buff + offset, DNX_MAX_LOG_BUFF - offset, "Error: ");
    break;
  case DNX_LOG_LEVEL_WARNING:
    n = dnx_snprintf(buff + offset, DNX_MAX_LOG_BUFF - offset, "Warning: ");
    break;
  case DNX_LOG_LEVEL_INFO:
    n = dnx_snprintf(buff + offset, DNX_MAX_LOG_BUFF - offset, "Info: ");
    break;
  case DNX_LOG_LEVEL_EXTRA:
    n = dnx_snprintf(buff + offset, DNX_MAX_LOG_BUFF - offset, "Extra: ");
    break;
  default:
    DNX_ASSERT(0);
  } 
  if (n >= DNX_MAX_LOG_BUFF - offset)
    {
      goto Exit;
    }

  offset += n;

  n = dnx_snprintf(buff + offset, DNX_MAX_LOG_BUFF - offset, "[%s: (%d)]: ", func,
    line);
  if (n >= DNX_MAX_LOG_BUFF - offset)
  {
    goto Exit;
  }
  offset += n;

  va_start(va, fmt);
  vsnprintf(buff + offset, DNX_MAX_LOG_BUFF - offset, fmt, va);
  va_end(va);

Exit:
  syslog(dnx_convert_prioroty(level), "%s", buff);
}
Пример #9
0
dnx_status_t dnx_rmlock_rem_ex(dnx_rmlock_t *lock, uint32_t count)
{  
  DNX_ASSERT(NULL != lock);

  dnx_atomic32_sub(&lock->cnt, count);

  if (0 == dnx_atomic32_get(&lock->cnt))
    dnx_event_set(&lock->event);

  return DNX_ERR_OK;
}
Пример #10
0
dnx_status_t dnx_thread_create(dnx_thread_t *thread, dnx_thread_cb_t cb,
  void *ctx)
{
  dnx_status_t rc = DNX_ERR_OK;
  int os_rc = 0;

  DNX_ASSERT(NULL != thread);
  DNX_ASSERT(NULL != cb);

  thread->cb = cb;
  thread->ctx =ctx;

  thread->hthread = CreateThread(NULL, 0, 
    (LPTHREAD_START_ROUTINE)dnx_thread_run, thread, 0, NULL);

  if (NULL == thread->hthread)
    rc = DNX_ERR_UNKNOWN;

  return rc;
}
Пример #11
0
void dnx_log(const char *func, uint32_t line,
  dnx_log_level_t level, const char *fmt, ...)
{
  char buff[DNX_MAX_LOG_BUFF] = {0};
  int n = 0, offset = 0;
  va_list va;

  if (level > dnx_max_dlevel)
    goto Exit;

  if (log_flags & DNX_LOG_FLAG_TIMESTAMP)
  {
    n = dnx_snprintf(buff + offset, DNX_MAX_LOG_BUFF - offset, "[%010u] ",
      dnx_timestamp());
    if (n >= DNX_MAX_LOG_BUFF - offset)
    {
      goto Exit;
    }
    offset += n;
  }

  n = dnx_snprintf(buff + offset, DNX_MAX_LOG_BUFF - offset, "[%s: (%d)]: ", func,
    line);
  if (n >= DNX_MAX_LOG_BUFF - offset)
  {
    goto Exit;
  }
  offset += n;

  va_start(va, fmt);
  dnx_vsnprintf(buff + offset, DNX_MAX_LOG_BUFF - offset, fmt, va);
  va_end(va);

Exit:
  switch (level)
  {
  case DNX_LOG_LEVEL_ERROR:
    printk(KERN_ERR "%s", buff);
    return;
  case DNX_LOG_LEVEL_WARNING:
    printk(KERN_WARNING "%s", buff);
    return;
  case DNX_LOG_LEVEL_INFO:
    printk(KERN_INFO "%s", buff);
    return;
  case DNX_LOG_LEVEL_EXTRA:
    printk(KERN_DEBUG "%s", buff);
    return;
  default:
    DNX_ASSERT(0);
    break;
  }
}
Пример #12
0
static void _dnx_mutex_uninit(dnx_mutex_t *mutex)
{
  if (mutex)
  {
    if (TRUE == mutex->created)
    {
      int os_rc = pthread_mutex_destroy(&mutex->os_mutex);
      DNX_ASSERT(0 == os_rc);
    }

    dnx_free(mutex);
  }
}
Пример #13
0
dnx_status_t dnx_event_wait(dnx_event_t *event, uint32_t msec)
{
  int res;

  DNX_ASSERT(NULL != event);

  res = msec?wait_event_timeout(event->wait_queue,
                                event->wait_flag,
                                msecs_to_jiffies(msec)):event->wait_flag;

  if (event->wait_flag)
    res = DNX_ERR_OK;
  else if (res == 0)
    res = DNX_ERR_TIMEOUT;
  else {
    // make sure we cover all cases
    printk(KERN_ALERT "wait_event_timeout returned %d", res);
    DNX_ASSERT(FALSE);
  }

  return res;
}
Пример #14
0
dnx_status_t dnx_event_init(dnx_event_t *event)
{
  dnx_status_t rc = DNX_ERR_OK;

  DNX_ASSERT(NULL != event);

  event->wait_flag = 0;
  init_waitqueue_head(&event->wait_queue);

  if (DNX_ERR_OK != rc && NULL != event)
    dnx_event_uninit(event);

  return rc;
}
Пример #15
0
dnx_status_t dnx_thread_create(dnx_thread_t *thread, dnx_thread_cb_t cb,
  void *ctx)
{
  dnx_status_t rc = DNX_ERR_OK;
  int os_rc = 0;

  DNX_ASSERT(NULL != thread);
  DNX_ASSERT(NULL != cb);

  thread->cb = cb;
  thread->ctx =ctx;
  thread->event_initialized = FALSE;

  rc = dnx_event_init(&thread->event); 
  if (DNX_ERR_OK != rc)
  {
    dnx_log_e("Failed to initialize event object\n");
    goto Exit;
  }

  thread->event_initialized = TRUE;
  thread->kthread = kthread_run(dnx_thread_run, thread,
    "dnx_tread");

  if (NULL == thread->kthread)
    rc = dnx_os_err_to_dnx_err(os_rc);

Exit:
  if (DNX_ERR_OK != rc && NULL != thread)
  {
    if (TRUE == thread->event_initialized)
      dnx_event_uninit(&thread->event);
  }

  return rc;
}
Пример #16
0
static int dnx_convert_prioroty(dnx_log_level_t level)
{  
  switch (level)
  {
  case DNX_LOG_LEVEL_ERROR:
    return LOG_ERR;
  case DNX_LOG_LEVEL_WARNING:
    return LOG_WARNING;
  case DNX_LOG_LEVEL_INFO:
    return LOG_INFO;
  case DNX_LOG_LEVEL_EXTRA:
    return LOG_DEBUG;
  default:
    DNX_ASSERT(0);
    return -1;
  }
}
Пример #17
0
dnx_status_t dnx_rmlock_init(dnx_rmlock_t *lock)
{
  dnx_status_t rc = DNX_ERR_OK;

  DNX_ASSERT(NULL != lock);
  lock->event_initialized = FALSE;

  rc = dnx_event_init(&lock->event);
  if (DNX_ERR_OK != rc)
    goto Exit;

  lock->event_initialized = TRUE;

  dnx_atomic32_set(&lock->cnt, 0);

Exit:
  if (DNX_ERR_OK != rc && NULL != lock)
    dnx_rmlock_uninit(lock);

  return rc;
}
Пример #18
0
bool_t dnx_thread_should_exit(dnx_thread_t *thread)
{
  DNX_ASSERT(NULL != thread);

  return thread->should_exit;
}
Пример #19
0
void dnx_event_uninit(dnx_event_t *event)
{
  DNX_ASSERT(NULL != event);
}
Пример #20
0
void dnx_log(const char *func, uint32_t line,
  dnx_log_level_t level, const char *fmt, ...)
{
  char buff[DNX_MAX_LOG_BUFF] = {0};
  int offset = 0, n = 0;
  va_list va;

  if (level > os_max_level)
    return;

  if (log_flags & DNX_LOG_FLAG_TIMESTAMP)
  {
    n = dnx_snprintf(buff + offset, DNX_MAX_LOG_BUFF - offset, "[%010u] ",
      dnx_timestamp());
    if (n >= DNX_MAX_LOG_BUFF - offset)
    {
      goto Exit;
    }
    offset += n;
  }

  switch (level) {
  case DNX_LOG_LEVEL_ERROR:
    n = dnx_snprintf(buff + offset, DNX_MAX_LOG_BUFF - offset, "Error: ");
    break;
  case DNX_LOG_LEVEL_WARNING:
    n = dnx_snprintf(buff + offset, DNX_MAX_LOG_BUFF - offset, "Warning: ");
    break;
  case DNX_LOG_LEVEL_INFO:
    n = dnx_snprintf(buff + offset, DNX_MAX_LOG_BUFF - offset, "Info: ");
    break;
  case DNX_LOG_LEVEL_EXTRA:
    n = dnx_snprintf(buff + offset, DNX_MAX_LOG_BUFF - offset, "Extra: ");
    break;
  default:
    DNX_ASSERT(0);
  } 
  if (n >= DNX_MAX_LOG_BUFF - offset)
    {
      goto Exit;
    }

  offset += n;

  n = dnx_snprintf(buff + offset, DNX_MAX_LOG_BUFF - offset, "[%s: (%d)]: ", func,
    line);
  if (n >= DNX_MAX_LOG_BUFF - offset)
  {
    goto Exit;
  }
  offset += n;

  if (os_ident)
  {
    n = dnx_snprintf(buff + offset, DNX_MAX_LOG_BUFF - offset, "%s: ",
      os_ident);
    /* if ident too long. skip it. */
    if (n < DNX_MAX_LOG_BUFF - offset)
    {
      offset +=n;
    }
  }

  va_start(va, fmt);
  n = dnx_vsnprintf(buff + offset, DNX_MAX_LOG_BUFF - offset, fmt, va);
  va_end(va);

  if (n >= DNX_MAX_LOG_BUFF - offset)
  {
    buff[DNX_MAX_LOG_BUFF - 1] = 0;
  }

Exit:
  OutputDebugStringA(buff);

  if (duplicate_to_stderr)
    fprintf(stderr, "%s\n", buff);
}
Пример #21
0
void dnx_rmlock_reset(dnx_rmlock_t *lock)
{
  DNX_ASSERT(NULL != lock);

  dnx_event_reset(&lock->event);
}
Пример #22
0
dnx_status_t dnx_rmlock_wait(dnx_rmlock_t *lock)
{
  DNX_ASSERT(NULL != lock);

  return dnx_event_wait(&lock->event, DNX_WAIT_FOREVER);
}
Пример #23
0
void dnx_event_reset(dnx_event_t *event)
{
  DNX_ASSERT(NULL != event);

  event->wait_flag = 0;
}