示例#1
0
static struct oh_handler *new_handler(GHashTable *handler_config)
{       /* Return a new oh_handler instance */
        struct oh_plugin *plugin = NULL;
        struct oh_handler *handler = NULL;
	char *plugin_name = NULL;
        static unsigned int handler_id = 1;
        unsigned int *hidp;

        if (!handler_config) {
                dbg("ERROR creating new handler. Invalid parameter.");
                return NULL;
        }

	plugin_name = (char *)g_hash_table_lookup(handler_config, "plugin");
	if (!plugin_name) {
		dbg("ERROR creating new handler. No plugin name received.");
		return NULL;
	}

        handler = (struct oh_handler *)g_malloc0(sizeof(struct oh_handler));
        hidp = (unsigned int *)g_malloc0(sizeof(unsigned int));

        plugin = oh_get_plugin(plugin_name);
        if(!plugin) { /* Attempt to load plugin here once */
		int rc = oh_load_plugin(plugin_name);
		if (rc) {
                	dbg("Could not create handler. Plugin %s not loaded",
                    	    plugin_name);
                	goto cleanexit;
		}

		plugin = oh_get_plugin(plugin_name);
		if (!plugin) {
			dbg("Tried but could not get a plugin to "
			    "create this handler.");
			goto cleanexit;
		}
        }

        /* Initialize handler */
        handler->abi = plugin->abi;
        plugin->handler_count++; /* Increment # of handlers using the plugin */
        oh_release_plugin(plugin);
        g_static_rec_mutex_lock(&oh_handlers.lock);
        handler->id = handler_id++;
        g_static_rec_mutex_unlock(&oh_handlers.lock);
        *hidp = handler->id;
        handler->plugin_name = (char *)g_hash_table_lookup(handler_config, "plugin");
        handler->config = handler_config;
        handler->refcount = 0;
        g_static_rec_mutex_init(&handler->lock);
        g_static_rec_mutex_init(&handler->refcount_lock);

        return handler;
cleanexit:
        g_free(hidp);
        g_free(handler);
        return NULL;
}
示例#2
0
void
gst_alsa_mixer_set_volume (GstAlsaMixer * mixer, GstMixerTrack * track,
    gint * volumes)
{
  GstAlsaMixerTrack *alsa_track = GST_ALSA_MIXER_TRACK (track);
  gint i;

  g_return_if_fail (mixer->handle != NULL);

  g_static_rec_mutex_lock (mixer->rec_mutex);

  gst_alsa_mixer_track_update (alsa_track);

  if (track->flags & GST_MIXER_TRACK_OUTPUT) {

    /* Is emulated mute flag activated? */
    if (track->flags & GST_MIXER_TRACK_MUTE &&
        !(alsa_track->alsa_flags & GST_ALSA_MIXER_TRACK_PSWITCH)) {
      for (i = 0; i < track->num_channels; i++)
        alsa_track->volumes[i] = volumes[i];
    } else {
      if (check_if_volumes_are_the_same (track->num_channels, volumes)) {
        snd_mixer_selem_set_playback_volume_all (alsa_track->element,
            volumes[0]);
        for (i = 0; i < track->num_channels; i++)
          alsa_track->volumes[i] = volumes[0];
      } else {
        for (i = 0; i < track->num_channels; i++) {
          alsa_track->volumes[i] = volumes[i];
          snd_mixer_selem_set_playback_volume (alsa_track->element, i,
              volumes[i]);
        }
      }
    }

  } else if (track->flags & GST_MIXER_TRACK_INPUT) {

    /* Is emulated record flag activated? */
    if (track->flags & GST_MIXER_TRACK_RECORD ||
        alsa_track->alsa_flags & GST_ALSA_MIXER_TRACK_CSWITCH) {
      if (check_if_volumes_are_the_same (track->num_channels, volumes)) {
        snd_mixer_selem_set_capture_volume_all (alsa_track->element,
            volumes[0]);
        for (i = 0; i < track->num_channels; i++)
          alsa_track->volumes[i] = volumes[0];
      } else {
        for (i = 0; i < track->num_channels; i++) {
          alsa_track->volumes[i] = volumes[i];
          snd_mixer_selem_set_capture_volume (alsa_track->element, i,
              volumes[i]);
        }
      }
    } else {
      for (i = 0; i < track->num_channels; i++)
        alsa_track->volumes[i] = volumes[i];
    }
  }
  g_static_rec_mutex_unlock (mixer->rec_mutex);
}
/**
 * Aquires the canvas lock used to synchronize threads.
 */
void CGenericCanvas::lock(void)
{
#ifdef _WINDOWS
  EnterCriticalSection(&FLock);
#else
  g_static_rec_mutex_lock(&FLock);
#endif
}
示例#4
0
static void __dec_domain_refcount(struct oh_domain *d)
{
        g_static_rec_mutex_lock(&d->refcount_lock);
        d->refcount--;
        g_static_rec_mutex_unlock(&d->refcount_lock);

        return;
}
示例#5
0
int 
lcm_subscription_set_queue_capacity(lcm_subscription_t* subs, int num_messages)
{
    g_static_rec_mutex_lock(&subs->lcm->mutex);
    subs->max_num_queued_messages = num_messages;
    g_static_rec_mutex_unlock(&subs->lcm->mutex);
    return 0;
}
示例#6
0
DictionaryWord *
dictionary_add_word (const char      *word,
                     Phoneme         *decomp)
{
    DictionaryWord *dword;
    char *query_word;

    g_return_val_if_fail (word != NULL, NULL);

    g_static_rec_mutex_lock (&dict_mutex);

    if (dictionary == NULL) {
        dictionary = g_hash_table_new (g_str_hash, g_str_equal);
    }

    query_word = g_ascii_strdown (word, -1);
    g_strstrip (query_word);
    dword = g_hash_table_lookup (dictionary, query_word);

    if (dword == NULL || (decomp != NULL && dword->decomp == NULL)) {

        gboolean add_word = FALSE;
        const char *w;

        if (dword == NULL) {

            if (dict_chunks == NULL) {
                dict_chunks = g_mem_chunk_create (DictionaryWord,
                                                  1000,
                                                  G_ALLOC_ONLY);
            }

            dword = g_chunk_new0 (DictionaryWord, dict_chunks);

            dword->word = query_word;

            /* pre-compute a hash key */
            dword->hash = 0xdeadbeef;
            for (w = word; *w; ++w)
                dword->hash = 17 * dword->hash + (long)*w;

            add_word = TRUE;
        } else {
            g_free (query_word);
        }
    
        dword->decomp = decomp;
        if (decomp)
            rhyme_index_word (dword);

        if (add_word)
            g_hash_table_insert (dictionary, dword->word, dword);
    }

    g_static_rec_mutex_unlock (&dict_mutex);

    return dword;
}
示例#7
0
/**
 * oh_create_domain
 * @capabilities:
 * @isPeer:
 * @tag:
 *
 *
 *
 * Returns: Domain id of newly created domain, or 0 if failed to create.
 **/
SaHpiDomainIdT oh_create_domain(SaHpiDomainCapabilitiesT capabilities,
                                SaHpiTimeoutT   aitimeout,
                                SaHpiTextBufferT *tag)
{
        struct oh_domain *domain = NULL;
        static SaHpiDomainIdT id = OH_FIRST_DOMAIN; /* domain ids will start at 1 */
        struct oh_global_param param = { .type = OPENHPI_DEL_SIZE_LIMIT };
        char del_filepath[SAHPI_MAX_TEXT_BUFFER_LENGTH*2];

        domain = g_new0(struct oh_domain,1);
        if (!domain) return 0;

        domain->capabilities = capabilities;
        domain->ai_timeout = aitimeout;
        domain->is_peer = SAHPI_FALSE;
        oh_init_rpt(&(domain->rpt));

        if (tag)
                memcpy(&(domain->tag), tag, sizeof(SaHpiTextBufferT));

        oh_get_global_param(&param);

        domain->del = oh_el_create(param.u.del_size_limit);
        domain->sessions = g_array_sized_new(FALSE, TRUE,
                                             sizeof(SaHpiSessionIdT),
                                             OH_SESSION_PREALLOC);

        g_static_rec_mutex_init(&(domain->lock));
        g_static_rec_mutex_init(&(domain->refcount_lock));

        if (!domain->del || !domain->sessions) {
                g_free(domain->del);
                g_array_free(domain->sessions, TRUE);
                g_static_rec_mutex_free(&(domain->lock));
                g_static_rec_mutex_free(&(domain->refcount_lock));
                g_free(domain);
                return 0;
        }

        param.type = OPENHPI_DEL_SAVE;
        oh_get_global_param(&param);

        g_static_rec_mutex_lock(&(oh_domains.lock)); /* Locked domain table */
        domain->id = id++;
        if (param.u.del_save) {
                param.type = OPENHPI_VARPATH;
                oh_get_global_param(&param);
                snprintf(del_filepath,
                         SAHPI_MAX_TEXT_BUFFER_LENGTH*2,
                         "%s/del.%u", param.u.varpath, domain->id);
                oh_el_map_from_file(domain->del, del_filepath);
        }
        g_hash_table_insert(oh_domains.table, &(domain->id), domain);
        g_static_rec_mutex_unlock(&(oh_domains.lock));  /* Unlocked domain table */

        return domain->id;
}
示例#8
0
const struct oh_domain_conf * oh_get_domain_conf(SaHpiDomainIdT did)
{
    struct oh_domain_conf *dc;
    g_static_rec_mutex_lock(&ohc_lock);
    dc = (struct oh_domain_conf *)g_hash_table_lookup(ohc_domains, &did);
    g_static_rec_mutex_unlock(&ohc_lock);

    return dc;
}
示例#9
0
/**
 * oh_getnext_plugin_name
 * @plugin_name: IN. If NULL is passed, the first plugin in the list is returned.
 * @next_plugin_name: OUT. Buffer to print the next plugin name to.
 * @size: IN. Size of the buffer at @next_plugin_name.
 *
 * Returns: 0 on Success.
 **/
int oh_getnext_plugin_name(char *plugin_name,
                           char *next_plugin_name,
                           unsigned int size)
{
        GSList *node = NULL;

        if (!next_plugin_name) {
                err("ERROR. Invalid parameter.");
                return -1;
        }
        memset(next_plugin_name, '\0', size);

        if (!plugin_name) {
                g_static_rec_mutex_lock(&oh_plugins.lock);
                if (oh_plugins.list) {
                        struct oh_plugin *plugin = oh_plugins.list->data;
                        strncpy(next_plugin_name, plugin->name, size);
                        g_static_rec_mutex_unlock(&oh_plugins.lock);
                        return 0;
                } else {
                        g_static_rec_mutex_unlock(&oh_plugins.lock);
                        dbg("No plugins have been loaded yet.");
                        return -1;
                }
        } else {
                g_static_rec_mutex_lock(&oh_plugins.lock);
                for (node = oh_plugins.list; node; node = node->next) {
                        struct oh_plugin *p = node->data;
                        if (strcmp(p->name, plugin_name) == 0) {
                                if (node->next) {
                                        p = node->next->data;
                                        strncpy(next_plugin_name, p->name, size);
                                        g_static_rec_mutex_unlock(&oh_plugins.lock);
                                        return 0;
                                } else {
                                        break;
                                }
                        }
                }
                g_static_rec_mutex_unlock(&oh_plugins.lock);
        }

        return -1;
}
示例#10
0
/**
 * oh_get_handler
 * @hid: id of handler being requested
 *
 * Returns: NULL if handler was not found.
 **/
struct oh_handler *oh_get_handler(unsigned int hid)
{
        GSList *node = NULL;
        struct oh_handler *handler = NULL;

        g_static_rec_mutex_lock(&oh_handlers.lock);
        node = g_hash_table_lookup(oh_handlers.table, &hid);
        handler = node ? node->data : NULL;
        if (!handler) {
                g_static_rec_mutex_unlock(&oh_handlers.lock);
                err("Error - Handler %d was not found", hid);
                return NULL;
        }
        __inc_handler_refcount(handler);
        g_static_rec_mutex_unlock(&oh_handlers.lock);
        g_static_rec_mutex_lock(&handler->lock);

        return handler;
}
示例#11
0
static gpointer
test_g_static_rec_mutex_thread (gpointer data)
{
  g_assert (GPOINTER_TO_INT (data) == 42);
  g_assert (g_static_rec_mutex_trylock (&test_g_static_rec_mutex_mutex) 
	    == FALSE);
  test_g_static_rec_mutex_thread_ready = TRUE;
  g_static_rec_mutex_lock (&test_g_static_rec_mutex_mutex);
  g_static_rec_mutex_lock (&test_g_static_rec_mutex_mutex);
  g_assert (test_g_static_rec_mutex_int == 42);
  test_g_static_rec_mutex_thread_ready = FALSE;
  g_static_rec_mutex_unlock (&test_g_static_rec_mutex_mutex);
  g_static_rec_mutex_unlock (&test_g_static_rec_mutex_mutex);

  g_thread_exit (GINT_TO_POINTER (43));
  
  g_assert_not_reached ();
  return NULL;
}
示例#12
0
gboolean
g_module_close (GModule	       *module)
{
  SUPPORT_OR_RETURN (FALSE);
  
  g_return_val_if_fail (module != NULL, FALSE);
  g_return_val_if_fail (module->ref_count > 0, FALSE);
  
  g_static_rec_mutex_lock (&g_module_global_lock);

  module->ref_count--;
  
  if (!module->ref_count && !module->is_resident && module->unload)
    {
      GModuleUnload unload;

      unload = module->unload;
      module->unload = NULL;
      unload (module);
    }

  if (!module->ref_count && !module->is_resident)
    {
      GModule *last;
      GModule *node;
      
      last = NULL;
      
      node = modules;
      while (node)
	{
	  if (node == module)
	    {
	      if (last)
		last->next = node->next;
	      else
		modules = node->next;
	      break;
	    }
	  last = node;
	  node = last->next;
	}
      module->next = NULL;
      
      _g_module_close (module->handle, FALSE);
      g_free (module->file_name);
#ifdef G_OS_WIN32
      g_free (module->cp_file_name);
#endif
      g_free (module);
    }
  
  g_static_rec_mutex_unlock (&g_module_global_lock);
  return g_module_error() == NULL;
}
示例#13
0
void
gst_alsa_mixer_set_record (GstAlsaMixer * mixer,
    GstMixerTrack * track, gboolean record)
{
  GstAlsaMixerTrack *alsa_track = GST_ALSA_MIXER_TRACK (track);

  g_return_if_fail (mixer->handle != NULL);

  g_static_rec_mutex_lock (mixer->rec_mutex);

  gst_alsa_mixer_track_update (alsa_track);

  if (!!(record) == !!(track->flags & GST_MIXER_TRACK_RECORD)) {
    g_static_rec_mutex_unlock (mixer->rec_mutex);
    return;
  }

  if (record) {
    track->flags |= GST_MIXER_TRACK_RECORD;
  } else {
    track->flags &= ~GST_MIXER_TRACK_RECORD;
  }

  if (alsa_track->alsa_flags & GST_ALSA_MIXER_TRACK_CSWITCH) {
    snd_mixer_selem_set_capture_switch_all (alsa_track->element,
        record ? 1 : 0);

    /* update all tracks in same exlusive cswitch group */
    if (alsa_track->alsa_flags & GST_ALSA_MIXER_TRACK_CSWITCH_EXCL) {
      GList *item;

      for (item = mixer->tracklist; item != NULL; item = item->next) {

        if (GST_IS_ALSA_MIXER_TRACK (item->data)) {
          GstAlsaMixerTrack *item_alsa_track =
              GST_ALSA_MIXER_TRACK (item->data);

          if (item_alsa_track->alsa_flags & GST_ALSA_MIXER_TRACK_CSWITCH_EXCL &&
              item_alsa_track->capture_group == alsa_track->capture_group) {
            gst_alsa_mixer_track_update (item_alsa_track);
          }
        }
      }
    }
  } else {
    gint i;

    for (i = 0; i < track->num_channels; i++) {
      long vol = record ? alsa_track->volumes[i] : track->min_volume;

      snd_mixer_selem_set_capture_volume (alsa_track->element, i, vol);
    }
  }
  g_static_rec_mutex_unlock (mixer->rec_mutex);
}
示例#14
0
SaErrorT oh_destroy_domain_sessions(SaHpiDomainIdT did)
{
        if (did == SAHPI_UNSPECIFIED_DOMAIN_ID)
                did = OH_DEFAULT_DOMAIN_ID;

        g_static_rec_mutex_lock(&oh_sessions.lock);
        g_hash_table_foreach(oh_sessions.table, __delete_by_did, &did);
        g_static_rec_mutex_unlock(&oh_sessions.lock);

        return SA_OK;
}
示例#15
0
void entity_rpt_set_updated(struct ohoi_resource_info *res_info,
		struct ohoi_handler *ipmi_handler)
{
	g_static_rec_mutex_lock(&ipmi_handler->ohoih_lock);
	if (!res_info->presence) {
		g_static_rec_mutex_unlock(&ipmi_handler->ohoih_lock);
		return;
	}	
	res_info->updated = 1;
	g_static_rec_mutex_unlock(&ipmi_handler->ohoih_lock);
}
示例#16
0
SaErrorT oh_destroy_domain_sessions(SaHpiDomainIdT did)
{
        if (did < 1)
                return SA_ERR_HPI_INVALID_PARAMS;

        g_static_rec_mutex_lock(&oh_sessions.lock);
        g_hash_table_foreach(oh_sessions.table, __delete_by_did, &did);
        g_static_rec_mutex_unlock(&oh_sessions.lock);

        return SA_OK;
}
示例#17
0
int
lcm_has_handlers (lcm_t * lcm, const char * channel)
{
    int has_handlers = 1;
    g_static_rec_mutex_lock (&lcm->mutex);
    GPtrArray * handlers = lcm_get_handlers (lcm, channel);
    if (!handlers || !handlers->len)
        has_handlers = 0;
    g_static_rec_mutex_unlock (&lcm->mutex);
    return has_handlers;
}
示例#18
0
static void
task_monitor_alsa (gpointer data)
{
  struct pollfd *pfds;
  unsigned int nfds, rnfds;
  unsigned short revents;
  GstAlsaMixer *mixer = (GstAlsaMixer *) data;

  g_static_rec_mutex_lock (mixer->rec_mutex);

  nfds = snd_mixer_poll_descriptors_count (mixer->handle);
  if (nfds <= 0) {
    GST_ERROR ("snd_mixer_poll_descriptors_count <= 0: %d", nfds);
    /* FIXME: sleep ? stop monitoring ? */
    return;
  }

  pfds = g_newa (struct pollfd, nfds + 1);
  rnfds = snd_mixer_poll_descriptors (mixer->handle, pfds, nfds);
  g_assert (rnfds <= nfds);

  pfds[rnfds].fd = mixer->pfd[0];
  pfds[rnfds].events = POLLIN | POLLPRI | POLLHUP | POLLERR;
  pfds[rnfds].revents = 0;

  g_static_rec_mutex_unlock (mixer->rec_mutex);

  GST_LOG ("task loop");
  poll (pfds, rnfds + 1, -1);

  g_static_rec_mutex_lock (mixer->rec_mutex);

  snd_mixer_poll_descriptors_revents (mixer->handle, pfds, nfds, &revents);
  if (revents & POLLIN || revents & POLLPRI) {
    GST_DEBUG ("Handling events");
    snd_mixer_handle_events (mixer->handle);
  }

  g_static_rec_mutex_unlock (mixer->rec_mutex);
}
示例#19
0
/**
 * oh_destroy_session
 * @sid:
 *
 *
 *
 * Returns:
 **/
SaErrorT oh_destroy_session(SaHpiSessionIdT sid)
{
        struct oh_session *session = NULL;
        struct oh_domain *domain = NULL;
        SaHpiDomainIdT did;
        gpointer event = NULL;
        int i, len;

        if (sid < 1) return SA_ERR_HPI_INVALID_PARAMS;

        g_static_rec_mutex_lock(&oh_sessions.lock); /* Locked session table */
        session = g_hash_table_lookup(oh_sessions.table, &sid);
        if (!session) {
                g_static_rec_mutex_unlock(&oh_sessions.lock);
                return SA_ERR_HPI_INVALID_SESSION;
        }

        g_hash_table_remove(oh_sessions.table, &(session->id));
        g_static_rec_mutex_unlock(&oh_sessions.lock); /* Unlocked session table */
        did = session->did;

        /* Finalize session */
        len = g_async_queue_length(session->eventq);
        if (len < 0) {
                for (i = 0; i > len; i--) {
                        g_async_queue_push(session->eventq, oh_generate_hpi_event());
                }
        } else if (len > 0) {
                for (i = 0; i < len; i++) {
                        event = g_async_queue_try_pop(session->eventq);
                        if (event) g_free(event);
                        event = NULL;
                }
        }
        g_async_queue_unref(session->eventq);
        g_free(session);

        /* Update domain about session deletion. */
        domain = oh_get_domain(did);
        if (domain) {
                len = domain->sessions->len;
                for (i = 0; i < len; i++) {
                        if (g_array_index(domain->sessions,SaHpiSessionIdT,i) == sid) {
                                g_array_remove_index(domain->sessions,i);
                                break;
                        }
                }
                oh_release_domain(domain);
        }

        return SA_OK;
}
示例#20
0
lcm_subscription_t
*lcm_subscribe (lcm_t *lcm, const char *channel, 
                     lcm_msg_handler_t handler, void *userdata)
{
    dbg (DBG_LCM, "registering %s handler %p\n", channel, handler);

    if (lcm->provider && lcm->vtable->subscribe) {
        if (0 != lcm->vtable->subscribe (lcm->provider, channel)) {
            return NULL;
        }
    }

    // create and populate a new message handler struct
    lcm_subscription_t *h = (lcm_subscription_t*)calloc (1, sizeof (lcm_subscription_t));
    h->channel = strdup(channel);
    h->handler = handler;
    h->userdata = userdata;
    h->callback_scheduled = 0;
    h->marked_for_deletion = 0;
    h->max_num_queued_messages = lcm->default_max_num_queued_messages;
    h->num_queued_messages = 0;
    h->lcm = lcm;

    char *regexbuf = g_strdup_printf("^%s$", channel);
#ifdef USE_GREGEX
    GError *rerr = NULL;
    h->regex = g_regex_new(regexbuf, (GRegexCompileFlags) 0, (GRegexMatchFlags) 0, &rerr);
    g_free(regexbuf);
    if(rerr) {
        fprintf(stderr, "%s: %s\n", __FUNCTION__, rerr->message);
        dbg(DBG_LCM, "%s: %s\n", __FUNCTION__, rerr->message);
        g_error_free(rerr);
        free(h);
        return NULL;
    }
#else
    int rstatus = regcomp (&h->preg, regexbuf, REG_NOSUB | REG_EXTENDED);
    g_free(regexbuf);
    if (rstatus != 0) {
        dbg (DBG_LCM, "bad regex in channel name!\n");
        free (h);
        return NULL;
    }
#endif

    g_static_rec_mutex_lock (&lcm->mutex);
    g_ptr_array_add(lcm->handlers_all, h);
    g_hash_table_foreach(lcm->handlers_map, map_add_handler_callback, h);
    g_static_rec_mutex_unlock (&lcm->mutex);

    return h;
}
示例#21
0
static void
gst_identity_notify_last_message (GstIdentity * identity)
{
  /* FIXME: this hacks around a bug in GLib/GObject: doing concurrent
   * g_object_notify() on the same object might lead to crashes, see
   * http://bugzilla.gnome.org/show_bug.cgi?id=166020#c60 and follow-ups.
   * So we really don't want to do a g_object_notify() here for out-of-band
   * events with the streaming thread possibly also doing a g_object_notify()
   * for an in-band buffer or event. */
  g_static_rec_mutex_lock (&identity->notify_lock);
  g_object_notify ((GObject *) identity, "last_message");
  g_static_rec_mutex_unlock (&identity->notify_lock);
}
示例#22
0
SaErrorT oh_close_session(SaHpiSessionIdT SessionId)
{        
        if (SessionId == 0)
		return SA_ERR_HPI_INVALID_PARAMS;

        g_static_rec_mutex_lock(&sessions_sem);
        // Since we used g_hash_table_new_full to create the tables,
        // this will remove the connection hash table and all of its entries also.
        g_hash_table_remove(sessions, &SessionId);
        
        g_static_rec_mutex_unlock(&sessions_sem);
        return SA_OK;
}
示例#23
0
void
gst_alsa_mixer_set_mute (GstAlsaMixer * mixer, GstMixerTrack * track,
    gboolean mute)
{
  GstAlsaMixerTrack *alsa_track = GST_ALSA_MIXER_TRACK (track);

  g_return_if_fail (mixer->handle != NULL);

  g_static_rec_mutex_lock (mixer->rec_mutex);

  gst_alsa_mixer_track_update (alsa_track);

  if (!!(mute) == !!(track->flags & GST_MIXER_TRACK_MUTE)) {
    g_static_rec_mutex_unlock (mixer->rec_mutex);
    return;
  }
  if (mute) {
    track->flags |= GST_MIXER_TRACK_MUTE;

    if (alsa_track->shared_mute)
      ((GstMixerTrack *) (alsa_track->shared_mute))->flags |=
          GST_MIXER_TRACK_MUTE;
  } else {
    track->flags &= ~GST_MIXER_TRACK_MUTE;

    if (alsa_track->shared_mute)
      ((GstMixerTrack *) (alsa_track->shared_mute))->flags &=
          ~GST_MIXER_TRACK_MUTE;
  }

  if (alsa_track->alsa_flags & GST_ALSA_MIXER_TRACK_PSWITCH) {
    snd_mixer_selem_set_playback_switch_all (alsa_track->element, mute ? 0 : 1);
  } else {
    gint i;
    GstAlsaMixerTrack *ctrl_track;

    if ((track->flags & GST_MIXER_TRACK_INPUT)
        && alsa_track->shared_mute != NULL)
      ctrl_track = alsa_track->shared_mute;
    else
      ctrl_track = alsa_track;

    for (i = 0; i < ((GstMixerTrack *) ctrl_track)->num_channels; i++) {
      long vol =
          mute ? ((GstMixerTrack *) ctrl_track)->
          min_volume : ctrl_track->volumes[i];
      snd_mixer_selem_set_playback_volume (ctrl_track->element, i, vol);
    }
  }
  g_static_rec_mutex_unlock (mixer->rec_mutex);
}
示例#24
0
void entity_rpt_set_presence(struct ohoi_resource_info *res_info,
		struct ohoi_handler *ipmi_handler, int present)
{
	g_static_rec_mutex_lock(&ipmi_handler->ohoih_lock);	
	dbg("res_info %p: old presence %d, new presence %d",
		res_info, res_info->presence, present);
	if (present == res_info->presence) {
		g_static_rec_mutex_unlock(&ipmi_handler->ohoih_lock);	
		return;
	}
	res_info->presence =  present;
	res_info->updated = 1;
	g_static_rec_mutex_unlock(&ipmi_handler->ohoih_lock);
}
示例#25
0
/**
 * oh_getnext_handler_id
 * @hid: If 0, will return the first handler id in the list.
 * Otherwise, indicates handler id previous to the one being requested.
 * @next_hid: Place where the next handler id after @hid
 * will be put.
 *
 * Returns: 0 on Success.
 **/
int oh_getnext_handler_id(unsigned int hid, unsigned int *next_hid)
{
        GSList *node = NULL;
        struct oh_handler *h = NULL;

        if (!next_hid) {
                err("ERROR. Invalid parameter.");
                return -1;
        }
        *next_hid = 0;

        if (!hid) { /* Return first handler id in the list */
                g_static_rec_mutex_lock(&oh_handlers.lock);
                if (oh_handlers.list) {
                        h = oh_handlers.list->data;
                        *next_hid = h->id;
                        g_static_rec_mutex_unlock(&oh_handlers.lock);
                        return 0;
                } else {
                        g_static_rec_mutex_unlock(&oh_handlers.lock);
                        err("Warning - no handlers");
                        return -1;
                }
        } else { /* Return handler id coming after hid in the list */
                g_static_rec_mutex_lock(&oh_handlers.lock);
                node = g_hash_table_lookup(oh_handlers.table, &hid);
                if (node && node->next && node->next->data) {
                        h = node->next->data;
                        *next_hid = h->id;
                        g_static_rec_mutex_unlock(&oh_handlers.lock);
                        return 0;
                }
        }
        g_static_rec_mutex_unlock(&oh_handlers.lock);

        return -1;
}
示例#26
0
void
ohoi_mc_event(enum ipmi_update_e op,
              ipmi_domain_t      *domain,
              ipmi_mc_t          *mc,
              void               *cb_data)
{

        struct oh_handler_state *handler = cb_data;
		struct ohoi_handler *ipmi_handler = handler->data;
		int rv;
		
	if ((ipmi_mc_get_channel(mc) == 0) && 
                 (ipmi_mc_get_address(mc) == 32) &&
		 ipmi_handler->d_type == IPMI_DOMAIN_TYPE_ATCA) {
		 	ipmi_handler->virt_mcid = ipmi_mc_convert_to_id(mc);
	}

	g_static_rec_mutex_lock(&ipmi_handler->ohoih_lock);			
        switch (op) {
                case IPMI_ADDED:
			/* if we get an MC but inactive, register a call to add
			it once it goes active */
			rv = ipmi_mc_add_active_handler(mc, mc_active, handler);
			rv = ipmi_mc_set_sdrs_first_read_handler(mc,
				mc_processed, handler);
			if(!ipmi_mc_is_active(mc)) {
				trace_ipmi_mc("ADDED but inactive...we ignore", mc);
				break;
			} else {
				mc_add(mc, handler);
				break;
			}
		case IPMI_DELETED:
			trace_ipmi_mc("DELETED, but nothing done", mc);
			break;

		case IPMI_CHANGED:
			if(!ipmi_mc_is_active(mc)) {
				trace_ipmi("CHANGED and is inactive: (%d %x)\n",
						ipmi_mc_get_address(mc), 
						ipmi_mc_get_channel(mc));
			} else {
				mc_add(mc, handler);
			}
			break;
		}
	g_static_rec_mutex_unlock(&ipmi_handler->ohoih_lock);

}
示例#27
0
int
lcm_dispatch_handlers (lcm_t * lcm, lcm_recv_buf_t * buf, const char *channel)
{
    g_static_rec_mutex_lock (&lcm->mutex);

    GPtrArray * handlers = lcm_get_handlers (lcm, channel);

    // ref the handlers to prevent them from being destroyed by an
    // lcm_unsubscribe.  This guarantees that handlers 0-(nhandlers-1) will not
    // be destroyed during the callbacks.  Store nhandlers in a local variable
    // so that we don't iterate over handlers that are added during the
    // callbacks.
    int nhandlers = handlers->len;
    for (int i = 0; i < nhandlers; i++) {
        lcm_subscription_t *h = (lcm_subscription_t *) g_ptr_array_index(handlers, i);
        h->callback_scheduled = 1;
    }

    // now, call the handlers.
    for (int i = 0; i < nhandlers; i++) {
        lcm_subscription_t *h = (lcm_subscription_t *) g_ptr_array_index(handlers, i);
        if (!h->marked_for_deletion && h->num_queued_messages > 0) {
            h->num_queued_messages--;
            int depth = g_static_rec_mutex_unlock_full (&lcm->mutex);
            h->handler (buf, channel, h->userdata);
            g_static_rec_mutex_lock_full (&lcm->mutex, depth);
        }
    }

    // unref the handlers and check if any should be deleted
    GList *to_remove = NULL;
    for (int i = 0; i < nhandlers; i++) {
        lcm_subscription_t *h = (lcm_subscription_t *) g_ptr_array_index(handlers, i);
        h->callback_scheduled = 0;
        if (h->marked_for_deletion)
            to_remove = g_list_prepend (to_remove, h);
    }
    // actually delete handlers marked for deletion
    for (;to_remove; to_remove = g_list_delete_link (to_remove, to_remove)) {
        lcm_subscription_t *h = (lcm_subscription_t *) to_remove->data;
        g_ptr_array_remove (lcm->handlers_all, h);
        g_hash_table_foreach (lcm->handlers_map, 
                map_remove_handler_callback, h);
        lcm_handler_free (h);
    }
    g_static_rec_mutex_unlock (&lcm->mutex);

    return 0;
}
示例#28
0
/**
 * oh_list_domains
 *
 *
 *
 * Returns:
 **/
GArray *oh_list_domains()
{
        trace("Entering list_domains");
        GArray *domain_ids = NULL;

        domain_ids = g_array_new(FALSE, TRUE, sizeof(SaHpiDomainIdT));
        if (!domain_ids) return NULL;
        trace("setup domain ids");
        g_static_rec_mutex_lock(&(oh_domains.lock));
        g_hash_table_foreach(oh_domains.table, collect_domain_ids, domain_ids);
        trace("Looping through table");
        g_static_rec_mutex_unlock(&(oh_domains.lock));

        return domain_ids;
}
示例#29
0
static void *
thread1 (void *t)
{
  gint i = 0;

  while (TRUE) {
    g_static_rec_mutex_lock (&mutex);
    if (i++ % 100000 == 0)
      g_print ("*");
    g_static_rec_mutex_unlock (&mutex);
    if (i++ % 100000 == 0)
      g_print ("*");
  }
  return NULL;
}
示例#30
0
int
lcm_handle (lcm_t * lcm)
{
    if (lcm->provider && lcm->vtable->handle) {
        int ret;
        g_static_rec_mutex_lock (&lcm->handle_mutex);
        assert(!lcm->in_handle); // recursive calls to lcm_handle are not allowed
        lcm->in_handle = 1;
        ret = lcm->vtable->handle (lcm->provider);
        lcm->in_handle = 0;
        g_static_rec_mutex_unlock (&lcm->handle_mutex);
        return ret;
    } else
        return -1;
}