static void *threadFunc2(void *arg) { int ret; ret = obj_lock(&obj); sleep(1); printf("obj.a = %d\n", obj.a); printf("obj.b = %d\n", obj.b); ret = obj_unlock(&obj); return NULL; }
static void *threadFunc1(void *arg) { int ret; ret = obj_lock(&obj); obj.a = 10; sleep(2); obj.b = 20; ret = obj_unlock(&obj); return NULL; }
void objdict_clean(objdict_t *dict) { int i; void *obj; for (i=0;i<dict->len;i++) { obj = obj_lock(dict->def[i].value,NULL); if (obj) obj_unlock(obj); else dict->def[i].value = 0; if (!dict->def[i].value) { free(dict->def[i].name); if (dict->len > i + 1) dict->def[i] = dict->def[dict->len - 1]; dict->len--; i--; } } }
static int tags_shell_fun(int argc, const char *argv[]) { if (argc > 0) { shell_print("Usage: tags\n"); shell_print("List currently defined tags and sprite types\n"); } else { int i; shell_print("Currently defined sprite tags:\n"); for (i=0; i<sprite_tags->len; i++) { sprite_t *s = obj_lock(sprite_tags->def[i].value,&sprite_type); if (s) { shell_print("%s\t (%s)\n",sprite_tags->def[i].name,obj_type(s)->name); obj_unlock(s); } } } return 0; }