ext/iodine/fio.c
/** Unsubscribes from a filter, pub/sub channle or patten */
Unsubscribes from a filter, pub/sub channle or patten
Unsubscribes from a filter pub / sub channle or patten
void fio_unsubscribe(subscription_s *s) {
  if (!s)
    return;
  if (fio_trylock(&s->unsubscribed))
    goto finish;
  fio_lock(&s->lock);
  channel_s *ch = s->parent;
  uint8_t removed = 0;
  fio_lock(&ch->lock);
  fio_ls_embd_remove(&s->node);
  if (fio_ls_embd_is_empty(&ch->subscriptions)) {
    fio_collection_s *c = ch->parent;
    uint64_t hashed = FIO_HASH_FN(
        ch->name, ch->name_len, &fio_postoffice.pubsub, &fio_postoffice.pubsub);
    fio_lock(&c->lock);
    if (fio_ls_embd_is_empty(&ch->subscriptions)) {
      fio_ch_set_remove(&c->channels, hashed, ch, NULL);
      removed = (c != &fio_postoffice.filters);
    }
    fio_unlock(&c->lock);
  }
  fio_unlock(&ch->lock);
  if (removed) {
    fio_pubsub_on_channel_destroy(ch);
  }
  s->on_message = NULL;
  fio_unlock(&s->lock);
finish:
  fio_subscription_free(s);
}
void fio_unsubscribe ( subscription_s * s ) { if ( ! s ) return ; if ( fio_trylock ( & s -> unsubscribed ) ) goto finish ; fio_lock ( & s -> lock ) ; channel_s * ch = s -> parent ; uint8_t removed = 0 ; fio_lock ( & ch -> lock ) ; fio_ls_embd_remove ( & s -> node ) ; if ( fio_ls_embd_is_empty ( & ch -> subscriptions ) ) { fio_collection_s * c = ch -> parent ; uint64_t hashed = FIO_HASH_FN ( ch -> name , ch -> name_len , & fio_postoffice . pubsub , & fio_postoffice . pubsub ) ; fio_lock ( & c -> lock ) ; if ( fio_ls_embd_is_empty ( & ch -> subscriptions ) ) { fio_ch_set_remove ( & c -> channels , hashed , ch , NULL ) ; removed = ( c != & fio_postoffice . filters ) ; } fio_unlock ( & c -> lock ) ; } fio_unlock ( & ch -> lock ) ; if ( removed ) { fio_pubsub_on_channel_destroy ( ch ) ; } s -> on_message = NULL ; fio_unlock ( & s -> lock ) ; finish : fio_subscription_free ( s ) ; }
Unsubscribes from a filter, pub/sub channle or patten
Unsubscribes from a filter pub / sub channle or patten
/* check if channel is done for */ /* lock collection */ /* test again within lock */ /* promise the subscription will be inactive */