Ejemplo n.º 1
0
pop()
{
	int tem,temp=0;
	temp=deque(head);
	while((tem=deque(head))!=-1)
	{
		swapQ();
		enque(temp,head);
		swapQ();
		temp=tem;		
	}
	swapQ();
	return temp;
}
Ejemplo n.º 2
0
int main(){
	Node* front=NULL,*rear = NULL;
	enq(&front, &rear, 1);
	enq(&front, &rear, 3);
	enq(&front, &rear, 6);
	enq(&front, &rear, 4);
	disp(front);
	puts("");
	deque(&front);
	deque(&front);
	disp(front);
	getchar();
	return 0;
}
Ejemplo n.º 3
0
static void* reconn_fun(void* arg){
		conn_t* conn;
		queue_t* q = &g_ctx.reconn_q;
		rval_t rval;
		int  times = 1;
		while(1){
				conn = list_entry(deque(q), conn_t,  reconn_link);
				assert(conn->conn_state == CONNECTING);
				assert(conn->conn_type == ACTIVE);
				debug_info("start reconn conn[%d], fd[%d],%s \n",
						   conn->id, conn->sockfd, dump_addr(conn->addr));
				rval =  re_connect(conn);
				if(success(rval)){
					debug_info("reconn conn[%d], fd[%d] success! \n", conn->id, conn->sockfd);
					set_conn_state(conn, CONNECTED);
					add_event(conn);

				}else{
						debug_warn("reconn conn[%d], fd[%d] failed! errno[%d]\n",
								conn->id, conn->sockfd, rval.err);
						enque(q, &conn->reconn_link); //continue reconn
				}
				sleep(times);
		}
}
Ejemplo n.º 4
0
BFS(int st, int n)
{
	 int p,q,r,i,j;
	 intialise(n);

	 enque(st-1);
	 time[st-1]=0;
	 par[st-1]=-1;
	 chk[st-1]=1;
	 
	 while(front<=rear)
	 {
	 	printf("\nworking");
	 	p=deque();
	 	printf(" %d ",p+1);
	 	//tim++;
	 	for(i=0;i<n;i++)
	 	{
	 		if(a[p][i]==1 && chk[i]==0)
	 		{
	 			enque(i);
	 			par[i]=p+1;
	 			time[i]=time[p]+1;
	 			chk[i]=1;
	 		}
	 	}	
	 }
}
int main()
{
	int n1;
	scanf("%d", &n1);
	int sq[n1];
	
	int n2, n, front, rear, i, c;
	front = rear = -1;
	scanf("%d", &n2);
	char s[100];
	for(i = 0; i < n2; i++) {
		scanf("%s", s);
		if (strcmp(s,"enque") == 0) {
			getchar();
			getchar();
			scanf("%d",&n);
			enque(sq,n,n1,&front,&rear);
		} else if (strcmp(s,"deque") == 0) {
			getchar();
			getchar();
			deque(sq,n1,&front,&rear);
		} else {
			c = size(n1,&front,&rear);
			printf("%d\n", c);
		}
	}
	return 0;
}
Ejemplo n.º 6
0
void flatten(struct node *n)
{
  if(n == NULL) return;
  struct node *curr = n;
  struct node *prev = NULL;
  init();
  enqueue(curr);
  while(!empty())
  {
    struct node *t = deque();
    if(prev!=NULL)
    {
      prev->next = t;
    }
    while(t!=NULL)
    {
      //      printf(" %d ",t->data);
      if(t->child!=NULL)
      {
        enqueue(t->child);
      }
      prev = t;
      t = t->next;
    }
  }
}
int main()
{
	int n1;
	scanf("%d", &n1);
	int sq[n1];
	
	int n2, n, front, rear, i;
	front = rear = -1;
	scanf("%d", &n2);
	char s[100];
	for(i = 0; i < n2; i++) {
		scanf("%s", s);
		if (strcmp(s,"enque") == 0) {
			getchar();
			getchar();
			scanf("%d",&n);
			enque(sq,n,n1,&front,&rear);
		} else if (strcmp(s,"deque") == 0) {
			getchar();
			getchar();
			deque(sq,&front,&rear);
		} else if (s[0] == 's' || s[0] == 'S') {
			size(&front,&rear);
		} else if (s[0] == 'f' || s[0] == 'F') {
			front_element(sq,&front,&rear);
		} else {
			rear_element(sq,&front,&rear);
		}
	}
	return 0;
}
Ejemplo n.º 8
0
int bfs(int s,int a, struct vertex *adj) {
    int i, u, j, l, v, w, k;

    struct queue *queue = malloc(sizeof(struct queue));
    struct queue *queueHyphen = malloc(sizeof(struct queue));
    queueInit(queue);
    queueInit(queueHyphen);
#pragma omp parallel for shared(adj)
    for (i = 0; i < adj[s].indeg; i++) { //par begin //compare ok
        u = adj[s].ins[i].u;
        j = adj[s].ins[i].iuout;
        eliminate(adj, u, j);                       //compare ok
    } //par end                                     //compare ok
    l = 0;                                          //compare ok
    adj[s].traversal = a;                           //compare ok
    adj[s].distance = l;                            //compare ok //before was adj[s].distance = l //compare with php
    struct queueNode *queueNode1 = malloc(sizeof(struct queueNode));
    enque(s, queue, queueNode1);                               //todo
//    printf("l74:queue -- should've queued %i\n", s);
    queueReset(queueHyphen);                        //todo
//    printf("l76:queueHypen -- should've reset");
    while (true) {  //repeat 1 begin
        l = l + 1;                                  //compare ok
        while (true) {  //repeat 2 begin
            u = deque(queue);                      //todo
//            printf("l81:queue -- should've dequeued %i\n", u);
            while (adj[u].first < adj[u].outdeg) {  //compare ok
                i = adj[u].first;                   //compare ok
                v = adj[u].out[i];                  //compare ok
#pragma omp parallel for shared(adj)
                for (j = 0; j < adj[v].indeg; j++) {  //par begin //compare ok
                    w = adj[v].ins[j].u;
                    k = adj[v].ins[j].iuout;
                    eliminate(adj, w, k);           //compare ok
                } //par end                         //compare ok
                a = a + 1;                          //compare ok
                adj[v].traversal = a;               //compare ok
                adj[v].distance = l;                //compare ok
                adj[v].parent = u;                  //compare ok
//                printf(":%i parent of %i\n", u, v);  //comment me
                struct queueNode *queueNode2 = malloc(sizeof(struct queueNode));
                enque(v, queueHyphen, queueNode2);              //todo
//                printf("l103:queueHyphen -- should've queued %i\n", v);
            } //end while                           //compare ok
            if (isQueueEmpty(queue)) {  //until
                break;
            }
        } //repeat 2 end                            //compare ok
        *queue = *queueHyphen;
        queueInit(queueHyphen);
//        printf("l121:queue = queueHyphen\n");
        if (isQueueEmpty(queue)) {
            break;
        }
    } //end repeat 1                                //compare ok
    return EXIT_SUCCESS;
}
Ejemplo n.º 9
0
void main()
{
  int ch=0,k,l;
	while(ch!=6)
	  {
	    printf("choose your option..!\n");
	    while((q!=1)&&(q!=2))
		{
		  printf("1.Input Restricted\t2.Output Restricted\n");
		  scanf("%d",&q);
		  if((q!=1)&&(q!=2))
		    printf("Wrong option\n");
		}
	    printf("1.Enqueue\t2.Dequeue\t3.Display\t4.Search\t5.Change the type\t6.Exit\n");
	    scanf("%d",&ch);
		switch(ch)
		  {
		  case 1:
		    printf("Enter the element to be queued\n");
		    scanf("%d",&k);
		    enque(k);
		    break;
		  case 2:
		    k=deque();
		    if(flag==0)
		      printf("Element %d is removed from the queue...!\n",k);
		    break;
		  case 3:
		    if((front==-1)||(front>rear))
		      printf("Nothing to display!!");
		    else
		      {
			printf("Elements in the queue are\n");
			display();
		      }
		    printf("\n");
		    break;
		  case 4:
		    printf("Enter the element to searched\n");
		    scanf("%d",&k);
		    l=search(k);
		    if(l==0)
		      printf("%d is not present in the queue\n",k);
		    else
		      printf("%d is present at the position %d\n",k,l);
		    break;
		  case 5:
		    printf("1.Input Restricted\t2.Output Restricted\n");
		    scanf("%d",&q);
		    break;
		  case 6:
		    break;
		  default:
		    printf("You've entered wrong option, please try again.........!\n");
		}
	  }
}
Ejemplo n.º 10
0
void rmque(qfmt *tail, qfmt *head)
   {
   while (tail->next != head)
      {
      deque(head);     /* empty out the FIFO queue node by node */
      } /* for each node in queue */
   free(head);
   free(tail);
   } /* rmque */
Ejemplo n.º 11
0
int main(){
	int z = 0;
	init();
	queue(3);
	queue(2);
	printf("%d\n", myqueue[0]);
	printf("%d\n", myqueue[1]);
	deque(&z);
	printf("%d\n", z);
}
Ejemplo n.º 12
0
void frchn(void *list, void *ch)
{
	STDITEM *freelist = (STDITEM *)list;
	STDITEM *chn = (STDITEM *)ch;
	STDITEM *i;

	if ((i = chn->link.prev) != chn) {
		deque(STDITEM, link, chn);
		splicef(STDITEM, link, freelist, i);
	}
}
Ejemplo n.º 13
0
Archivo: test.c Proyecto: shixv/test
int main(void)
{
	Queue* q=initQueue();
	enque(q,1);
	enque(q,2);
	printf("%d,",head(q));
	deque(q);
	printf("%d,",head(q));
	freeQueue(q);
	return 0;
}
Ejemplo n.º 14
0
int main() {
  DEBUG_PRINT("creating QUEUE");
  UIntQueue Q;
  DEBUG_PRINT("QUEUE created!");

  for (uint32_t rounds = 0; rounds < ROUNDS; ++rounds) {
    enque(Q);
    random_access(Q);
    deque(Q);
  }

  return 0;
}
Ejemplo n.º 15
0
// ready to send
static void readyToSend(void)
{
    if(length(&sendBuffer) > 0)
    {
        // send next byte
        LINDAT = deque(&sendBuffer);
        sending = 1;
    }
    else
    {
        // nothing to send
        sending = 0;
        LINSIR |= (1 << LTXOK);
    }
}
Ejemplo n.º 16
0
void doBFS(int v)
{
   enque(v);

   while(isQueEmpty() == 0)
   {
      int k = deque();

      if(visited[k] == 0)
      {
         printf("BFS visited %d \n",k);
         visited[k] = 1;
         addAdjacentNonVisitedVertexToQue(k);
      }
   }
}
Ejemplo n.º 17
0
int uyankpop(BW *bw)
{
	if (bw->b == yankbuf && bw->cursor->byte == yankwhere) {
		P *q;
		UNDOREC *ptr = yanked.link.prev;

		deque(UNDOREC, link, &yanked);
		enqueb(UNDOREC, link, ptr, &yanked);
		q = pdup(bw->cursor, "uyankpop");
		pbkwd(q, ptr->len);
		inyank = 1;
		bdel(q, bw->cursor);
		inyank = 0;
		prm(q);
		return uyank(bw);
	} else
		return uyank(bw);
}
Ejemplo n.º 18
0
void* warp_fun(void* arg){
    thread_t* th = (thread_t*)arg;
    task_t* task;
    struct list_head* list;
	
	debug_info("thread[%d] on ready\n",th->myid);
    sem_wait(&th->ready);
	debug_info("thread[%d] on start\n",th->myid);

    while(1){
	   	list = deque(&th->q);
		task = list_entry(list, task_t, link);
		debug_info("begin execute task[%lu], on thread[%d]\n", task->id, th->myid);
		task->rval = task->fun(task->arg);
		debug_info("complete execute task[%lu], on thread[%d]\n", task->id, th->myid);
		destroy_task(task);
   }
}
int main(void)
{
	board_init();												//Initialize the circuit board configurations
  	changeState(START);											//Initialize the state
  	enque(DIAGNOSTIC);											//first do diagnostic
  	//motorsInit();
  	//motorDir(CLOCKWISE);
  	
  	#ifdef SHOW_MESSAGES
	    hal_sendString_UART1("Machine started");
	    hal_sendChar_UART1('\n');
    #endif
  	
  	//INTEnableInterrupts();
  	//INTEnableSystemMultiVectoredInt();
  	
  	
  	SKPIC32_Init();
	SKPIC32_GLCDInit();
	SKPIC32_GLCDWriteText(0, 0, "Hello World!");
	SKPIC32_GLCDWriteText(0, 1, "This is SKPIC32!");
	SKPIC32_GLCDWriteText(0, 2, "1234567890");
	SKPIC32_GLCDWrite(0, 3, 0x31);
	DelayMs(2000);
	

  	while(1){
    	uint8 nextEvent = deque();								//get next event
    	if(nextEvent)
	    {
     		stateMachine(nextEvent);							//enter the event functions
    	}
  
    	if(keyuse ==(uint8)PRODUCT)								//check key press for product selection
     	{	    
     			keypad_pole();
     	}
     	else if(keyuse ==(uint8)AMOUNT)							//check key press for amount selection
     	{
     			keypad_pole();	
     	}	
  	}	
  	
}
Ejemplo n.º 20
0
double main( void )
{
	QueueNodePtr header = NULL, tail = NULL; // declare two pointer of Queue type

	double input;

	printf( "Enter a set of number, stop at -999\n" );

	while( scanf( "%lf", &input ) && input != -999 ) // scan an integer input while input not equal -999
	{
		enque( &header, &tail, input );
	}

	printf( "Output of the queue:\n" );

	while( header != NULL )
		printf( "%lf\n", deque( &header, &tail ) ); // output queue


	return 0;
}
Ejemplo n.º 21
0
static void process(FILE *is, FILE *os)
{
	struct aqueue queue;
	int ret;
	int i;

	xprintf(os, "\nEnque and Deque test with the simple array queue\n");
	xprintf(os, "================================================\n\n");

	init(&queue);
	i = 0;
	while ((ret = fgetc(is)) != EOF) {
		/* First get the queue operator. */
		if (isalpha(ret)) {
			xprintf(os, "%2d) ", ++i);
			if (tolower(ret) == 'e') {
				/* Enque operation. */
				fscanf(is, "%d", &ret);
				enque(&queue, ret);
				xprintf(os, "Enque %d", ret);
			} else if (tolower(ret) == 'd') {
				/* Deque operation. */
				ret = deque(&queue);
				if (ret == EOF)
					xprintf(os, "Deque underflow");
				else
					xprintf(os, "Deque %d", ret);
			}
			xprintf(os, ", and the current queue is: ");
			print(&queue, os);
			xprintf(os, "\n");
		}
	}

	xprintf(os, "\nFinal queue contents: ");
	print(&queue, os);
	xprintf(os, "\n");

	xprintf(os, "\nThank you!\n");
}
int main()
{
	int c,x,p;
	while(1)
{
	printf("1.enque\n2.deque\n3.display\n4.exit\n");
	scanf("%d",&c);
	switch(c)
	{
		case 1:	printf("enter element and priority: ");
				scanf("%d%d",&x,&p);
				enque(x,p);
				break;
		case 2: deque();
				break;
		case 3: display();
				break;
		case 4: goto end;
	}
}
end:;
}
Ejemplo n.º 23
0
int dijkstra(int src, int tar){

	int i,v;
	for(i = 0; i < N; i++) dist[i] = INF,visited[i] = 0;
	dist[src] = 0;
	par[src] = -1;

	while(1){
		v = deque();
		visited[v] = 1;
		if(v < 0) return INF;
		if(v == tar) return dist[v];

		for(i = 0; i < N; i++){
			if (dist[i] > dist[v]+adj[v][i]){
				dist[i] = dist[v] + adj[v][i];
				par[i] = v;
			}
		}
	}

	return INF;
}
Ejemplo n.º 24
0
int
binary_semaphore_up(int s_id)
{
	acquire(&list_lock);
	if(!is_legal_id(s_id) || !is_semaphore_init(s_id))
		return -1;
	
	struct binary_semaphore *s = &bsemaphores[s_id];
	
	acquire(&s->lock);
	
	void *p=0;
	if(deque(&s->waiting, &p)<0){
		// no waiting procs
		//cprintf("[unlk %d %d]", proc->pid, s_id);
		s->value=1;
		release(&s->lock);
		release(&list_lock);
		return 0;
	}
	
	if(((struct proc*) p)->tid == proc->tid){
		s->value=1;
		//cprintf("[self %d %d]", proc->pid, s_id);
		release(&s->lock);
		release(&list_lock);
		return binary_semaphore_up(s_id);
	}
	//release(&s->lock);
	s->value=0;
	//cprintf("[wake %d %d]", ((struct proc*) p)->pid, s_id);
	wakeup((struct proc*) p);
	release(&s->lock);
	release(&list_lock);
	return 0;
}
Ejemplo n.º 25
0
void cond_variable_signal(cond_variable * c)
{
	if (!q_is_empty(c->q)) {
		kill(deque(c->q), 1);
	}
}
Ejemplo n.º 26
0
void main()
{
	int i,j,a[11][11],b[11][11],c[11],d[11],p[11],u,v,k,x;
	for(i=1;i<11;i++)
		for(j=1;j<11;j++)
			a[i][j]=0;
	printf("\n\n  Enter how many nodes(0<n<11) :");
	scanf("%d",&n);
	printf("\n\n  Enter your edges(ex- u sp v)(press 'e' for end) : \n");
	for(i=1;i<=(n*n)/2;i++)
	{
		if(getchar()=='e')
			break;
		scanf("%d%d",&u,&v);
		a[u][v]=a[v][u]=1;
	}
	for(i=1;i<=n;i++)
	{
		k=1;
		for(j=1;j<=n;j++)
			if(a[i][j])
			{
				b[i][k]=j;
				k++;
			}
		b[i][k]=0;
	}
	printf("\n\n  Which vertex is the root : ");
	scanf("%d",&x);
	for(i=1;i<=n;i++)
	{
		c[i]=1;
		d[i]=25000;
		p[i]=0;
	}
	c[x]=2;
	d[x]=0;
	p[x]=0;
	enque(x);
	while(f!=n+1&&r!=n+1)
	{
		u=deque();
		for(i=1;b[u][i]!=0;i++)
		{
			v=b[u][i];
			if(c[v]==1)
			{
				c[v]=2;
				d[v]=d[u]+1;
				p[v]=u;
				enque(v);
			}
		}
		c[u]=3;
	}
	printf("\n\n  The vulues of vertice in BFS : \n\n");
	printf("\n  nodes  values\n\n");
	for(i=1;i<=n;i++)
		printf("\n%5d%5d",i,d[i]);
	printf("\n\n");
}
Ejemplo n.º 27
0
void JvDecoder::decompress()
{
	decompressing_ = 1;
	pbd_ = deque();
	start();
}
Ejemplo n.º 28
0
// **********************************************************************
// **********************************************************************
// scheduler
//
static int scheduler()
{
	int nextTask, i, j, childCount, percent, timeSlice;

	if( scheduler_mode == 0 ) {
		// Round Robin Scheduling
		nextTask = deque(rq, -1);

		if (nextTask >= 0)
		{
			enque(rq, nextTask, tcb[nextTask].priority);
		}
	}
	else {
		bool found = FALSE;
		// Fair Scheduling - look for non-zero task to schedule
		for(i=1; i <= rq[0]; i++) {
			if(tcb[rq[i]].time > 0) {
				nextTask = rq[i];
				tcb[rq[i]].time--;
				found = TRUE;
				break;
			}
		}

		if(! found) {
			// didn't find a task. All are 0. Loop through to find a possible parent
			for(i=1; i <= rq[0]; i++) {
				// Has this task already been alloted time this pass?
				if(tcb[rq[i]].time == 0) {
					// If not, lets check if it has any children
					childCount = 0;
					for(j=1; j <= rq[0]; j++) {
						if(tcb[rq[j]].parent == rq[i]) {
							childCount++;
						}
					}

					if((childCount == 0)) {
						//tcb[rq[i]].time = 1;
						continue;
					}

					// we've counted all the siblings
					percent = 100/NUM_PARENTS;
					timeSlice = percent / childCount;

					// Set sibling timeSlices
					for(j=1; j <= rq[0]; j++) {
						if(tcb[rq[j]].parent == rq[i]) {
							tcb[rq[j]].time = timeSlice;
						}
					}

					// set parent timeSlices
					tcb[rq[i]].time = percent % childCount;
				}
			}
			nextTask = rq[1]; // Give shell an occasional run
		}
	}

	if (tcb[nextTask].signal & mySIGSTOP) return -1;
	//printf("(%i)", nextTask);
	return nextTask;

} // end scheduler
Ejemplo n.º 29
0
void createBinaryTree(TreeNode **root)
{
  char c;
  int data;
  TreeNode *newNode=NULL,*parentNode = NULL;

  printf("\n Do you want insertion(Y/N) :");
  scanf(" %c",&c);
  //  c=getchar();
  
  if(c=='Y')
    {

      parentNode = deque();
      
      if( parentNode == NULL )
	{
	  printf("\n Enter data of root of tree :");
	  scanf("%d",&data);
	  newNode = (TreeNode *)malloc(sizeof(TreeNode));
	  newNode -> data = data ;
	  newNode -> leftChild = NULL;
	  newNode -> rightChild = NULL ;
	  (*root)= newNode ;
	  enque(newNode);
	  createBinaryTree(&*root);
	  return;
	}
      
      printf("\n Enter left child of parent %d . (If NULL enter -1) :",parentNode -> data);
      scanf("%d",&data);
      
      if(data != -1)
	{
	  newNode = (TreeNode *)malloc(sizeof(TreeNode));
	  newNode -> data = data ;
	  newNode -> leftChild = NULL;
	  newNode -> rightChild = NULL ;
	  parentNode -> leftChild = newNode ;
	  enque(newNode);
	}

      printf("\n Enter right child of parent %d . (If NULL enter -1) :",parentNode -> data);
      scanf("%d",&data);
      
      if(data != -1)
	{
	  newNode = (TreeNode *)malloc(sizeof(TreeNode));
	  newNode -> data = data ;
	  newNode -> leftChild = NULL;
	  newNode -> rightChild = NULL ;
	  parentNode -> rightChild = newNode ;
	  enque(newNode);
	}

      createBinaryTree(&*root);
      return;
    }

  else if(c=='N')
    {
      printf("Thank You.............. \n");
      return;
      // exit(0) ;
    }

  else
    {
      printf("\nWrong input .");
      createBinaryTree(&*root);
    }
  return;
}
Ejemplo n.º 30
0
void* asyncWrite(void* parameters)
{
    pdebug("asyncWrite()\n");
    writeParams* params = parameters;
    int64_t write = openForWrite(params->temp_file_name);

    if(write < 0)
    {
        pdebug("Error opening file for write\n");
        *(params->error) = FILE_IO_FAIL;

        return NULL;
    }

    chunk* write_chunk = NULL;
    uint64_t bytes_written = 0;
    uint64_t bytes_to_write = 0;
    uint64_t write_progress = 0;

    while(*(params->running) && *(params->error) == 0)
    {
        if(write_chunk == NULL) //Get a chunk from the queue
        {
            pthread_mutex_lock(params->mutex);
            if(front(params->in) != NULL)
            {
                write_chunk = front(params->in);
                if(write_chunk != NULL) { deque(params->in); }
            }
            pthread_mutex_unlock(params->mutex);
        }

        //check for termination conditions
        if((write_chunk != NULL && write_chunk->action == DONE) || 
            ((params->file_size) != NULL &&
            *(params->valid) && 
            bytes_written >= *(params->file_size))) 
            //size constraints
        {
            pdebug("^^^^ AsyncWrite() terminating loop ^^^^\n");
            destroyChunk(write_chunk);
            break;
        }

        if(write_chunk != NULL && write_chunk->data != NULL)
        {
            //ensure we aren't writing padding or attack attempts
            if(params->file_size == NULL) { bytes_to_write = write_chunk->data_size; }
            else if(bytes_written + write_chunk->data_size > *(params->file_size))
            { bytes_to_write = *(params->file_size) - bytes_written; }
            else { bytes_to_write = write_chunk->data_size; }

            write_progress += write_chunk->data_size;

            if(!writeBytes((uint8_t*)write_chunk->data, bytes_to_write, write))
            {
                pdebug("^^^^ File I/O Error ^^^^\n");
                *(params->error) = FILE_IO_FAIL;
		        close(write);
                break;
            }
            
            ///write it to the file
            pdebug("^^^^ Writing a chunk of size %lu ^^^^\n", bytes_to_write);
            bytes_written += bytes_to_write;
            destroyChunk(write_chunk); //free the chunk
            write_chunk = NULL; 
        }
        
        if(write_progress > 0) //update the progress bar
	    {
	        if(pthread_mutex_trylock(params->progress->progress_mutex) == 0)
	        {
	            params->progress->progress += write_progress;
		        write_progress = 0;
		        pthread_mutex_unlock(params->progress->progress_mutex);
	        }
	    }	
    }
    
    close(write);

    if(*(params->error) == 0)
    {
        if(params->args->rename) //change the output file to what the user wanted
        { rename((char*)params->temp_file_name, (char*)params->args->rename_file); }
        else //rename the temp file to the original file name (replaces file)
        { rename((char*)params->temp_file_name, (char*)params->args->target_file); }

        //signal any other running threads to stop (in case they are stuck)
        *(params->running) = false;
    }
    
    pdebug("^^^^ writeThread Done ^^^^\n");
    //we are done
    return NULL;  
}