static ngx_int_t sub_enqueue(ngx_int_t timeout, void *ptr, sub_data_t *d) { DBG("%p enqueued (%p %V %i) %V", d->multi->sub, d->multi_chanhead, &d->multi_chanhead->id, d->n, &d->multi->id); assert(d->multi_chanhead->multi_waiting > 0); d->multi_chanhead->multi_waiting --; if(d->multi_chanhead->multi_waiting == 0) { memstore_ready_chanhead_unless_stub(d->multi_chanhead); } return NGX_OK; }
static void receive_subscribe_reply(ngx_int_t sender, subscribe_data_t *d) { memstore_channel_head_t *head; store_channel_head_shm_t *old_shared; DBG("received subscribe reply for channel %V", d->shm_chid); //we have the chanhead address, but are too afraid to use it. if(!d->shared_channel_data && !d->d.subscriber) { ERR("failed to subscribe"); return; } if((head = nchan_memstore_get_chanhead_no_ipc_sub(d->shm_chid, d->cf)) == NULL) { ERR("Error regarding an aspect of life or maybe freshly fallen cookie crumbles"); return; } old_shared = head->shared; if(old_shared) { assert(old_shared == d->shared_channel_data); } DBG("receive subscribe proceed to do ipc_sub stuff"); head->shared = d->shared_channel_data; if(old_shared == NULL) { //ERR("%V local total_sub_count %i, internal_sub_count %i", &head->id, head->sub_count, head->internal_sub_count); assert(head->total_sub_count >= head->internal_sub_count); ngx_atomic_fetch_add(&head->shared->sub_count, head->total_sub_count - head->internal_sub_count); ngx_atomic_fetch_add(&head->shared->internal_sub_count, head->internal_sub_count); } else { ERR("%V sub count already shared, don't update", &head->id); } assert(head->shared != NULL); if(head->foreign_owner_ipc_sub) { assert(head->foreign_owner_ipc_sub == d->d.subscriber); } else { head->foreign_owner_ipc_sub = d->d.subscriber; } memstore_ready_chanhead_unless_stub(head); str_shm_free(d->shm_chid); }