[Gs-commits] r597 - trunk/code/src/gsl/common
Author: slang Date: 2009-06-23 19:03:12 -0500 (Tue, 23 Jun 2009) New Revision: 597 Modified: trunk/code/src/gsl/common/gs.c Log: allow NULL context to be passed to gs_poll Modified: trunk/code/src/gsl/common/gs.c =================================================================== --- trunk/code/src/gsl/common/gs.c 2009-06-23 23:35:17 UTC (rev 596) +++ trunk/code/src/gsl/common/gs.c 2009-06-24 00:03:12 UTC (rev 597) @@ -48,9 +48,9 @@ if(idx != (gs_resource_count -1)) { - /* this is not the last resource in the table; shift everything down */ - memmove(&gs_resource_entries[idx], &gs_resource_entries[idx+1], - (sizeof(struct gs_resource_entry) * (gs_resource_count-idx-1))); + /* this is not the last resource in the table; shift everything down */ + memmove(&gs_resource_entries[idx], &gs_resource_entries[idx+1], + (sizeof(struct gs_resource_entry) * (gs_resource_count-idx-1))); } gs_resource_count--; } @@ -80,7 +80,7 @@ if(resource_id == 0) { - ctl = (struct gs_ctl *)(intptr_t)gs_id_lookup(op_id, NULL); + ctl = (struct gs_ctl *)(intptr_t)gs_id_lookup(op_id, NULL); gs_mutex_lock(&ctl->mutex); if(ctl->cancelled) { @@ -91,9 +91,9 @@ ctl->cancelled = 1; if(ctl->in_pwait) - { + { /* cancel children */ - struct gs_list_link *entry; + struct gs_list_link *entry; struct gs_ctl *child_ctl; if(gs_list_empty(&ctl->children)) { @@ -116,7 +116,7 @@ ret = gs_cancel_op(context, ctl->current_op_id); } gs_mutex_unlock(&ctl->mutex); - return ret; + return ret; } ret = gs_resource_entries[ridx].resource->cancel(context, op_id); @@ -145,18 +145,18 @@ ctl = (struct gs_ctl *)ptr; if(gs_list_empty(&ctl->children)) { - return -EINVAL; + return -EINVAL; } gs_list_for_each(entry, &ctl->children) { - child_ctl = gs_list_get_entry(entry, typeof(*child_ctl), link); - ret = gs_cancel_op(context, child_ctl->current_op_id); - if(ret != 0) - { - /* cancel failed */ - return ret; - } + child_ctl = gs_list_get_entry(entry, typeof(*child_ctl), link); + ret = gs_cancel_op(context, child_ctl->current_op_id); + if(ret != 0) + { + /* cancel failed */ + return ret; + } } return 0; @@ -196,23 +196,42 @@ int resource_ms, i, ret; int rid, ridx; int resources_polled = 0; - - resource_ms = millisecs / context->resource_count; - - for(i = 0; i < context->resource_count; ++i) + + if(context) { - rid = context->resource_ids[i]; - ridx = GS_RESOURCE_ID2IDX(rid); - if(gs_resource_entries[ridx].resource->poll_context) + resource_ms = millisecs / context->resource_count; + for(i = 0; i < context->resource_count; ++i) { - ret = gs_resource_entries[ridx].resource->poll_context(context, resource_ms); - if(ret != 0) + rid = context->resource_ids[i]; + ridx = GS_RESOURCE_ID2IDX(rid); + if(gs_resource_entries[ridx].resource->poll_context) { - return ret; + ret = gs_resource_entries[ridx].resource->poll_context(context, resource_ms); + if(ret != 0) + { + return ret; + } + resources_polled++; } - resources_polled++; } } + else + { + resource_ms = millisecs / gs_resource_count; + for(i = 0; i < gs_resource_count; ++i) + { + if(gs_resource_entries[i].resource->poll_context) + { + ret = gs_resource_entries[i].resource->poll_context( + context, resource_ms); + if(ret != 0) + { + return ret; + } + resources_polled++; + } + } + } if(resources_polled == 0) { @@ -264,7 +283,7 @@ rname = va_arg(ap, char *); /* find the matching resource and register the context with that resource */ - + for(j = 0; j < gs_resource_count; ++j) { if(!strcmp(gs_resource_entries[j].resource->resource_name, rname)) @@ -296,11 +315,11 @@ *context = c; return 0; } - + int gs_context_destroy(gs_context_t context) { int rid, idx, i; - + for(i = 0; i < context->resource_count; ++i) { rid = context->resource_ids[i]; @@ -317,7 +336,11 @@ return 0; } - - - - +/* + * Local variables: + * c-indent-level: 4 + * c-basic-offset: 4 + * End: + * + * vim: ts=8 sts=4 sw=4 expandtab + */
participants (1)
-
slang@mcs.anl.gov