VCOS_STATUS_T vcos_init(void)
{
   VCOS_STATUS_T st = VCOS_SUCCESS;

#ifdef HAVE_MTRACE
   // enable glibc memory debugging, if the environment
   // variable MALLOC_TRACE names a valid file.
   mtrace();
#endif

   vcos_mutex_create(&lock, "global_lock");

   vcos_demand(pthread_key_create(&_vcos_thread_current_key, NULL) == 0);

   /* Initialise a VCOS wrapper for the thread which called vcos_init. */
   vcos_semaphore_create(&vcos_thread_main.suspend, NULL, 0);
   vcos_thread_main.thread = pthread_self();
   pthread_setspecific(_vcos_thread_current_key, &vcos_thread_main);

   st = vcos_msgq_init();
   vcos_assert(st == VCOS_SUCCESS);

   vcos_logging_init();

   return st;
}
VCOS_STATUS_T vcos_init(void)
{
   if(!inited)
   {
      BOOL ok;
      VCOS_STATUS_T status;

      ok = QueryPerformanceFrequency(&ticks_per_second);
      vcos_assert(ok);
      if (!ok)
         return VCOS_ENOSYS;

      vcos_thread_data_tls = TlsAlloc();
      if (vcos_thread_data_tls == (DWORD)-1)
         return VCOS_ENOMEM;

      status = _vcos_thread_create_attach(&main_thread, "main");
      if (status != VCOS_SUCCESS) {
         TlsFree(vcos_thread_data_tls);
         return status;
      }

      vcos_msgq_init();

      InitializeCriticalSection(&lock);

      vcos_logging_init();

      inited = 1;
   }
   return VCOS_SUCCESS;
}
Пример #3
0
VCOS_STATUS_T vcos_platform_init(void)
{
   VCOS_STATUS_T st;
   uint32_t flags = 0;

   st = _vcos_named_semaphore_init();
   if (!vcos_verify(st == VCOS_SUCCESS))
      goto end;

   flags |= VCOS_INIT_NAMED_SEM;

   st = vcos_once(&current_thread_key_once, current_thread_key_init);
   if (!vcos_verify(st == VCOS_SUCCESS))
      goto end;

   /* Initialise a VCOS wrapper for the thread which called vcos_init. */
   st = vcos_semaphore_create(&vcos_thread_main.suspend, NULL, 0);
   if (!vcos_verify(st == VCOS_SUCCESS))
      goto end;

   flags |= VCOS_INIT_MAIN_SEM;

#ifdef WIN32_KERN 
   vcos_thread_main.thread = PsGetCurrentThreadId();

   // TODO Implement thread context for kernel mode
#else
   int pst;

   vcos_thread_main.thread = GetCurrentThread();

   // For windows zero return value is failure
   pst = TlsSetValue(_vcos_thread_current_key, &vcos_thread_main);
   if (!vcos_verify(pst != 0))
   {
       st = VCOS_EINVAL;
       goto end;
   }
#endif

   st = vcos_msgq_init();
   if (!vcos_verify(st == VCOS_SUCCESS))
      goto end;

   flags |= VCOS_INIT_MSGQ;

   vcos_logging_init();

end:
   if (st != VCOS_SUCCESS)
      vcos_term(flags);

   return st;
}
Пример #4
0
VCOS_STATUS_T vcos_platform_init(void)
{
   VCOS_STATUS_T st;
   uint32_t flags = 0;
   int pst;

   st = _vcos_named_semaphore_init();
   if (!vcos_verify(st == VCOS_SUCCESS))
      goto end;

   flags |= VCOS_INIT_NAMED_SEM;

#ifdef HAVE_MTRACE
   /* enable glibc memory debugging, if the environment
    * variable MALLOC_TRACE names a valid file.
    */
   mtrace();
#endif

#ifdef ANDROID
   st = vcos_mutex_create(&printf_lock, "printf");
   if (!vcos_verify(st == VCOS_SUCCESS))
      goto end;

   flags |= VCOS_INIT_PRINTF_LOCK;
#endif

   st = vcos_once(&current_thread_key_once, current_thread_key_init);
   if (!vcos_verify(st == VCOS_SUCCESS))
      goto end;

   /* Initialise a VCOS wrapper for the thread which called vcos_init. */
   st = vcos_semaphore_create(&vcos_thread_main.suspend, NULL, 0);
   if (!vcos_verify(st == VCOS_SUCCESS))
      goto end;

   flags |= VCOS_INIT_MAIN_SEM;

   vcos_thread_main.thread = pthread_self();

   pst = pthread_setspecific(_vcos_thread_current_key, &vcos_thread_main);
   if (!vcos_verify(pst == 0))
   {
      st = VCOS_EINVAL;
      goto end;
   }

   st = vcos_msgq_init();
   if (!vcos_verify(st == VCOS_SUCCESS))
      goto end;

   flags |= VCOS_INIT_MSGQ;

   vcos_logging_init();

end:
   if (st != VCOS_SUCCESS)
      vcos_term(flags);

   return st;
}