instance operations must also ensure thread is considered awake or GC may free tkmap instances prematurely
Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
		
							parent
							
								
									84506b8518
								
							
						
					
					
						commit
						0f7ce1ac43
					
				
					 1 changed files with 66 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -76,17 +76,8 @@ dds_instance_remove(
 | 
			
		|||
        assert (data);
 | 
			
		||||
        inst = dds_instance_find (topic, data, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (inst) {
 | 
			
		||||
        struct thread_state1 * const thr = lookup_thread_state();
 | 
			
		||||
        const bool asleep = thr ? !vtime_awake_p(thr->vtime) : false;
 | 
			
		||||
        if (asleep) {
 | 
			
		||||
            thread_state_awake(thr);
 | 
			
		||||
        }
 | 
			
		||||
        ddsi_tkmap_instance_unref (inst);
 | 
			
		||||
        if (asleep) {
 | 
			
		||||
            thread_state_asleep(thr);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -133,6 +124,8 @@ dds_register_instance(
 | 
			
		|||
        _Out_ dds_instance_handle_t *handle,
 | 
			
		||||
        _In_ const void *data)
 | 
			
		||||
{
 | 
			
		||||
    struct thread_state1 * const thr = lookup_thread_state();
 | 
			
		||||
    const bool asleep = !vtime_awake_p(thr->vtime);
 | 
			
		||||
    struct ddsi_tkmap_instance * inst;
 | 
			
		||||
    dds_entity *wr;
 | 
			
		||||
    dds_return_t ret;
 | 
			
		||||
| 
						 | 
				
			
			@ -154,14 +147,20 @@ dds_register_instance(
 | 
			
		|||
        ret = DDS_ERRNO(rc);
 | 
			
		||||
        goto err;
 | 
			
		||||
    }
 | 
			
		||||
    if (asleep) {
 | 
			
		||||
        thread_state_awake(thr);
 | 
			
		||||
    }
 | 
			
		||||
    inst = dds_instance_find (((dds_writer*) wr)->m_topic, data, true);
 | 
			
		||||
    if(inst != NULL){
 | 
			
		||||
        *handle = inst->m_iid;
 | 
			
		||||
        ret = DDS_RETCODE_OK;
 | 
			
		||||
    } else{
 | 
			
		||||
    } else {
 | 
			
		||||
        DDS_ERROR("Unable to create instance\n");
 | 
			
		||||
        ret = DDS_ERRNO(DDS_RETCODE_ERROR);
 | 
			
		||||
    }
 | 
			
		||||
    if (asleep) {
 | 
			
		||||
        thread_state_asleep(thr);
 | 
			
		||||
    }
 | 
			
		||||
    dds_entity_unlock(wr);
 | 
			
		||||
err:
 | 
			
		||||
    return ret;
 | 
			
		||||
| 
						 | 
				
			
			@ -192,6 +191,8 @@ dds_unregister_instance_ts(
 | 
			
		|||
       _In_opt_ const void *data,
 | 
			
		||||
       _In_ dds_time_t timestamp)
 | 
			
		||||
{
 | 
			
		||||
    struct thread_state1 * const thr = lookup_thread_state();
 | 
			
		||||
    const bool asleep = !vtime_awake_p(thr->vtime);
 | 
			
		||||
    dds_return_t ret = DDS_RETCODE_OK;
 | 
			
		||||
    dds__retcode_t rc;
 | 
			
		||||
    bool autodispose = true;
 | 
			
		||||
| 
						 | 
				
			
			@ -219,11 +220,17 @@ dds_unregister_instance_ts(
 | 
			
		|||
    if (wr->m_qos) {
 | 
			
		||||
        dds_qget_writer_data_lifecycle (wr->m_qos, &autodispose);
 | 
			
		||||
    }
 | 
			
		||||
    if (asleep) {
 | 
			
		||||
        thread_state_awake(thr);
 | 
			
		||||
    }
 | 
			
		||||
    if (autodispose) {
 | 
			
		||||
        dds_instance_remove (((dds_writer*) wr)->m_topic, data, DDS_HANDLE_NIL);
 | 
			
		||||
        action |= DDS_WR_DISPOSE_BIT;
 | 
			
		||||
    }
 | 
			
		||||
    ret = dds_write_impl ((dds_writer*)wr, sample, timestamp, action);
 | 
			
		||||
    if (asleep) {
 | 
			
		||||
        thread_state_asleep(thr);
 | 
			
		||||
    }
 | 
			
		||||
    dds_entity_unlock(wr);
 | 
			
		||||
err:
 | 
			
		||||
    return ret;
 | 
			
		||||
| 
						 | 
				
			
			@ -236,6 +243,8 @@ dds_unregister_instance_ih_ts(
 | 
			
		|||
       _In_opt_ dds_instance_handle_t handle,
 | 
			
		||||
       _In_ dds_time_t timestamp)
 | 
			
		||||
{
 | 
			
		||||
    struct thread_state1 * const thr = lookup_thread_state();
 | 
			
		||||
    const bool asleep = !vtime_awake_p(thr->vtime);
 | 
			
		||||
    dds_return_t ret = DDS_RETCODE_OK;
 | 
			
		||||
    dds__retcode_t rc;
 | 
			
		||||
    bool autodispose = true;
 | 
			
		||||
| 
						 | 
				
			
			@ -261,6 +270,9 @@ dds_unregister_instance_ih_ts(
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    map = gv.m_tkmap;
 | 
			
		||||
    if (asleep) {
 | 
			
		||||
        thread_state_awake(thr);
 | 
			
		||||
    }
 | 
			
		||||
    topic = dds_instance_info((dds_entity*)wr);
 | 
			
		||||
    sample = ddsi_sertopic_alloc_sample (topic->m_stopic);
 | 
			
		||||
    if (ddsi_tkmap_get_key (map, topic->m_stopic, handle, sample)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -270,6 +282,9 @@ dds_unregister_instance_ih_ts(
 | 
			
		|||
        ret = DDS_ERRNO(DDS_RETCODE_PRECONDITION_NOT_MET);
 | 
			
		||||
    }
 | 
			
		||||
    ddsi_sertopic_free_sample (topic->m_stopic, sample, DDS_FREE_ALL);
 | 
			
		||||
    if (asleep) {
 | 
			
		||||
        thread_state_asleep(thr);
 | 
			
		||||
    }
 | 
			
		||||
    dds_entity_unlock(wr);
 | 
			
		||||
err:
 | 
			
		||||
    return ret;
 | 
			
		||||
| 
						 | 
				
			
			@ -288,10 +303,18 @@ dds_writedispose_ts(
 | 
			
		|||
 | 
			
		||||
    rc = dds_writer_lock(writer, &wr);
 | 
			
		||||
    if (rc == DDS_RETCODE_OK) {
 | 
			
		||||
        struct thread_state1 * const thr = lookup_thread_state();
 | 
			
		||||
        const bool asleep = !vtime_awake_p(thr->vtime);
 | 
			
		||||
        if (asleep) {
 | 
			
		||||
            thread_state_awake(thr);
 | 
			
		||||
        }
 | 
			
		||||
        ret = dds_write_impl (wr, data, timestamp, DDS_WR_ACTION_WRITE_DISPOSE);
 | 
			
		||||
        if (ret == DDS_RETCODE_OK) {
 | 
			
		||||
            dds_instance_remove (wr->m_topic, data, DDS_HANDLE_NIL);
 | 
			
		||||
        }
 | 
			
		||||
        if (asleep) {
 | 
			
		||||
            thread_state_asleep(thr);
 | 
			
		||||
        }
 | 
			
		||||
        dds_writer_unlock(wr);
 | 
			
		||||
    } else {
 | 
			
		||||
        DDS_ERROR("Error occurred on locking writer\n");
 | 
			
		||||
| 
						 | 
				
			
			@ -309,6 +332,7 @@ dds_dispose_impl(
 | 
			
		|||
       _In_ dds_time_t timestamp)
 | 
			
		||||
{
 | 
			
		||||
    dds_return_t ret;
 | 
			
		||||
    assert(vtime_awake_p(lookup_thread_state()->vtime));
 | 
			
		||||
    assert(wr);
 | 
			
		||||
    ret = dds_write_impl(wr, data, timestamp, DDS_WR_ACTION_DISPOSE);
 | 
			
		||||
    if (ret == DDS_RETCODE_OK) {
 | 
			
		||||
| 
						 | 
				
			
			@ -330,7 +354,15 @@ dds_dispose_ts(
 | 
			
		|||
 | 
			
		||||
    rc = dds_writer_lock(writer, &wr);
 | 
			
		||||
    if (rc == DDS_RETCODE_OK) {
 | 
			
		||||
        struct thread_state1 * const thr = lookup_thread_state();
 | 
			
		||||
        const bool asleep = !vtime_awake_p(thr->vtime);
 | 
			
		||||
        if (asleep) {
 | 
			
		||||
            thread_state_awake(thr);
 | 
			
		||||
        }
 | 
			
		||||
        ret = dds_dispose_impl(wr, data, DDS_HANDLE_NIL, timestamp);
 | 
			
		||||
        if (asleep) {
 | 
			
		||||
            thread_state_asleep(thr);
 | 
			
		||||
        }
 | 
			
		||||
        dds_writer_unlock(wr);
 | 
			
		||||
    } else {
 | 
			
		||||
        DDS_ERROR("Error occurred on locking writer\n");
 | 
			
		||||
| 
						 | 
				
			
			@ -353,15 +385,23 @@ dds_dispose_ih_ts(
 | 
			
		|||
 | 
			
		||||
    rc = dds_writer_lock(writer, &wr);
 | 
			
		||||
    if (rc == DDS_RETCODE_OK) {
 | 
			
		||||
        struct thread_state1 * const thr = lookup_thread_state();
 | 
			
		||||
        const bool asleep = !vtime_awake_p(thr->vtime);
 | 
			
		||||
        struct ddsi_tkmap *map = gv.m_tkmap;
 | 
			
		||||
        const dds_topic *topic = dds_instance_info((dds_entity*)wr);
 | 
			
		||||
        void *sample = ddsi_sertopic_alloc_sample (topic->m_stopic);
 | 
			
		||||
        if (asleep) {
 | 
			
		||||
            thread_state_awake(thr);
 | 
			
		||||
        }
 | 
			
		||||
        if (ddsi_tkmap_get_key (map, topic->m_stopic, handle, sample)) {
 | 
			
		||||
            ret = dds_dispose_impl(wr, sample, handle, timestamp);
 | 
			
		||||
        } else {
 | 
			
		||||
            DDS_ERROR("No instance related with the provided handle is found\n");
 | 
			
		||||
            ret = DDS_ERRNO(DDS_RETCODE_PRECONDITION_NOT_MET);
 | 
			
		||||
        }
 | 
			
		||||
        if (asleep) {
 | 
			
		||||
            thread_state_asleep(thr);
 | 
			
		||||
        }
 | 
			
		||||
        ddsi_sertopic_free_sample (topic->m_stopic, sample, DDS_FREE_ALL);
 | 
			
		||||
        dds_writer_unlock(wr);
 | 
			
		||||
    } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -390,9 +430,17 @@ dds_lookup_instance(
 | 
			
		|||
 | 
			
		||||
    topic = dds_instance_info_by_hdl (entity);
 | 
			
		||||
    if (topic) {
 | 
			
		||||
        struct thread_state1 * const thr = lookup_thread_state();
 | 
			
		||||
        const bool asleep = !vtime_awake_p(thr->vtime);
 | 
			
		||||
        if (asleep) {
 | 
			
		||||
            thread_state_awake(thr);
 | 
			
		||||
        }
 | 
			
		||||
        sd = ddsi_serdata_from_sample (topic->m_stopic, SDK_KEY, data);
 | 
			
		||||
        ih = ddsi_tkmap_lookup (map, sd);
 | 
			
		||||
        ddsi_serdata_unref (sd);
 | 
			
		||||
        if (asleep) {
 | 
			
		||||
            thread_state_asleep(thr);
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        DDS_ERROR("Acquired topic is NULL\n");
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -416,6 +464,8 @@ dds_instance_get_key(
 | 
			
		|||
        dds_instance_handle_t inst,
 | 
			
		||||
        void *data)
 | 
			
		||||
{
 | 
			
		||||
    struct thread_state1 * const thr = lookup_thread_state();
 | 
			
		||||
    const bool asleep = !vtime_awake_p(thr->vtime);
 | 
			
		||||
    dds_return_t ret;
 | 
			
		||||
    const dds_topic * topic;
 | 
			
		||||
    struct ddsi_tkmap * map = gv.m_tkmap;
 | 
			
		||||
| 
						 | 
				
			
			@ -433,13 +483,18 @@ dds_instance_get_key(
 | 
			
		|||
        goto err;
 | 
			
		||||
    }
 | 
			
		||||
    ddsi_sertopic_zero_sample (topic->m_stopic, data);
 | 
			
		||||
    if (asleep) {
 | 
			
		||||
        thread_state_awake(thr);
 | 
			
		||||
    }
 | 
			
		||||
    if (ddsi_tkmap_get_key (map, topic->m_stopic, inst, data)) {
 | 
			
		||||
        ret = DDS_RETCODE_OK;
 | 
			
		||||
    } else{
 | 
			
		||||
        DDS_ERROR("No instance related with the provided entity is found\n");
 | 
			
		||||
        ret = DDS_ERRNO(DDS_RETCODE_BAD_PARAMETER);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (asleep) {
 | 
			
		||||
        thread_state_asleep(thr);
 | 
			
		||||
    }
 | 
			
		||||
err:
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue