static inline void fp_rem_thd(struct sched_thd *t) { u16_t p = sched_get_metric(t)->priority; /* if on a list _and_ no other thread at this priority? */ if (!EMPTY_LIST(t, prio_next, prio_prev) && t->prio_next == t->prio_prev) { mask_unset(p); } REM_LIST(t, prio_next, prio_prev); }
void *pool_malloc(mem_pool *pool) { uint8_t i; for(i = 0; i < pool->num_elems; ++i) { if(mask_query(pool->free_vec, i)) { mask_unset(pool->free_vec, i); return (pool->pool + (i * pool->type_size)); } } return NULL; }
static uint8_t dvdrp_mesg_send(dvdrp_mesg_pkt *dvdrp_ptr, comBuf *pkt) { node_id_t cur_next_hop = 0; //to make build clean uint32_t /*global,*/ local_bv; uint8_t global; uint8_t i, ret; // Add the proto ID to the end of the packet. pkt->data[pkt->size++] = DVDRP_PROTO_ID; // This is a rather rough function to write without dynamicly // sized DSs, so here it is unoptimized: // 1) create a global bit vector marked with matching routes // 2) take the first marked route and record it's next_hop // 3) unmark that route from the global bv ---\ !! // 4) mark in the local bv ---/ now rolled into step 5! // 5) iterate through the rest of the marked routes // a) if next_hop is the same, repeat 3 & 4 for route // 6) local bv is packets bvs; assign and send out // 7) goto 2 // // This strategy, while slow, saves on the need for larger arrays // or other memory hungary data structures. We can pay for // smaller memory size with a little bit of energy. // // Note: I've looked at the asm for this function and it's horrid. // avr-libc's 32-bit number support isn't poor, but rather I // didn't realize what an impact emulating 32-bit operations would // have. This function will need to get a serious facelift soon. // If the use of global can be reduced by doing inline marking in // the route table, or some other method, it'll be a major victory // toward reducing the size. // 1) global = 0; ret = FALSE; for(i = 0; i < DVDRP_RT_MAX_PREDICATES; ++i) { if(route_tbl[i].receiver_id != DVDRP_INVALID_NODE_ID && mask_query(dvdrp_ptr->split_bv, route_tbl[i].bv_pos)) { // printf(".r;%d:%C", route_tbl[i].receiver_id, route_tbl[i].bv_pos); mask_set(global, i); } } // 2) while(1) { for(i = 0; i < DVDRP_RT_MAX_PREDICATES; ++i) { if(mask_query(global, i)) { cur_next_hop = route_tbl[i].paths[0].next_hop; break; } } if(i == DVDRP_RT_MAX_PREDICATES) { // printf(".outp"); break; } // 5) local_bv = 0; for(i = 0; i < DVDRP_RT_MAX_PREDICATES; ++i) { // 5a) if(mask_query(global, i) && cur_next_hop == route_tbl[i].paths[0].next_hop) { // 5a - 3) mask_unset(global, i); // 5a - 4) mask_set(local_bv, route_tbl[i].bv_pos); } } //check for local delivery if(cur_next_hop == node_id) { ret = TRUE; // printf(".mf;l"); } else { dvdrp_ptr->immed_dest = cur_next_hop; dvdrp_ptr->split_bv = local_bv; // printf(".mf;%d", dvdrp_ptr->immed_dest); com_send(IFACE_RADIO, pkt); //mos_led_toggle(1); } } // printf(".pts;%d\n", mos_check_stack(mos_thread_current())); return ret; }
int str_to_mask (Mask *mask, const char *orig, char **rejects) { char *ptr, *rest; int len, i, neg; int warn = 0; char * str; size_t cluep = 0; mask_unsetall(mask); if (!orig) return 0; /* Whatever */ if (rejects == NULL || *rejects != NULL) panic(1, "str_to_mask: rejects must be a pointer to null"); str = LOCAL_COPY(orig); while ((str = next_arg(str, &rest)) != NULL) { while (str) { if ((ptr = strchr(str, ',')) != NULL) *ptr++ = 0; if ((len = strlen(str)) != 0) { if (my_strnicmp(str, "ALL", len) == 0) mask_setall(mask); else if (my_strnicmp(str, "NONE", len) == 0) mask_unsetall(mask); else { if (*str == '-') { str++, len--; neg = 1; } else neg = 0; for (i = 0; i < level_bucket->numitems; i++) { if (!my_strnicmp(str, LEVELNAME(i), len)) { if (neg) mask_unset(mask, LEVELNUM(i)); else mask_set(mask, LEVELNUM(i)); break; } } if (i == level_bucket->numitems) malloc_strcat_word_c(rejects, space, str, DWORD_NO, &cluep); } } str = ptr; } str = rest; } if (rejects && *rejects) return -1; return 0; }