static void locate_sector(struct disk_data *dd, uint32_t sector, int *track, int *rotoffset) { /* * Assume sector has already been checked for being in bounds. * * Note that we start numbering sectors from the outermost * (fastest) track. */ uint32_t i; uint32_t start = 0; for (i = dd->dd_tracks; i > 0; i--) { uint32_t tr = i-1; uint32_t end = start + dd->dd_sectors[tr]; if (sector >= start && sector < end) { *track = tr; *rotoffset = sector - start; return; } start = end; } smoke("Cannot locate sector %u\n", sector); }
int main(int argc, char**argv) { CLIENT *cl; if(argc != 2) { printf("Usage: ./smoker%d HOSTNAME\n", SMOKER_ID); return 1; } char *server_hostname = argv[1]; cl = clnt_create(server_hostname, SMOKER_PROG, SMOKER_VERS, "udp"); if(cl == NULL) { clnt_pcreateerror("Error creating client\n"); exit(EXIT_FAILURE); } int suppliesLeft = 1; // 1 = true while (suppliesLeft != 0) { if (canSmoke() == 1) smoke(); else { printf("Need more supplies!\n"); // Creates a struct with an empty supply type to send to the agent struct supplyReq request = {getEmptySup(), 1, SMOKER_ID, 0}; printf("Supply Type of request: %c\n", request.supplyType); // Creates a struct to receive the supplies from the agent int* result = getmemysupply_1(&request, cl); // Checks the result struct and whether resources are available // if (*result == REQUEST_GRANTED) { printf("Supplies are received, and now smoking!\n"); updateSupplies(request); // Will update resources and smoke on next iteration } else if (*result == INSUFFICIENT_SUPPLIES) suppliesLeft = 0; else if (*result == CHANGE_SMOKERS) { printf("Waiting to request again after 3 seconds\n"); sleep(3); } else if (*result == TERMINATE) { printf("I am the last smoker and there are no more supplies... I will take the agent down with me!\n"); exit_1(&request, cl); clnt_destroy(cl); exit(0); } else printf("No communication\n"); } } printf("Sadly no more smoking supplies, now I will go kill myself.\n"); clnt_destroy(cl); return 0; }
void selectType(char *type, Particle **p) { if (!strcmp(type, "bouble")) bouble(&(*p)); if (!strcmp(type, "smoke")) smoke(&(*p)); if (!strcmp(type, "water")) water(&(*p)); if (!strcmp(type, "ball")) ball(&(*p)); if (!strcmp(type, "wind")) wind(&(*p)); if (!strcmp(type, "siva")) siva(&(*p)); if (!strcmp(type, "sun")) sun(&(*p)); }
static void disk_close(struct disk_data *dd) { disk_unlock(dd); if (close(dd->dd_fd)) { smoke("disk: slot %d: close: %s", dd->dd_slot, strerror(errno)); } }
int main(void){ int n; while(scanf("%d",&n)!=EOF){ int i; for(i=0;i<n;i++){ scanf("%d",&(color[i][i])); } printf("%llu\n",smoke(n)); } return 0; }
void forkSmokers() { printf("FORKING THREE SMOKERS!\n\n"); pid_t S1 = fork(); if (S1 == 0) { //forked properly printf("SMOKER S1:%d\n", getpid()); smoke(); fflush(stdout); exit(0); } else if (S1 < 0) { perror("Failed to fork"); } else { wait(); consume(); pid_t S2 = fork(); if (S2 == 0) { printf("SMOKER S2:%d\n", getpid()); smoke(); fflush(stdout); exit(0); } else if (S2 < 0) { perror("Failed to fork"); } else { wait(); consume(); pid_t S3 = fork(); if (S3 == 0) { printf("SMOKER S3:%d\n", getpid()); smoke(); fflush(stdout); exit(0); } else if (S3 < 0) { perror("Failed to fork"); } } } }
void onselect(int fd, void *data, int (*func)(void *), void (*rfunc)(void *)) { int ix = findsel(); if (ix<0) { smoke("Ran out of select() records in mainloop"); } selections[ix].sd_fd = fd; selections[ix].sd_data = data; selections[ix].sd_func = func; selections[ix].sd_rfunc = rfunc; }
Projectile::Projectile( Type type, const TextureManager & textures, b2Body * body ) : Entity( 1, body ), pImpl( new Impl( type, textures ) ) { // Add particle system for missiles if ( IsGuided() ) { std::unique_ptr<EmitterNode> smoke( new EmitterNode( Particle::Type::Smoke ) ); smoke->setPosition( 0.f, GetBoundingRect().height / 2.f ); AttachChild( std::move( smoke ) ); std::unique_ptr<EmitterNode> propellant( new EmitterNode( Particle::Type::Propellant ) ); propellant->setPosition( 0.f, GetBoundingRect().height / 2.f ); AttachChild( std::move( propellant ) ); } }
void notonselect(int fd) { int i; for (i=0; i<nsels; i++) { if (selections[i].sd_fd == fd) { if (selections[i].sd_rfunc) { selections[i].sd_rfunc(selections[i].sd_data); } selections[i].sd_fd = -1; return; } } smoke("notonselect: fd %d not found", fd); }
void CMapPlayGalaxy::pumpEvent(const CEvent *evPtr) { if( const EventSpawnObject *ev = dynamic_cast<const EventSpawnObject*>(evPtr) ) { std::shared_ptr<CGalaxySpriteObject> obj( static_cast<CGalaxySpriteObject*>( const_cast<CSpriteObject*>(ev->pObject) ) ); mObjectPtr.push_back( move(obj) ); } else if( const EventSpawnFoot *ev = dynamic_cast<const EventSpawnFoot*>(evPtr) ) // Special Case where the Foot is created { // Episode 4 Secret level // kill all the InchWorms in that case, so they can't do any spawning for( auto obj=mObjectPtr.rbegin() ; obj!=mObjectPtr.rend() ; obj++ ) { galaxy::CInchWorm *inchworm = dynamic_cast<galaxy::CInchWorm*>(obj->get()); if( inchworm != NULL ) { inchworm->exists = false; } } // Create the foot with Smoke Puff int posX = ev->x; int posY = ev->y-(4<<CSF); for( int x=-1 ; x<2 ; x++ ) { for( int y=-1 ; y<2 ; y++ ) { std::shared_ptr<CGalaxySpriteObject> smoke(new galaxy::CSmokePuff( &mMap, posX+(x<<CSF), posY+(y<<CSF), 0 )); mObjectPtr.push_back( smoke ); } } std::shared_ptr<CGalaxySpriteObject> foot(new galaxy::CFoot( &mMap, ev->foeID, 0x2EF4, posX, posY)); mObjectPtr.push_back( foot ); } for( auto obj = mObjectPtr.begin(); obj != mObjectPtr.end() ; obj++) { auto &objRef = *(obj->get()); objRef.pumpEvent(evPtr); } }
Projectile::Projectile(Type type, const TextureHolder& textures) : Entity(1) , mType(type) , mSprite(textures.get(Table[type].texture), Table[type].textureRect) , mTargetDirection() { centerOrigin(mSprite); // Add particle system for missiles if (isGuided()) { std::unique_ptr<EmitterNode> smoke(new EmitterNode(Particle::Smoke)); smoke->setPosition(0.f, getBoundingRect().height / 2.f); attachChild(std::move(smoke)); std::unique_ptr<EmitterNode> propellant(new EmitterNode(Particle::Propellant)); propellant->setPosition(0.f, getBoundingRect().height / 2.f); attachChild(std::move(propellant)); } }
void* smoker(void* resource_type_vp) { int resource_type = (intptr_t) resource_type_vp; uthread_mutex_lock(mx); uthread_cond_signal(smoker_waiting); for (int i = 0; i < NUM_ITERATIONS; i++) { uthread_cond_wait(resource[resource_type]); switch (num_woken) { case 0: num_woken++; resource_of_first = resource_type; break; case 1: num_woken++; switch(resource_of_first * 10 + resource_type) { case 01: case 10: uthread_cond_signal(resource[2]); break; case 02: case 20: uthread_cond_signal(resource[1]); break; case 12: case 21: uthread_cond_signal(resource[0]); break; } break; case 2: num_woken = 0; resource_of_first = -1; smoke(resource_type); uthread_cond_signal(done_smoking); break; } } uthread_mutex_unlock(mx); return NULL; }
SmokeModule *SmokeObject::module() const { return SmokeModule::module(smoke()); }
static int compute_sectors(struct disk_data *dd) { uint32_t physsectors; // total number of actual sectors //uint32_t sectorspertrack; // average sectors per track uint32_t i, tot; double sectors_per_area; double trackwidth; /* * Compute number of physical sectors. We use a bit more than the * requested space so as to leave room for sector remapping. Not * that we actually do sector remapping when computing latencies, * but we could. Note that these spare sectors do not appear in * the file we use for underlying storage. */ physsectors = (uint32_t)(dd->dd_totsectors * SECTOR_FUDGE); if (physsectors < dd->dd_totsectors) { /* Overflow - didn't fit in uint32_t */ smoke("Fatal error computing disk geometry"); return -1; } //sectorspertrack = physsectors/NUMTRACKS; dd->dd_tracks = NUMTRACKS; /* allocate space for dd_tracks entries */ dd->dd_sectors = domalloc(dd->dd_tracks*sizeof(uint32_t)); /* compute the width of each track */ trackwidth = ((OUTER_DIAM - INNER_DIAM)/2) / (double)dd->dd_tracks; /* compute the number of sectors per unit area of disk */ sectors_per_area = physsectors / (PLATTER_AREA); /* * Now, figure out how many sectors are on each track. * We do this by computing the area of the track and multiplying * by sectors_per_area, truncating to the next smallest integer. * We reserve one sector on each track. */ for (i=0; i<dd->dd_tracks; i++) { double inside = INNER_DIAM/2.0 + i*trackwidth; double outside = inside + trackwidth; /* * this track's area = pi*(outside^2 - inside^2) = pi*(outside + * inside)*(outside - inside) = pi*(outside + * inside)*(trackwidth) */ double trackarea = (outside+inside)*trackwidth*PI; double sectors = sectors_per_area*trackarea; if (sectors < 2.0) { /* too small */ msg("disk: slot %d: track %u has only one sector", dd->dd_slot, i); return -1; } dd->dd_sectors[i] = ((int)sectors) - 1; } /* Now compute the total number of sectors available. */ tot = 0; for (i=0; i<dd->dd_tracks; i++) { tot += dd->dd_sectors[i]; } /* Make sure we've got enough space. */ if (tot < dd->dd_totsectors) { /* * Shouldn't happen. If it does, increase SECTOR_FUDGE. */ msg("disk: slot %d: Not enough SECTOR_FUDGE", dd->dd_slot); return -1; } return 0; }