Functions | Variables

gs_seq_data_handle.c File Reference

#include "gs_seq_data_handle.h"
Include dependency graph for gs_seq_data_handle.c:

Go to the source code of this file.

Functions

int make_new_data_handle_list (GS_DAG_t *dag)
int insert_data_handle (char *producer_func, int seq_id, int pindex, void *dptr, char *data_handle)
char * find_data_handle (char *consumer_func, int seq_id, int cindex, void *dptr)
void free_data_handle_list ()

Variables

data_handle_list_t * GS_SEQ_DATA_HANDLE_LIST = NULL

Function Documentation

char* find_data_handle ( char *  consumer_func,
int  seq_id,
int  cindex,
void *  dptr 
)

find a specific data handle according to the function name of the consumer service and the argument index in the consumer side

Definition at line 120 of file gs_seq_data_handle.c.

                                                                                {
    data_handle_t *handle;

    if (!GS_SEQ_DATA_HANDLE_LIST) {
        fprintf(stderr, "bad data handle list\n");
        return NULL;
    }
        
    if (GS_SEQ_DATA_HANDLE_LIST->num_handles == 0) {
        fprintf(stderr, "no data handle found\n");
        return NULL;
    }
    
    for (handle = GS_SEQ_DATA_HANDLE_LIST->head; 
        handle != NULL; handle = handle->next) {
        if (strcmp(handle->consumer_func, consumer_func) == 0 &&
            /*handle->cseq_id == seq_id && */
            handle->cindex == cindex &&
            handle->cdptr == dptr &&
            handle->used &&
            !handle->visited) {
            handle->visited = 1;
            if (!handle->data_handle) {
                fprintf(stderr, "bad data handle\n");
                return NULL;
            } else {
                return handle->data_handle;
            }
        }
    }
    
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void free_data_handle_list (  ) 

release the memory allocated for the data handle list

Definition at line 158 of file gs_seq_data_handle.c.

                             {
    data_handle_t *handle;

    if (GS_SEQ_DATA_HANDLE_LIST == NULL) return;

    /* there is no data handle to free */
    if (GS_SEQ_DATA_HANDLE_LIST->num_handles == 0) {
        free(GS_SEQ_DATA_HANDLE_LIST);
        GS_SEQ_DATA_HANDLE_LIST = NULL;
        return;
    }
    
    /* there is one data handle to free */
    if (GS_SEQ_DATA_HANDLE_LIST->num_handles == 1) {
        free(GS_SEQ_DATA_HANDLE_LIST->head);
        free(GS_SEQ_DATA_HANDLE_LIST);
        GS_SEQ_DATA_HANDLE_LIST = NULL;
        return;
    }

    /* there is more than one data handle to free */
    while (GS_SEQ_DATA_HANDLE_LIST->num_handles > 0) {
        handle = GS_SEQ_DATA_HANDLE_LIST->tail;
        GS_SEQ_DATA_HANDLE_LIST->tail = handle->prev;
        free(handle);
        GS_SEQ_DATA_HANDLE_LIST->num_handles--;
    }

    free(GS_SEQ_DATA_HANDLE_LIST);
    GS_SEQ_DATA_HANDLE_LIST = NULL;
    
    return;
}

Here is the caller graph for this function:

int insert_data_handle ( char *  producer_func,
int  seq_id,
int  pindex,
void *  dptr,
char *  data_handle 
)

insert a data handle to the data handle list

Definition at line 80 of file gs_seq_data_handle.c.

                                    {
    data_handle_t *handle;

    if (!data_handle) {
        fprintf(stderr, "bad data handle\n");
        return -1;
    }
    
    if (!GS_SEQ_DATA_HANDLE_LIST) {
        fprintf(stderr, "bad data handle list\n");
        return -1;
    }

    if (GS_SEQ_DATA_HANDLE_LIST->num_handles == 0) {
        fprintf(stderr, "no data handle hole found\n");
        return -1;
    }

    for (handle = GS_SEQ_DATA_HANDLE_LIST->head;
        handle != NULL; handle = handle->next) {
        if (strcmp(handle->producer_func, producer_func) == 0 &&
            /*handle->pseq_id == seq_id && */
            handle->pindex == pindex &&
            handle->pdptr == dptr &&
            !handle->used) {
            handle->data_handle = data_handle;
            handle->used = 1;
        }
    }

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int make_new_data_handle_list ( GS_DAG_t *  dag  ) 

create a new empty data handle list

Definition at line 18 of file gs_seq_data_handle.c.

                                             {
    GS_DAG_Dep_t *dep;
    data_handle_t *handle;

    
    GS_SEQ_DATA_HANDLE_LIST = 
    (data_handle_list_t *) malloc(sizeof(data_handle_list_t));
    if (!GS_SEQ_DATA_HANDLE_LIST) {
        perror("malloc");
        return -1;
    }
    
    GS_SEQ_DATA_HANDLE_LIST->head = NULL;
    GS_SEQ_DATA_HANDLE_LIST->tail = NULL;
    GS_SEQ_DATA_HANDLE_LIST->num_handles = 0;

    for (dep = dag->head_dep; dep != NULL; dep = dep->next) {

        if (dep->dep_type == INPUT_AFTER_OUTPUT_DEPENDENCY) {

            handle = (data_handle_t *) malloc(sizeof(data_handle_t));
            if (!handle) {
                perror("malloc");
                return -1;
            }

            handle->producer_func = dep->pnode->func_name;
            handle->consumer_func = dep->cnode->func_name;
            handle->pseq_id = dep->pnode->handle->problem_desc->seq_id;
            handle->cseq_id = dep->cnode->handle->problem_desc->seq_id;
            handle->pindex = dep->largp->index;
            handle->cindex = dep->rargp->index;
            handle->pdptr = dep->largp->data;
            handle->cdptr = dep->rargp->data;
            handle->used = 0;
            handle->visited = 0;

            if (GS_SEQ_DATA_HANDLE_LIST->num_handles == 0) {
                GS_SEQ_DATA_HANDLE_LIST->head = handle;
                GS_SEQ_DATA_HANDLE_LIST->tail = handle;
                handle->prev = NULL;
                handle->next = NULL;
                GS_SEQ_DATA_HANDLE_LIST->num_handles = 1;
            } else {
                handle->prev = GS_SEQ_DATA_HANDLE_LIST->tail;
                handle->next = NULL;
                GS_SEQ_DATA_HANDLE_LIST->tail->next = handle;
                GS_SEQ_DATA_HANDLE_LIST->tail = handle;
                GS_SEQ_DATA_HANDLE_LIST->num_handles++;
            }
        }
    }
    
    printf("# data handles: %d\n", GS_SEQ_DATA_HANDLE_LIST->num_handles);

    return 0;
}

Here is the caller graph for this function:


Variable Documentation

data_handle_list_t* GS_SEQ_DATA_HANDLE_LIST = NULL

Definition at line 12 of file gs_seq_data_handle.c.