Esempio n. 1
0
void
AirspaceNearestSort::visit_sorted(const Airspaces &airspaces,
                                  AirspaceVisitor &visitor,
                                  const fixed range) 
{
  populate_queue(airspaces, range);

  while (!m_q.empty()) {
    visitor.Visit(*m_q.top().second.second.get_airspace());
    m_q.pop();
  } 
}
Esempio n. 2
0
const AbstractAirspace *
AirspaceNearestSort::find_nearest(const Airspaces &airspaces,
                                  const fixed range)
{
  populate_queue(airspaces, range);

  if (!m_q.empty()) {
    return m_q.top().second.second;
  } else {
    return nullptr;
  }
}
Esempio n. 3
0
/*
 * Main file manager routine.  Watches for new data to be appended to the
 * slapd replication log.  When new data is appended, fm does the following:
 *  - appends the data to slurpd's private copy of the replication log.
 *  - truncates the slapd replog
 *  - adds items to the internal queue of replication work to do
 *  - signals the replication threads to let them know new work has arrived.
 */
void *
fm(
    void *arg
)
{
    int rc;
    int i;
    fd_set readfds;

    /* Set up our signal handlers:
     * SIG{TERM,INT,HUP} causes a shutdown
     */
    (void) SIGNAL( SIGTERM, slurp_set_shutdown );
    (void) SIGNAL( SIGINT, slurp_set_shutdown );
#ifdef SIGHUP
    (void) SIGNAL( SIGHUP, slurp_set_shutdown );
#endif
#if defined(SIGBREAK) && defined(HAVE_NT_SERVICE_MANAGER)
    (void) SIGNAL( SIGBREAK, do_nothing );
#endif

    if ( sglob->one_shot_mode ) {
	if ( file_nonempty( sglob->slapd_replogfile )) {
	    populate_queue( sglob->slapd_replogfile );
	}
	printf( "Processing in one-shot mode:\n" );
	printf( "%d total replication records in file,\n",
		sglob->rq->rq_getcount( sglob->rq, RQ_COUNT_ALL ));
	printf( "%d replication records to process.\n",
		sglob->rq->rq_getcount( sglob->rq, RQ_COUNT_NZRC ));
	return NULL;
    }
    /*
     * There may be some leftover replication records in our own
     * copy of the replication log.  If any exist, add them to the
     * queue.
     */
    if ( file_nonempty( sglob->slurpd_replogfile )) {
	populate_queue( sglob->slurpd_replogfile );
    }

    FD_ZERO( &readfds );

    while ( !sglob->slurpd_shutdown ) {
	if ( file_nonempty( sglob->slapd_replogfile )) {
	    /* New work found - copy to slurpd replog file */
#ifdef NEW_LOGGING
    	LDAP_LOG ( SLURPD, ARGS, 
			"fm: new work in %s\n", sglob->slapd_replogfile, 0, 0 );
#else
	    Debug( LDAP_DEBUG_ARGS, "new work in %s\n",
		    sglob->slapd_replogfile, 0, 0 );
#endif
	    if (( rc = copy_replog( sglob->slapd_replogfile,
		    sglob->slurpd_replogfile )) == 0 )  {
		populate_queue( sglob->slurpd_replogfile );
	    } else {
		if ( rc < 0 ) {
#ifdef NEW_LOGGING
    		LDAP_LOG ( SLURPD, CRIT, 
				"fm: Fatal error while copying replication log\n" , 0, 0, 0);
#else
		    Debug( LDAP_DEBUG_ANY,
			    "Fatal error while copying replication log\n",
			    0, 0, 0 );
#endif
		    sglob->slurpd_shutdown = 1;
		}
	    }
	} else {
	    struct timeval tv;

    	    FD_SET( sglob->wake_sds[0], &readfds );
	    tv.tv_sec = sglob->no_work_interval;
	    tv.tv_usec = 0;

	    rc = select( sglob->wake_sds[0]+1, &readfds, NULL, NULL, &tv );
	}

	/* Garbage-collect queue */
	sglob->rq->rq_gc( sglob->rq );

	/* Trim replication log file, if needed */
	if ( sglob->rq->rq_needtrim( sglob->rq )) {
	    FILE *fp, *lfp;
	    if (( rc = acquire_lock( sglob->slurpd_replogfile, &fp,
		    &lfp )) < 0 ) {
#ifdef NEW_LOGGING
   		LDAP_LOG ( SLURPD, ERR, 
			"fm: Error: cannot acquire lock on \"%s\" for trimming\n",
			sglob->slurpd_replogfile, 0, 0 );
#else
		Debug( LDAP_DEBUG_ANY,
			"Error: cannot acquire lock on \"%s\" for trimming\n",
			sglob->slurpd_replogfile, 0, 0 );
#endif
	    } else {
		sglob->rq->rq_write( sglob->rq, fp );
		(void) relinquish_lock( sglob->slurpd_replogfile, fp, lfp );
	    }
	}
    }
    sglob->rq->rq_lock( sglob->rq );			/* lock queue */
    ldap_pvt_thread_cond_broadcast( &(sglob->rq->rq_more) );	/* wake repl threads */
    for ( i = 0; i < sglob->num_replicas; i++ ) {
	(sglob->replicas[ i ])->ri_wake( sglob->replicas[ i ]);
    }
    sglob->rq->rq_unlock( sglob->rq );			/* unlock queue */
#ifdef NEW_LOGGING
	LDAP_LOG ( SLURPD, RESULTS, "fm: exiting\n", 0, 0, 0 );
#else
    Debug( LDAP_DEBUG_ARGS, "fm: exiting\n", 0, 0, 0 );
#endif
    return NULL;
}