Example #1
0
void Semaphore_wait( ISemaphore* self )
{
	Mutex_lock( self->mutex );
	{
		while ( self->value <= 0 ) {
			ConditionVariable_wait( self->cv, self->mutex );
		}
		self->value -= 1;
	}
	Mutex_unlock( self->mutex );
}
void _p(const char * s,byte * d, uint ld, uint w) {
  if (!_screen_m) {
     _screen_m = Mutex_new(0);
  }
  
  Mutex_lock ( _screen_m );
  printf(" - - - [%s] - - -\n",s);
  dump_data_as_hex(d,ld,w);  
  printf(" - - - - - - - - \n");
  Mutex_unlock(_screen_m);
}
Example #3
0
// Handle Windows API ReadFile
static
retval __read(HANDLE hFile, byte * buf, uint lbuf) {
  uint bytes_read = 0;
  retval res = {0};
  Mutex_lock(_static_lock);
 
  ReadFile(hFile, buf, lbuf, &bytes_read, NULL);
  res.rval = bytes_read;
  res.err = GetLastError();
  SetLastError(0);

  Mutex_unlock(_static_lock);
  return res;
}
/**
 * Sets the indicator which determines whether noise suppression is to be
 * performed by the specified <tt>AudioQualityImprovement</tt> (for captured
 * audio).
 *
 * @param aqi the <tt>AudioQualityImprovement</tt> on which to set the indicator
 * which determines whether it is to perform noise suppression (for captured audio)
 * @param denoise <tt>JNI_TRUE</tt> if the specified <tt>aqi</tt> is to perform
 * noise suppression (for captured audio); otherwise, <tt>JNI_FALSE</tt>
 */
void
AudioQualityImprovement_setDenoise
    (AudioQualityImprovement *aqi, jboolean denoise)
{
    if (!Mutex_lock(aqi->mutex))
    {
        if (aqi->denoise != denoise)
        {
            aqi->denoise = denoise;
            AudioQualityImprovement_updatePreprocess(aqi);
        }
        Mutex_unlock(aqi->mutex);
    }
}
Example #5
0
// Handle Windows API WriteFile
static
retval __write(HANDLE hFile, byte * buf, uint lbuf) {
	uint bytes_written = 0;
  retval res = {0};
  Mutex_lock(_static_lock);

  // https://msdn.microsoft.com/en-us/library/windows/desktop/aa365747%28v=vs.85%29.aspx	
  WriteFile(hFile, buf, lbuf,&bytes_written, NULL);
  res.err = GetLastError(); SetLastError(0);
  res.rval = bytes_written;

  Mutex_unlock(_static_lock);
  return res;
}
void
AudioQualityImprovement_setSampleRate
    (AudioQualityImprovement *aqi, int sampleRate)
{
    if (!Mutex_lock(aqi->mutex))
    {
        if (aqi->sampleRate != sampleRate)
        {
            aqi->sampleRate = sampleRate;
            AudioQualityImprovement_updatePlayDelay(aqi);
            AudioQualityImprovement_updatePreprocess(aqi);
        }
        Mutex_unlock(aqi->mutex);
    }
}
/**
 * Sets the filter length in milliseconds of the echo cancellation
 * implementation of the specified <tt>AudioQualityImprovement</tt>. The
 * recommended filter length is approximately the third of the room
 * reverberation time. For example, in a small room, reverberation time is in
 * the order of 300 ms, so a filter length of 100 ms is a good choice (800
 * samples at 8000 Hz sampling rate).
 *
 * @param aqi the <tt>AudioQualityImprovement</tt> to set the filter length of
 * @param echoFilterLengthInMillis the filter length in milliseconds of the echo
 * cancellation of <tt>aqi</tt>
 */
void
AudioQualityImprovement_setEchoFilterLengthInMillis
    (AudioQualityImprovement *aqi, jlong echoFilterLengthInMillis)
{
    if (echoFilterLengthInMillis < 0)
        echoFilterLengthInMillis = 0;
    if (!Mutex_lock(aqi->mutex))
    {
        if (aqi->echoFilterLengthInMillis != echoFilterLengthInMillis)
        {
            aqi->echoFilterLengthInMillis = echoFilterLengthInMillis;
            AudioQualityImprovement_updatePreprocess(aqi);
        }
        Mutex_unlock(aqi->mutex);
    }
}
Example #8
0
File: crawler.c Project: wkfunk/cs
void *downloader(void *arg) {
  //printf("***downloader started!\n");

  // loop forever
  while(1) {

    Mutex_lock(&l_m);
    while(link_count == 0) {
      //printf("***downloader waiting!\n");
      // wait
      Cond_wait(&l_fill, &l_m);
    }
    // make a new pointer to the top of the stack
    node *next = links;
    // pop the top of the stack (will need to free the node and the string later)
    links = pop(links);
    link_count--;

    printf("POP link: %s\n", next->link);
    printf("--> link_count: %d\n", link_count);
    printf("--> page_count: %d\n", page_count);

    // signal links empty
    Cond_signal(&l_empty);
    Mutex_unlock(&l_m);

    // do actual processing
    download(next);

    // free node
    free(next->link);
    free(next);

    //Mutex_lock(&l_m);
    //link_count--;
    //Mutex_unlock(&l_m);
  
  }

  return 0;
}
Example #9
0
void mutexUnlock(PCB_p pcb, Mutex_p mutex) {
    int error;

    printf("PID %lu: requested unlock on mutex M%lu - ", pcb->PID, mutex->ID);

    if (Mutex_unlock(mutex, pcb)) {
        // The mutex unlock succeeded. Resume process operation.
        printf("succeeded\n");
        pcb->state = running;
    } else {
        // The mutex unlock has failed.
        printf("blocked by PID %lu\n", mutex->key->PID);
        // The process has now been enqueued in the mutex queue, and will get the lock (and thus unlock) when it is its turn.
        // So enqueue PCB back into the ready queue and run the scheduler to dispatch the next process.
        // TODO: Move the enqueue into the scheduler.
        current_pcb->state = waiting;
        current_pcb->PC--;  // Decrement so that the PCB will try to unlock again next time it's run.
        PriorityQ_enqueue(ready_PCBs, current_pcb, &error);
        runScheduler(
                trap_interrupt);   // Current process has been blocked, run scheduler to dispatch the next one.
    }
}
Example #10
0
                        /* trigger reload of spread configuration */
                        Reload_Conf();
                        printf("Reload Membership. \n");

                        break;
		case '9':
		case 'q':
			printf("Bye.\n");
			exit( 0 );

			break;

		default:
			printf("\nUnknown commnad\n");
			Print_menu();

			break;
	}
}

static	void	Print_menu()
{
	printf("\n");
	printf("=============\n");
	printf("Monitor Menu:\n");
	printf("-------------\n");
	printf("\t0. Activate/Deactivate Status {all, none, Proc, CR}\n");
	printf("\n");
	printf("\t1. Define Partition\n");
	printf("\t2. Send   Partition\n");
	printf("\t3. Review Partition\n");
	printf("\t4. Cancel Partition Effects\n");
	printf("\n");
	printf("\t5. Define Flow Control\n");
	printf("\t6. Send   Flow Control\n");
	printf("\t7. Review Flow Control\n");
	printf("\n");
	printf("\t8. Terminate Spread Daemons {all, none, Proc, CR}\n");
	printf("\n");
	printf("\tr. Reload Configuration File\n");
	printf("\n");
	printf("\t9. Exit\n");
	printf("\n");
	printf("Monitor> ");
	fflush(stdout);
}

static	void	Print_partition( int16 partition[MAX_PROCS_RING] )
{
	int32	proc_id;
	proc	p;
	int	proc_index;
	int	i,j;

	printf("\n");
	printf("=============\n");
	printf("Partition Map:\n");
	printf("-------------\n");

	printf("\n");
	for( i=0; i < Cn.num_segments ; i++ )
	{
	    for( j=0; j < Cn.segments[i].num_procs; j++ )
	    {
		proc_id = Cn.segments[i].procs[j]->id;
		proc_index = Conf_proc_by_id( proc_id, &p );
		printf("\t%s\t%d\n", p.name, partition[proc_index] );
	    }
	    printf("\n");
	}
	printf("\n");
	printf("Monitor> ");
	fflush(stdout);
}

static	void	Define_partition()
{
	int32	proc_id;
	proc	p;
	int	proc_index;
	char	str[80];
	int	legal,ret,temp;
	int	i,j;

	printf("\n");
	printf("=============\n");
	printf("Define Partition\n");
	printf("-------------\n");

	printf("\n");
	for( i=0; i < Cn.num_segments ; i++ )
	{
	    for( j=0; j < Cn.segments[i].num_procs; j++ )
	    {
		proc_id = Cn.segments[i].procs[j]->id;
		proc_index = Conf_proc_by_id( proc_id, &p );
		for( legal=0; !legal; )
		{
		    printf("\t%s\t", p.name);

		    if( fgets( str, 70, stdin ) == NULL )
		    {
			printf("Bye.\n");
			exit(0);
		    }
		    ret = sscanf(str, "%d", &temp );
		    Work_partition[proc_index] = temp;
		    if( ret > 0 ) legal = 1;
		    else printf("Please enter a number\n");
		}
	    }
	    printf("\n");
	}
}

static	void	Send_partition()
{
	int32	proc_id;
	proc	p;
	int	proc_index;
	int	i,j;

	Pack.type    = PARTITION_TYPE;
	Pack.type    = Set_endian( Pack.type );
        Pack.conf_hash = MONITOR_HASH;
	Pack.data_len= sizeof( Partition );;

	Pack_scat.num_elements    = 2;
	Pack_scat.elements[1].len = sizeof( Partition );
	Pack_scat.elements[1].buf = (char *)&Partition;

	Alarm( PRINT  , "Monitor: send partition\n");
	for( i=0; i < Cn.num_segments ; i++ )
	{
	    for( j=0; j < Cn.segments[i].num_procs; j++ )
	    {
		proc_id = Cn.segments[i].procs[j]->id;
		proc_index = Conf_proc_by_id( proc_id, &p );
		DL_send( SendChan, p.id, p.port, &Pack_scat );
		DL_send( SendChan, p.id, p.port, &Pack_scat );
	    }
	}
#ifndef _REENTRANT
	E_queue( Send_partition, 0, NULL, Send_partition_timeout );
#endif
}

#ifdef	_REENTRANT

#ifndef 	ARCH_PC_WIN95
static	void	*Partition_send_thread_routine()
#else		/* ARCH_PC_WIN95 */
static	DWORD WINAPI    Partition_send_thread_routine( void *dummy)
#endif		/* ARCH_PC_WIN95 */
{
    sp_time onesecond_time = { 1, 0};
    sp_time send_interval;
    int active_p;

    for(;;)
    {
        Mutex_lock( &Partition_mutex );
        active_p = Partition_active;
        send_interval = Send_partition_timeout;
        Mutex_unlock( &Partition_mutex );
        if (active_p) {
            Send_partition();

            E_delay(send_interval); 
        } else {
            E_delay(onesecond_time);
        }
    }
    return( 0 );
}

#endif	/* _REENTRANT */

static	void	Print_flow_control( int16 fc_buf[MAX_PROCS_RING][2] )
{
	int32	proc_id;
	proc	p;
	int	proc_index;
	int	i,j;

	printf("\n");
	printf("========================\n");
	printf("Flow Control Parameters:\n");
	printf("------------------------\n");
	printf("\n");
	printf("Window size:  %d\n",fc_buf[ Conf_num_procs( &Cn )][0]);
	printf("\n");
	for( i=0; i < Cn.num_segments ; i++ )
	{
	    for( j=0; j < Cn.segments[i].num_procs; j++ )
	    {
		proc_id = Cn.segments[i].procs[j]->id;
		proc_index = Conf_proc_by_id( proc_id, &p );
		printf("\t%s personal window\t%d\n", p.name, fc_buf[proc_index][0] );

		if (Conf_get_accelerated_ring()) {
		  printf("\t%s accelerated window\t%d\n", p.name, fc_buf[proc_index][1] );
		}
	    }
	    printf("\n");
	}
	printf("\n");
	printf("Monitor> ");
	fflush(stdout);
}

static	void	Define_flow_control()
{
	int32	proc_id;
	proc	p;
	int	proc_index;
	char	str[80];
	int	legal,ret,temp;
	int	i,j;

	printf("\n");
	printf("===================\n");
	printf("Define Flow Control\n");
	printf("-------------------\n");

	printf("\n");
	for( legal=0; !legal; )
	{
	    printf("    Window size: ");

	    if( fgets( str,70,stdin ) == NULL )
	    {
		printf("Bye.\n");
		exit(0);
	    }
	    ret = sscanf(str, "%d", &temp );
	    Work_fc_buf[Conf_num_procs( &Cn )][0] = temp;
	    if( ret > 0 ) legal = 1;
	    else if( ret == -1 ){
		legal = 1;
		Work_fc_buf[Conf_num_procs( &Cn )][0] = -1;
	    }else printf("Please enter a number\n");
	}
	printf("\n");
	for( i=0; i < Cn.num_segments ; i++ )
	{
	    for( j=0; j < Cn.segments[i].num_procs; j++ )
	    {
		proc_id = Cn.segments[i].procs[j]->id;
		proc_index = Conf_proc_by_id( proc_id, &p );
		for( legal=0; !legal; )
		{
		    printf("\t%s personal window\t", p.name);

		    if( fgets( str, 70, stdin ) == NULL )
		    {
			printf("Bye.\n");
			exit(0);
		    }
		    ret = sscanf(str, "%d", &temp);
		    Work_fc_buf[proc_index][0] = temp;
		    if( ret > 0 ) legal = 1;
		    else if( ret == -1 ){
			legal = 1;
			Work_fc_buf[proc_index][0] = -1;
		    }else printf("Please enter a number\n");
		}

		if (Conf_get_accelerated_ring()) {

		  for( legal=0; !legal; )
		    {
		      printf("\t%s accelerated window\t", p.name);

		      if( fgets( str, 70, stdin ) == NULL )
			{
			  printf("Bye.\n");
			  exit(0);
			}
		      ret = sscanf(str, "%d", &temp);
		      Work_fc_buf[proc_index][1] = temp;
		      if( ret > 0 ) legal = 1;
		      else if( ret == -1 ){
			legal = 1;
			Work_fc_buf[proc_index][1] = -1;
		      }else printf("Please enter a number\n");
		    }
		}
	    }
	    printf("\n");
	}
}

static	void	Send_flow_control()
{
	int32	proc_id;
	proc	p;
	int	proc_index;
	int	i,j;

	Pack.type    = FC_TYPE;
	Pack.type    = Set_endian( Pack.type );
        Pack.conf_hash = MONITOR_HASH;
	Pack.data_len= sizeof( Fc_buf );;

	Pack_scat.num_elements    = 2;
	Pack_scat.elements[1].len = sizeof( Fc_buf );
	Pack_scat.elements[1].buf = (char *)&Fc_buf;

	Alarm( PRINT  , "Monitor: send flow control params\n");
	for( i=0; i < Cn.num_segments ; i++ )
	{
	    for( j=0; j < Cn.segments[i].num_procs; j++ )
	    {
		proc_id = Cn.segments[i].procs[j]->id;
		proc_index = Conf_proc_by_id( proc_id, &p );
		DL_send( SendChan, p.id, p.port, &Pack_scat );
		DL_send( SendChan, p.id, p.port, &Pack_scat );
	    }
	}
}

static	void	Activate_status()
{
	proc	p;
	int	proc_index;
	char	str[80];
	int	legal,ret;
	int	i;
	int	end;

	printf("\n");
	printf("=============\n");
	printf("Activate Status\n");
	printf("-------------\n");

	printf("\n");

	end = 0;
	while( !end )
	{
		for( legal=0; !legal; )
		{
		    printf("\tEnter Proc Name: ");

		    if( fgets( str, 70, stdin ) == NULL )
		    {
			printf("Bye.\n");
			exit(0);
		    }
		    ret = sscanf(str, "%s", p.name );
		    if( ret > 0  || str[0] == '\n' ) legal = 1;
		    else printf("Please enter a legal proc name, none, or all\n");
		}
		if( str[0] == '\n' ){
			end = 1;
		}else if( !strcmp( p.name, "all" ) ){
			for( i=0; i < Conf_num_procs( &Cn ); i++ )
				Status_vector[i] = 1;
		}else if( !strcmp( p.name, "none" ) ){
			for( i=0; i < Conf_num_procs( &Cn ); i++ )
				Status_vector[i] = 0;
		}else{
			proc_index = Conf_proc_by_name( p.name, &p );
			if( proc_index != -1 ){
				Status_vector[proc_index] = 1;
			}else printf("Please! enter a legal proc name, none, or all\n");
		}
	}
#ifndef _REENTRANT
	E_dequeue( Send_status_query, 0, NULL );
#endif
        Mutex_lock( &Status_mutex );
        Status_active = 0;
	for( i=0; i < Conf_num_procs( &Cn ); i++ )
	{
		if( Status_vector[i] )
		{
                    Status_active = 1;
			break;
		}
	}
        Mutex_unlock( &Status_mutex );
#ifndef _REENTRANT
        if (Status_active)
            Send_status_query();
#endif
}

static	void 	Send_status_query()
{

	int32	proc_id;
	proc	p;
	int	proc_index;
	int	i,j;

	Pack.type    = STATUS_TYPE;
	Pack.type    = Set_endian( Pack.type );
        Pack.conf_hash = MONITOR_HASH;
	Pack.data_len= 0;

	Pack_scat.num_elements    = 1;

	Alarm( PRINT  , "Monitor: send status query\n");
	for( i=0; i < Cn.num_segments ; i++ )
	{
	    for( j=0; j < Cn.segments[i].num_procs; j++ )
	    {
		proc_id = Cn.segments[i].procs[j]->id;
		proc_index = Conf_proc_by_id( proc_id, &p );
		if( Status_vector[proc_index] )
		{
			DL_send( SendChan, p.id, p.port, &Pack_scat );
		}
	    }
	}
#ifndef _REENTRANT
	E_queue( Send_status_query, 0, NULL, Send_status_timeout );
#endif
}

#ifdef	_REENTRANT

#ifndef 	ARCH_PC_WIN95
static	void	*Status_send_thread_routine()
#else		/* ARCH_PC_WIN95 */
static	DWORD WINAPI    Status_send_thread_routine( void *dummy)
#endif		/* ARCH_PC_WIN95 */
{
    sp_time onesecond_time = { 1, 0};
    sp_time send_interval;
    int active_p;

    for(;;)
    {
        Mutex_lock( &Status_mutex );
        active_p = Status_active;
        send_interval = Send_status_timeout;
        Mutex_unlock( &Status_mutex );
        if (active_p) {
            Send_status_query();

            E_delay(send_interval); 
        } else {
            E_delay(onesecond_time);
        }
    }
    return( 0 );
}
AudioQualityImprovement *
AudioQualityImprovement_getSharedInstance(const char *stringID, jlong longID)
{
    AudioQualityImprovement *theSharedInstance = NULL;

    if (!Mutex_lock(AudioQualityImprovement_sharedInstancesMutex))
    {
        AudioQualityImprovement *aSharedInstance
            = AudioQualityImprovement_sharedInstances;

        while (aSharedInstance)
        {
            if ((aSharedInstance->longID == longID)
                    && ((aSharedInstance->stringID == stringID)
                        || (0 == strcmp(aSharedInstance->stringID, stringID))))
            {
                theSharedInstance = aSharedInstance;
                break;
            }
            aSharedInstance = aSharedInstance->next;
        }
        if (theSharedInstance)
            AudioQualityImprovement_retain(theSharedInstance);
        else
        {
            theSharedInstance
                = AudioQualityImprovement_new(
                    stringID,
                    longID,
                    AudioQualityImprovement_sharedInstances);
            if (theSharedInstance)
                AudioQualityImprovement_sharedInstances = theSharedInstance;
        }
        Mutex_unlock(AudioQualityImprovement_sharedInstancesMutex);
    }
    return theSharedInstance;
}
Example #12
0
static	void	Activate_status()
{
	proc	p;
	int	proc_index;
	char	str[80];
	int	legal,ret;
	int	i;
	int	end;

	printf("\n");
	printf("=============\n");
	printf("Activate Status\n");
	printf("-------------\n");

	printf("\n");

	end = 0;
	while( !end )
	{
		for( legal=0; !legal; )
		{
		    printf("\tEnter Proc Name: ");

		    if( fgets( str, 70, stdin ) == NULL )
		    {
			printf("Bye.\n");
			exit(0);
		    }
		    ret = sscanf(str, "%s", p.name );
		    if( ret > 0  || str[0] == '\n' ) legal = 1;
		    else printf("Please enter a legal proc name, none, or all\n");
		}
		if( str[0] == '\n' ){
			end = 1;
		}else if( !strcmp( p.name, "all" ) ){
			for( i=0; i < Conf_num_procs( &Cn ); i++ )
				Status_vector[i] = 1;
		}else if( !strcmp( p.name, "none" ) ){
			for( i=0; i < Conf_num_procs( &Cn ); i++ )
				Status_vector[i] = 0;
		}else{
			proc_index = Conf_proc_by_name( p.name, &p );
			if( proc_index != -1 ){
				Status_vector[proc_index] = 1;
			}else printf("Please! enter a legal proc name, none, or all\n");
		}
	}
#ifndef _REENTRANT
	E_dequeue( Send_status_query, 0, NULL );
#endif
        Mutex_lock( &Status_mutex );
        Status_active = 0;
	for( i=0; i < Conf_num_procs( &Cn ); i++ )
	{
		if( Status_vector[i] )
		{
                    Status_active = 1;
			break;
		}
	}
        Mutex_unlock( &Status_mutex );
#ifndef _REENTRANT
        if (Status_active)
            Send_status_query();
#endif
}
Example #13
0
static	void	User_command()
{
	char	command[80];
	int	i;

	if( fgets( command,70,stdin ) == NULL )
	{
		printf("Bye.\n");
		exit( 0 );
	}

	switch( command[0] )
	{
		case '0':
			Activate_status();

			printf("\n");
			printf("Monitor> ");
			fflush(stdout);

			break;

		case '1':
			Define_partition();
			Print_partition( Work_partition );

			break;

		case '2':
			for( i=0; i < Conf_num_procs( &Cn ); i++ )
				Partition[i] = Work_partition[i];
                        Mutex_lock( &Partition_mutex );
                        Partition_active = 1;
                        Mutex_unlock( &Partition_mutex );
#ifndef _REENTRANT
			Send_partition();
#endif

			printf("\n");
			printf("Monitor> ");
			fflush(stdout);

			break;

		case '3':
			Print_partition( Partition );

			break;

		case '4':
			for( i=0; i < Conf_num_procs( &Cn ); i++ )
			{
				Partition[i] = 0;
				Work_partition[i] = 0;
			}
                        Mutex_lock( &Partition_mutex );
                        Partition_active = 0;
                        Mutex_unlock( &Partition_mutex );

			Send_partition();
#ifndef _REENTRANT
			E_dequeue( Send_partition, 0, NULL );
#endif
			printf("\n");
			printf("Monitor> ");
			fflush(stdout);

			break;

		case '5':
			Define_flow_control();
			Print_flow_control( Work_fc_buf );

			break;

		case '6':
		        for( i=0; i < Conf_num_procs( &Cn )+1; i++ ) {
				Fc_buf[i][0] = Work_fc_buf[i][0];
				Fc_buf[i][1] = Work_fc_buf[i][1];
			}
			Send_flow_control();

			printf("\n");
			printf("Monitor> ");
			fflush(stdout);

			break;

		case '7':
			Print_flow_control( Fc_buf );

			break;

		case '8':
			Kill_spreads();

			printf("\n");
			printf("Monitor> ");
			fflush(stdout);

			break;

                case 'r':
                        /* trigger reload of spread configuration */
                        Reload_Conf();
                        printf("Reload Membership. \n");

                        break;
		case '9':
		case 'q':
			printf("Bye.\n");
			exit( 0 );

			break;

		default:
			printf("\nUnknown commnad\n");
			Print_menu();

			break;
	}
}
Example #14
0
/* Send message to all daemons to reload their configuration files to change the set of daemons */
static  void    Reload_Conf()
{
       	int32	proc_id;
	proc	p;
	int	proc_index;
	int	i,j;

	Pack.type    = RELOAD_TYPE;
	Pack.type    = Set_endian( Pack.type );
        Pack.conf_hash = MONITOR_HASH;
	Pack.data_len = 0;

	Pack_scat.num_elements    = 1;

        Alarm( PRINT, "Old configuration hash is: %u\n", Cn.hash_code);

	Alarm( PRINT  , "Monitor: send conf reload command\n");
	for( i=0; i < Cn.num_segments ; i++ )
	{
	    for( j=0; j < Cn.segments[i].num_procs; j++ )
	    {
		proc_id = Cn.segments[i].procs[j]->id;
		proc_index = Conf_proc_by_id( proc_id, &p );
		DL_send( SendChan, p.id, p.port, &Pack_scat );
	    }
	}
        /* Now reload monitor's configuration 
         * and clear all Partition, Status, FC arrays as they are now inaccurate
         */

        read_configuration();

        for( i=0; i < Conf_num_procs( &Cn ); i++ )
	{
            Partition[i] = 0;
            Work_partition[i] = 0;
            Fc_buf[i][0] = 0;
            Fc_buf[i][1] = 0;
            Work_fc_buf[i][0] = 0;
            Work_fc_buf[i][1] = 0;
            Status_vector[i] = 0;
	}
        Mutex_lock( &Partition_mutex );
        Partition_active = 0;
        Mutex_unlock( &Partition_mutex );
        
#ifndef _REENTRANT
        E_dequeue( Send_partition, 0, NULL );
#endif

        Mutex_lock( &Status_mutex );
        Status_active = 0;
        Mutex_unlock( &Status_mutex );

#ifndef _REENTRANT
	E_dequeue( Send_status_query, 0, NULL );
#endif

        Alarm( PRINT, "New configuration hash is: %u\n", Cn.hash_code);
        Alarm( PRINT, "All Status, Partition, FC, etc commands are reset by configuration reload!\n");

}
Example #15
0
// Removes all instances of the passed pcbs in the waiting list and the key. Useful for process termination.
void Mutex_remove(Mutex_p mut, PCB_p pcb) {
    int error = 0;
    Mutex_unlock(mut, pcb);
    FIFOq_remove(mut->wait, pcb, &error);
}
/**
 *
 * @param aqi
 * @param sampleOrigin
 * @param sampleRate
 * @param sampleSizeInBits
 * @param channels
 * @param latency the latency of the stream associated with <tt>buffer</tt> in
 * milliseconds
 * @param buffer
 * @param length the length of <tt>buffer</tt> in bytes
 */
void
AudioQualityImprovement_process
    (AudioQualityImprovement *aqi,
    AudioQualityImprovementSampleOrigin sampleOrigin,
    double sampleRate, unsigned long sampleSizeInBits, int channels,
    jlong latency,
    void *buffer, unsigned long length)
{
    if ((sampleSizeInBits == 16) && (channels == 1) && !Mutex_lock(aqi->mutex))
    {
        switch (sampleOrigin)
        {
        case AUDIO_QUALITY_IMPROVEMENT_SAMPLE_ORIGIN_INPUT:
            if (sampleRate == aqi->sampleRate)
            {
                AudioQualityImprovement_setFrameSize(aqi, length);
                if (aqi->preprocess)
                {
                    float spl;
                    jboolean suppressEcho;

                    AudioQualityImprovement_setInputLatency(aqi, latency);

                    if (aqi->echo && aqi->play && aqi->playLength)
                    {
                        spl
                            = AudioQualityImprovement_cancelEchoFromPlay(
                                aqi,
                                buffer, length);
                        suppressEcho = aqi->suppressEcho;
                    }
                    else
                    {
                        spl = 0;
                        /*
                         * Let the echo suppression fade out if it's enabled and
                         * there hasn't been recent playback.
                         */
                        suppressEcho
                            = (aqi->suppressEcho && !(aqi->playLength))
                                ? JNI_TRUE
                                : JNI_FALSE;
                    }

                    speex_preprocess_run(aqi->preprocess, buffer);

                    if (JNI_TRUE == suppressEcho)
                        AudioQualityImprovement_suppressEcho(
                            aqi,
                            buffer, length / sizeof(spx_int16_t),
                            spl);
                }
            }
            break;

        case AUDIO_QUALITY_IMPROVEMENT_SAMPLE_ORIGIN_OUTPUT:
            if (aqi->preprocess && aqi->echo)
            {
                AudioQualityImprovement_setOutputLatency(aqi, latency);
                AudioQualityImprovement_resampleInPlay(
                    aqi,
                    sampleRate, sampleSizeInBits, channels,
                    buffer, length);
            }
            break;
        }
        Mutex_unlock(aqi->mutex);
    }
}
Example #17
0
File: crawler.c Project: wkfunk/cs
void do_tokenizing(char *orig, char *source) {
  //printf("***tokenizing...\n------------------------\n%s\n----------------------\n", orig);
  char *str = strdup(orig);

  char *curr, *new_str, *word;
  char *saveptr1, *saveptr2;


  while( (curr = strstr(str, "link:")) != NULL) {
    new_str = strdup(curr+1);

    if(curr == str || (curr > str && is_blank_space(*(curr-1)))) {

      curr = strtok_r(curr, " \n", &saveptr1);
      assert(curr != NULL);

      word = strtok_r(curr, ":", &saveptr2);
      word = strtok_r(NULL, ":", &saveptr2);

      //printf("found word: %s\n", word);
      assert(word != NULL);

      edge_fn(source, word);

      // check hash set and, if not present, add
      // link producer
      Mutex_lock(&l_m);
      while(link_count == max_link) {
	// wait
	Cond_wait(&l_empty, &l_m);
      }
    
      if(!contains(table, word)) {
	// do pushing
	printf("PUSH link: %s\n", word);
	links = push(NULL, strdup(word), links);
	link_count++;
      
	Mutex_lock(&done_m);
	total_work++;
	Mutex_unlock(&done_m);

	printf("--> new link_count: %d\n", link_count);
	printf("--> curr page_count: %d\n", page_count);
	// update table
	add(table, word);
      }
    
      Cond_signal(&l_fill);
      Mutex_unlock(&l_m);

    }

    free(str);
    str = new_str;
  }

  free(str);

  return;
}
Example #18
0
File: crawler.c Project: wkfunk/cs
void *parser(void *arg) {
/*
 * 1) queue of links (parsers to downloaders): first, push start_url onto queue
 *  - fixed-size
 *  - parsers push links on, wait when full (need cv)
 *  - downloader wait when empty (need cv)
 *  - need mutex
 */

  while(1) {

    //printf("***parser started!\n");

    Mutex_lock(&p_m);
    while(page_count == 0) {
      //printf("***parser waiting!\n");
      // wait
      Cond_wait(&p_fill, &p_m);
    }
    // make a new pointer to the top of the stack
    node *next = pages;
    // pop the top of the stack (will need to free the node and the string later)
    pages = pop(pages);
    page_count--;
    printf("POP page: %s\n", next->link);
    printf("--> new link_count: %d\n", link_count);
    printf("--> curr page_count: %d\n", page_count);


    // signal pages empty: may not need to do this since nobody will be waiting on
    // pages to be reduced in size (unbounded)
    // Cond_signal(&p_empty);
    Mutex_unlock(&p_m);

    // do actual processing
    parse(next);

    // free node
    free(next->str);
    free(next->link);
    free(next);

    //Mutex_lock(&p_m);
    //page_count--;
    //Mutex_unlock(&p_m);

    //Mutex_lock(&p_m);
    //Mutex_lock(&l_m);
    Mutex_lock(&done_m);
    total_work--;

    printf("link count: %d\npage count: %d\n", link_count, page_count);
    //if(page_count == 0 && link_count == 0) {
    if(total_work == 0) {
      //done = 1;
      Cond_signal(&done_cv);
    }

    Mutex_unlock(&done_m);
    //Mutex_unlock(&l_m);
    //Mutex_unlock(&p_m);

  }

  return 0;
}
Example #19
0
File: Ssl.c Project: Nejuf/monit
static void _mutexLock(int mode, int n, const char *file, int line) {
        if (mode & CRYPTO_LOCK)
                Mutex_lock(instanceMutexTable[n]);
        else
                Mutex_unlock(instanceMutexTable[n]);
}