void* getNotifier(LPCUSBSIO_I2C_Ctrl_t * dev) { CONTAINER_STATUS lContainerStatus = CONTAINER_SUCCESS; uint32_t size = 0x00; void* Notifier = NULL; if(NULL != dev) { framework_LockMutex(dev->NotifierContainerLock); if(NULL == dev->NotifierContainer) { lContainerStatus = container_create(&dev->NotifierContainer, 2); } if (CONTAINER_SUCCESS == lContainerStatus) { lContainerStatus = container_size(dev->NotifierContainer, &size); if(0x00 == size) { framework_CreateMutex(&Notifier); } else { container_remove(dev->NotifierContainer, 0x00, &Notifier); } } framework_UnlockMutex(dev->NotifierContainerLock); } return Notifier; }
void ReleaseNotifier(LPCUSBSIO_I2C_Ctrl_t * dev) { void* Notifier = NULL; if(NULL != dev) { framework_LockMutex(dev->NotifierContainerLock); if(NULL != dev->NotifierContainer) { do { container_remove(dev->NotifierContainer, 0x00, &Notifier); if(NULL != Notifier) { framework_DeleteMutex(Notifier); Notifier = NULL; } }while(NULL != Notifier); container_delete(dev->NotifierContainer); dev->NotifierContainer = NULL; } framework_UnlockMutex(dev->NotifierContainerLock); } }
void action(dungeon* d, int action) { int sel, x; container* con = (action==A_LOOT)? d->room_chest : &(d->player.inventory); item selection = {0,0,0,0}; if(action == A_LOOT && !d->cur_room->chest) { printf("There is no chest in this room!"); goto INVALID_SELECTION; } TOP: for (x=0; x < con->num_items; ++x) { get_item_desc(x, con->items[x]); } if(action != A_INVENTORY) { printf("[%d] Exit selection\n", con->num_items); for(;;) { sel = input(action_prompt[action], I_NUM); if(sel > con->num_items || sel < 0) { goto INVALID_SELECTION; } if(sel == con->num_items) { break; } if(action == A_DROP || action == A_LOOT) { selection = container_remove(con, sel); if(action == A_LOOT) { container_add(&(d->player.inventory), selection); get_item_desc(d->player.inventory.num_items - 1, selection); goto TOP; } break; } else if (action == A_PUTON && con->items[sel].type == T_ARMOR) { selection = container_remove(con, sel); d->player.armor = selection; get_item_desc(sel, selection); break; } else if (action == A_ARM && con->items[sel].type == T_WEAP) { selection = container_remove(con, sel); d->player.weapon = selection; get_item_desc(sel, selection); break; } else if (action == A_CONSUME && con->items[sel].type == T_FOOD) { selection = container_remove(con, sel); get_item_desc(sel, selection); d->player.hp += get_rand(selection.val * 2); break; } INVALID_SELECTION: printf("I believe I've made a mistake in my selection.\n"); if(!input("Should I try again (y/n)?", I_BOOL)) { break; } } } }