Exemplo n.º 1
0
void vcos_deinit(void)
{
   vcos_global_lock();

   vcos_assert(init_refcount > 0);

   if (init_refcount > 0 && --init_refcount == 0)
      vcos_platform_deinit();

   vcos_global_unlock();
}
Exemplo n.º 2
0
VCOS_STATUS_T vcos_init(void)
{
   VCOS_STATUS_T st = VCOS_SUCCESS;

   vcos_global_lock();

   if (init_refcount++ == 0)
      st = vcos_platform_init();

   vcos_global_unlock();

   return st;
}
VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *instance)
{
   VCHIQ_INSTANCE_T inst = NULL;
   int i;

   vcos_global_lock();

#ifdef VCHIQ_LOCAL
   if (vchiq_num_instances < 2)
   {
      vchiq_init_state(&vchiq_instances[vchiq_num_instances].state,
                       &vchiq_channels[vchiq_num_instances],
                       &vchiq_channels[vchiq_num_instances ^ 1]);
      if (vchiq_num_instances == 1)
      {
         /* This state initialisation may have erased a signal - signal anyway
            to be sure. This is a bit of a hack, caused by the desire for the
            server threads to be started on the same core as the calling thread. */
         vcos_event_signal(&vchiq_channels[vchiq_num_instances].trigger.event);
      }
      vchiq_num_instances++;
   }
#endif /* VCHIQ_LOCAL */

   for (i = 0; i < vchiq_num_instances; i++)
   {
      if (!vchiq_instances[i].state.initialised)
      {
         inst = &vchiq_instances[i];
         inst->connected = 0;
         inst->state.id = i;
         inst->state.initialised = 1;
         break;
      }
   }

   vcos_global_unlock();

   *instance = inst;

   return (inst != NULL) ? VCHIQ_SUCCESS : VCHIQ_ERROR;
}
Exemplo n.º 4
0
VCOS_STATUS_T vcos_once(VCOS_ONCE_T *once_control,
                        void (*init_routine)(void))
{
   /* In order to be thread-safe we need to re-test *once_control
    * inside the lock. The outer test is basically an optimization
    * so that once it is initialized we don't need to waste time
    * trying to acquire the lock.
    */

   if ( *once_control == 0 )
   {
       vcos_global_lock();
       if ( *once_control == 0 )
       {
           init_routine();
           *once_control = 1;
       }
       vcos_global_unlock();
   }

   return VCOS_SUCCESS;
}