/[pdpsoft]/trunk/grid-mw-security/ees/src/aos/aos.c
ViewVC logotype

Diff of /trunk/grid-mw-security/ees/src/aos/aos.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1389 by aramv, Tue Jan 12 12:25:15 2010 UTC revision 1390 by aramv, Mon Jan 18 15:41:17 2010 UTC
# Line 26  aos_storage_t * aos_get_storage(){ Line 26  aos_storage_t * aos_get_storage(){
26    
27    if(!(storage = pthread_getspecific(_aos_key))) {    if(!(storage = pthread_getspecific(_aos_key))) {
28      if((storage = calloc(1, sizeof(aos_storage_t)))){      if((storage = calloc(1, sizeof(aos_storage_t)))){
29          storage->last_context = NULL;
30        pthread_setspecific(_aos_key, storage);        pthread_setspecific(_aos_key, storage);
31        printf("Created new TLS at %p\n", storage);        printf("Created new TLS at %p\n", storage);
32      }      }
# Line 60  EES_RC aos_free_storage(aos_storage_t* s Line 61  EES_RC aos_free_storage(aos_storage_t* s
61        /* free here */        /* free here */
62        printf("Checking attribute at %p\n", attribute);        printf("Checking attribute at %p\n", attribute);
63        if(attribute->needs_free){        if(attribute->needs_free){
64          eef_log(LOG_DEBUG, "Freeing arg %i at %p\n",attribute_count, attribute);          eef_log(LOG_DEBUG, "Freeing arg data %i at %p\n",attribute_count, attribute->data);
65          free(attribute->data);          free(attribute->data);
66          free(attribute);          free(attribute);
67        } else {        } else {
68          eef_log(LOG_DEBUG, "Not freeing arg %i at %p\n",attribute_count, attribute);          /*eef_log(LOG_DEBUG, "Not freeing arg data %i at %p\n",attribute_count, attribute->data);*/
69            free(attribute);
70        }        }
71        attribute = next_attribute;        attribute = next_attribute;
72        attribute_count++;        attribute_count++;
# Line 85  aos_context_t * createContext(aos_contex Line 87  aos_context_t * createContext(aos_contex
87    if((context = calloc(1, sizeof(aos_context_t)))){    if((context = calloc(1, sizeof(aos_context_t)))){
88      context->context_class = context_class;      context->context_class = context_class;
89      context->list_attributes = NULL;      context->list_attributes = NULL;
90        context->last_attribute = NULL;
91      context->next = NULL;      context->next = NULL;
92    }    }
93    return context;    return context;
# Line 94  EES_RC addContext(aos_context_t* context Line 97  EES_RC addContext(aos_context_t* context
97    aos_storage_t* storage = aos_get_storage();    aos_storage_t* storage = aos_get_storage();
98    printf("Adding context at %p to storage at %p\n", context, storage);    printf("Adding context at %p to storage at %p\n", context, storage);
99    if(storage->last_context){    if(storage->last_context){
100        printf("Inserted at %p\n", storage->last_context);
101      storage->last_context->next = context;      storage->last_context->next = context;
102    } else {    } else {
103        printf("Created at %p\n", storage->list_contexts);
104      storage->list_contexts = context;      storage->list_contexts = context;
105        storage->last_context = NULL;
106    }    }
107      printf("Copied context to %p\n", storage->last_context);
108    storage->last_context = context;    storage->last_context = context;
109    return EES_SUCCESS;    return EES_SUCCESS;
110  }  }
111    
112  aos_context_t * getNextContext(aos_context_class_t context_class, aos_storage_t* storage){  aos_context_t * getNextContext(aos_context_class_t context_class, aos_storage_t* storage){
113    aos_context_t* current_context;    aos_context_t* current_context;
114    if(!storage){    aos_storage_t* current_storage;
115      storage = aos_get_storage();  
116      if(storage){
117        printf("Using passed storage\n");
118        current_storage = storage;
119      } else {
120        printf("Using TLS getter\n");
121        current_storage = aos_get_storage();
122    }    }
123    if(storage->last_context != NULL){  
124      current_context = storage->last_context->next;    if(current_storage->last_context != NULL){
125      storage->last_context = current_context;      printf("Picking up from last context\n");
126        current_context = current_storage->last_context->next;
127    } else {    } else {
128      current_context = storage->list_contexts;      printf("Walking list contexts\n");
129        current_context = current_storage->list_contexts;
130      while(current_context){      while(current_context){
131          printf("Current context: %p\n", current_context);
132        if((current_context->context_class == context_class) || (context_class == ANY) ){        if((current_context->context_class == context_class) || (context_class == ANY) ){
133            printf("Found context with class %i\n", context_class);
134          break;          break;
135        }        }
136        current_context = current_context->next;        current_context = current_context->next;
137      }      }
138    }    }
139      current_storage->last_context = current_context;
140    
141    if(current_context){    if(current_context){
142        printf("Found something on the first go\n");
143      return current_context;      return current_context;
144    } else {    } else {
145      if(storage != _global_storage){      if(current_storage != _global_storage){
146          printf("Retrying at global storage\n");
147        return getNextContext(context_class, _global_storage);        return getNextContext(context_class, _global_storage);
148      } else {      } else {
149        return NULL;        printf("Failed to find anything\n");
150      }      }
151    }    }
152      return NULL;
153  }  }
154    
155  void setContextObligationId(aos_context_t* context, char * obligation){  void setContextObligationId(aos_context_t* context, char * obligation){
# Line 136  void setContextObligationId(aos_context_ Line 158  void setContextObligationId(aos_context_
158    }    }
159  }  }
160    
161    char* getContextObligationId(aos_context_t* context){
162      return context->obligation_name;
163    }
164    
165  aos_attribute_t* createAttribute(void){  aos_attribute_t* createAttribute(void){
166    aos_attribute_t* attribute = NULL;    aos_attribute_t* attribute = NULL;
167    if((attribute = calloc(1, sizeof(aos_attribute_t)))){    if((attribute = calloc(1, sizeof(aos_attribute_t)))){
# Line 151  EES_RC addAttribute(aos_context_t * cont Line 177  EES_RC addAttribute(aos_context_t * cont
177      context->last_attribute->next = attribute;      context->last_attribute->next = attribute;
178    } else {    } else {
179      context->list_attributes = attribute;      context->list_attributes = attribute;
180        context->last_attribute = NULL;
181    }    }
182    context->last_attribute = attribute;    context->last_attribute = attribute;
183    return EES_SUCCESS;    return EES_SUCCESS;
# Line 330  void aos_make_key(void){ Line 357  void aos_make_key(void){
357  }  }
358    
359  void aos_free_key(void* storage){  void aos_free_key(void* storage){
360      pid_t             tid;
361      tid = syscall(SYS_gettid);
362      printf("Killing thread %i\n", tid);
363    aos_free_storage(storage);    aos_free_storage(storage);
364      printf("Freed storage for thread %i\n", tid);
365  }  }
366    
367  EES_RC AOS_Clean(void){  EES_RC AOS_Clean(void){
# Line 340  EES_RC AOS_Clean(void){ Line 371  EES_RC AOS_Clean(void){
371    if(!_is_threading){    if(!_is_threading){
372      return EES_FAILURE;      return EES_FAILURE;
373    }    }
374    /*aos_free_storage(aos_get_storage());*/    aos_free_storage(aos_get_storage());
375    printf("Freed storage for thread %i\n", tid);    printf("Freed storage for thread %i\n", tid);
376    return EES_SUCCESS;    return EES_SUCCESS;
377  }  }

Legend:
Removed from v.1389  
changed lines
  Added in v.1390

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28