MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / ketama_roll

Function ketama_roll

libCacheSim/dataStructure/ketama/ketama.c:495–594  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

493
494
495int
496ketama_roll( ketama_continuum* contptr, char* filename )
497{
498 if (shm_ids == NULL) {
499 init_shm_id_tracker();
500 }
501
502 if (shm_data == NULL) {
503 init_shm_data_tracker();
504 }
505
506 strcpy( k_error, "" );
507
508 key_t key;
509 int shmid;
510 int *data;
511 int sem_set_id;
512
513// setlogmask( LOG_UPTO ( LOG_NOTICE | LOG_ERR | LOG_INFO ) );
514// openlog( "ketama", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1 );
515
516 key = ftok( filename, 'R' );
517 if ( key == -1 )
518 {
519 set_error( "Invalid filename specified: %s", filename );
520 return 0;
521 }
522
523 *contptr = malloc( sizeof( continuum ) );
524 (*contptr)->numpoints = 0;
525 (*contptr)->array = 0;
526 (*contptr)->modtime = 0;
527
528 sem_set_id = ketama_sem_init( key );
529
530 int sanity = 0;
531 while ( semctl( sem_set_id, 0, GETVAL, 0 ) == 2 )
532 {
533 // wait for the continuum creator to finish, but don't block others
534 usleep( 5 );
535
536 // if we are waiting for > 1 second, take drastic action:
537 if(++sanity > 1000000)
538 {
539 usleep( rand()%50000 );
540 ketama_sem_unlock( sem_set_id );
541 break;
542 }
543 }
544
545 time_t modtime = file_modtime( filename );
546 time_t* fmodtime = 0;
547 while ( !fmodtime || modtime != *fmodtime )
548 {
549 shmid = shmget( key, MC_SHMSIZE, 0 ); // read only attempt.
550 track_shm_id(shmid);
551
552 data = shmat( shmid, (void *)0, SHM_RDONLY );

Callers

nothing calls this directly

Calls 10

init_shm_id_trackerFunction · 0.70
init_shm_data_trackerFunction · 0.70
set_errorFunction · 0.70
ketama_sem_initFunction · 0.70
ketama_sem_unlockFunction · 0.70
file_modtimeFunction · 0.70
track_shm_idFunction · 0.70
ketama_sem_lockFunction · 0.70
ketama_create_continuumFunction · 0.70
track_shm_dataFunction · 0.70

Tested by

no test coverage detected