data_type dequeue() { pointer_t tail, head, next; data_type val=NULL; while(true){ head = this->head_; tail = this->tail_; next = (head.ptr)->next; if (head != this->head_) continue; if(head.ptr == tail.ptr){ if (next.ptr == NULL){ return 1; } pointer_t new_pt(next.ptr, tail.tag+1); CAS2(&(this->tail_), tail, new_pt); } else{ val = next.ptr->value; pointer_t new_pt(next.ptr, head.tag+1); if(CAS2(&(this->head_), head, new_pt)){ break; } } } delete head.ptr; return val; }
void parse(t_env *env) { char *line; char **tab; t_point *cur; cur = env->map; while (get_next_line(env->arg.fd, &line) > 0) { test_line(env, line); tab = ft_strsplit(line, ' '); ft_strdel(&line); env->map_x = 0; while (tab[env->map_x] != NULL) { cur->next = new_pt(env->map_x, env->map_y, atoi(tab[env->map_x])); cur = cur->next; env->map_x += 1; } destroy_tab(tab); env->map_y += 1; } ft_strdel(&line); (env->map_y == 0 ? error(env, 1) : 0); define_map(env); (close(env->arg.fd) == -1 ? error(env, 4) : 0); }
void enqueue(data_type val) { pointer_t tail, next; node_t* nd = new node_t(); nd->value = val; //printf("%lld\n", val); while(true){ tail = this->tail_; next = tail.ptr->next; if (tail == this->tail_) { if(next.ptr == NULL) { pointer_t new_pt(nd, next.tag+1); if(CAS2(&(this->tail_.ptr->next), next, new_pt)){ break; // Enqueue done! } }else { pointer_t new_pt(next.ptr, tail.tag+1); CAS2(&(this->tail_), tail, new_pt); } } } pointer_t new_pt(nd, tail.tag+1); CAS2(&(this->tail_), tail, new_pt); }
Point2f Project( float x, float y, float z, float *ret_depth = NULL ) const { Matx31f X, new_pt; X(0) = x; X(1) = y; X(2) = z; new_pt = m_R*X + m_t; if ( ret_depth ) { *ret_depth = -new_pt(2); } new_pt(0) /= -new_pt(2); new_pt(1) /= -new_pt(2); new_pt(2) = 1.0f; new_pt = m_K*new_pt; return Point2f( new_pt(0), new_pt(1) ); }
void Arcball::mouse_motion(int x, int y, int shift, int ctrl, int alt) { /* Set the X constraint if CONTROL key is pressed, Y if ALT key */ set_constraints( ctrl != 0, alt != 0 ); vec2 new_pt( (float)x, (float) y ); vec3 v0 = mouse_to_sphere( down_pt ); vec3 v1 = mouse_to_sphere( new_pt ); vec3 cross = v0^v1; q_drag.set( cross, v0 * v1 ); // *rot_ptr = (q_drag * q_now).to_mat4(); mat4 temp = q_drag.to_mat4(); *rot_ptr = *rot_ptr * temp; down_pt = new_pt; /* We keep a copy of the current incremental rotation (= q_drag) */ q_increment = q_drag; rot_increment = q_increment.to_mat4(); set_constraints(false, false); if ( q_increment.s < .999999 ) { is_spinning = true; zero_increment = false; } else { is_spinning = false; zero_increment = true; } }