int main(void) { MAKE_FIFO(tf, 4); int i; assert(DEPTH(tf)==0); assert(FREE(tf)==4); for (i=0; i<3; i++) { PUT(tf, i); assert(DEPTH(tf)==i+1); assert(FREE(tf)==4-i-1); } assert(!IS_FULL(tf)); assert(IS_NOT_FULL(tf)); assert(!OVFL(tf)); PUT(tf, 5); assert(DEPTH(tf)==4); assert(FREE(tf)==0); assert(IS_FULL(tf)); assert(!IS_NOT_FULL(tf)); assert(!OVFL(tf)); REMOVE(tf); REMOVE(tf); assert(DEPTH(tf)==2); for (i=0; i<2; i++) { PUT(tf, i); assert(DEPTH(tf)==3+i); } REMOVE(tf); REMOVE(tf); REMOVE(tf); REMOVE(tf); assert(DEPTH(tf)==0); assert(FREE(tf)==4); for (i=0; i<4; i++) { PUT(tf, i); assert(DEPTH(tf)==i+1); assert(FREE(tf)==4-i-1); } assert(!OVFL(tf)); PUT(tf, 5); assert(OVFL(tf)); return 0; }
int PUSH_SIZE_CHECK(t_valor_variable*x , t_stack* pila, int pos) { if(IS_FULL(pila, pos)) return STACK_OVERFLOW; else { PUSH_POSITION(x,pila,pos); return SIN_ERROR; } }
bool RSRG::add_marking(const int& npl,const Net_Mark_p& net_mark,const int& num,const int& type,int (*pf)(const int&, const Net_Mark_p&)) { v[0][0]=0; int count=MAX_ID; int MASK = 1<<(count-1); int conv=num; v[0][1]=type; int j=2; while(count--) { v[0][j]=((conv & MASK ) ? 1 : 0); #if DEBUG6 cerr<<((conv & MASK ) ? 1 : 0); #endif conv <<= 1; j++; } for(int pl = 0 ; pl < npl; pl++) {/* foreach place */ if (GORDER) if (IS_NEUTRAL(pl)) {//neutral place v[0][pl+j]=net_mark[pl].total; } else {//colored if (IS_FULL(pl)) { v[0][pl+j]=(*pf)(pl,net_mark); } else {//empty v[0][pl+j]=0; }//empty }//colored place else {//colored not implemented v[0][pl+j]=net_mark[OrdPlaces[pl]].total; }//colored not implemented }/* foreach place */ //dd_edge new_marking(rs); rs->createEdge(v, 1, *new_marking); if ((type==3)||(type==1)) (*marking)+=(*new_marking); else (*un_marking)+=(*new_marking); #if DEBUG3 for (int i=0;i<npl+MAX_ID+2;i++) { cout<<"["<<i<<"]"<<v[0][i]<<" "; } cout<<endl; }
matrix_pointer new_node(void) { matrix_pointer temp; temp = (matrix_pointer)malloc(sizeof(matrix_node)); if(IS_FULL(temp)) { fprintf(stderr, "The memory is full\n"); exit(1); } return temp; }
void add(stack_pointer *top, element item) { stack_pointer temp = (stack_pointer) malloc(sizeof(stack)); if (IS_FULL(temp)) { fprintf(stderr, "The memory is full.\n"); return; } temp->item = item; temp->link = *top; *top = temp; }
struct rain_ctx * rain_ctx_new(rain_routine_t prid, const char * mod_name,const char *args) { if(IS_FULL(H)){ return NULL; } struct rain_moudle *mod = rain_module_query(mod_name); if(!mod){ RAIN_LOG(0,"MODE_QUERY:modname:%s",mod_name); return NULL; } //INIT struct rain_ctx *ctx = malloc(sizeof(struct rain_ctx)); ctx->mod = mod; ctx->bdis = 0; ctx->recv = NULL; ctx->recv_rsp = NULL; ctx->link = NULL; ctx->session = 0; ctx->timeoutfn = NULL; ctx->nexttickfn = NULL; rain_mutex_init(&ctx->mtx); wod_array_init(&ctx->arr,sizeof(rain_routine_t)); ctx->msgQue = rain_message_queue_new(); ctx->bmain = false; _ctx_genid(ctx); ctx->ref = 1; ctx->bexit = 0; ctx->prid = prid; ctx->arg = rain_module_instance_init(mod,ctx,args); //EXEC; if(ctx->arg == NULL){ RAIN_LOG(0,"RAIN_MAIN_FIALED:modname:%s args:%s",mod_name,args); rain_ctx_unref(ctx); return NULL; } __sync_bool_compare_and_swap(&ctx->bmain,false,true); if(rain_message_queue_size(ctx->msgQue) > 0){ if(__sync_bool_compare_and_swap(&ctx->bdis,0,1)){ rain_life_queue_push(ctx->rid); } } RAIN_LOG(0,"LAUNCH.ctx(%x.%s).arguments:%s",ctx->rid,mod_name,args); return ctx; }
/*二叉树的复制*/ tree_pointer copy(tree_pointer original) { tree_pointer temp; if(original) { temp = (tree_pointer)malloc(sizeof(Node)); if(IS_FULL(temp)) { fprintf(stderr, "The memory is full\n"); exit(1); } temp->left_child = copy(original->left_child); temp->right_child = copy(original->right_child); temp->data = original->data; return temp; } return NULL; }
static void _ctx_genid(struct rain_ctx *ctx) { assert(!IS_FULL(H)); struct rain_handle* h = H; rain_mutex_lock(&h->mtx); int hash; for(;;){ int handle = h->cut_index++; hash = hash_func(handle); if(!h->ppctx[hash]){ break; } } assert(hash != -1); h->ppctx[hash] = ctx; ctx->rid =CREATE_ID(h->rainid,hash); ++h->num_used; rain_mutex_unlock(&h->mtx); }
bool RSRG::init_RS(const int& npl,const Net_Mark_p& net_mark,const int&num,int (*pf)(const int&, const Net_Mark_p&)) { v[0][0]=0; int count=MAX_ID; int MASK = 1<<(count-1); int conv=num; v[0][1]=0;//tangible int j=2; while(count--) { v[0][j]=((conv & MASK ) ? 1 : 0); #if DEBUG6 cerr<<((conv & MASK ) ? 1 : 0); #endif conv <<= 1; j++; } for(int pl = 0 ; pl < npl; pl++) {/* foreach place */ if (GORDER) { if (IS_NEUTRAL(pl)) {//neutral place v[0][pl+j]=net_mark[pl].total; }//neutral place else {//colored if (IS_FULL(pl)) { v[0][pl+j]=pf(pl,net_mark); } else {//empty v[0][pl+j]=0; }//empty }//colored place } else {//colored not implemented v[0][pl+j]=net_mark[OrdPlaces[pl]].total; }//colored not implemented }/* foreach place */ rs->createEdge(v, 1, *un_marking); #if DEBUG3 for (int i=0;i<npl+MAX_ID+2;i++) { cout<<"["<<i<<"]"<<v[0][i]<<" "; } cout<<endl<<endl; #endif #if DEBUG cout<<"\nInitial Marking\n"; (*un_marking).show(stdout,true); #endif return true; }
int main() { short int out[MAX_SIZE]; node_pointer seq[MAX_SIZE]; node_pointer x,y,top; int i,j,n; printf("Enter the size (<= %d) ", MAX_SIZE); scanf("%d",&n); for(i=0;i<n;i++) { out[i] = TRUE; seq[i] = NULL; } printf("Enter a pair of numbers (-1 -1 to quit): "); scanf("%d%d",&i,&j); while(i>=0) { x = (node_pointer)malloc(sizeof(node)); if(IS_FULL(x)) { fprintf(stderr, "The memory is full\n"); exit(1); } x->data = j; x->link = seq[i]; seq[i] = x; x = (node_pointer)malloc(sizeof(node)); if(IS_FULL(x)) { fprintf(stderr, "The memory is full\n"); exit(1); } x->data = i; x->link = seq[j]; seq[j] = x; printf("Enter a pair of numbers (-1 -1 quit): "); scanf("%d%d",&i,&j); } for(i=0;i<n;i++) { if(out[i]) { printf("\nNew class: %5d",i); out[i] = FALSE; x = seq[i]; top = NULL; for(;;) { while(x) { j = x->data; if(out[j]) { printf("%5d", j); out[j] = FALSE; y = x->link; x->link = top; top = x; x = y; } else { x = x->link; } } if(!top) break; x=seq[top->data]; top = top->link; } } } return 0; }