int CodeCache::cache( const AssemblyKeyBase& keyBase, const sp<Assembly>& assembly) { pthread_mutex_lock(&mLock); const ssize_t assemblySize = assembly->size(); while (mCacheInUse + assemblySize > mCacheSize) { // evict the LRU size_t lru = 0; size_t count = mCacheData.size(); for (size_t i=0 ; i<count ; i++) { const cache_entry_t& e = mCacheData.valueAt(i); if (e.when < mCacheData.valueAt(lru).when) { lru = i; } } const cache_entry_t& e = mCacheData.valueAt(lru); mCacheInUse -= e.entry->size(); mCacheData.removeItemsAt(lru); } ssize_t err = mCacheData.add(key_t(keyBase), cache_entry_t(assembly, mWhen)); if (err >= 0) { mCacheInUse += assemblySize; mWhen++; // synchronize caches... char* base = reinterpret_cast<char*>(assembly->base()); char* curr = reinterpret_cast<char*>(base + assembly->size()); __builtin___clear_cache(base, curr); } pthread_mutex_unlock(&mLock); return err; }
void MainWindow::append_user(const quint32 ip, const quint16 port) { const udp_chat::user_desc_s key(ip, port); const QString nickname = udp_chat::client::UserList::instance().get(key); m_keys.push_back(key_t(udp_chat::user_desc_s(ip, port), ui->user_list->count())); ui->user_list->addItem(nickname); }
InputDeviceAdapterVisBox::InputDeviceAdapterVisBox(InputDeviceManager* sInputDeviceManager,const Misc::ConfigurationFileSection& configFileSection) :InputDeviceAdapter(sInputDeviceManager), xyzhpr((const float*)-1) { /* Retrieve the shared memory key from the configuration file: */ key_t sharedMemoryKey=key_t(configFileSection.retrieveValue<int>("./sharedMemoryKey",0xDEAD)); /* Try attaching to the shared memory segment: */ int sharedMemoryID=shmget(sharedMemoryKey,6*sizeof(float),0777); if(sharedMemoryID<0) Misc::throwStdErr("InputDeviceAdapterVisBox::InputDeviceAdapterVisBox: Could not attach to shared memory segment using key %x",int(sharedMemoryKey)); /* Get the pointer to the tracker state variables: */ xyzhpr=reinterpret_cast<const float*>(shmat(sharedMemoryID,0,SHM_RDONLY)); if(xyzhpr==(const float*)-1) Misc::throwStdErr("InputDeviceAdapterVisBox::InputDeviceAdapterVisBox: Could not map shared memory segment using key %x",int(sharedMemoryKey)); /* Allocate new adapter state arrays: */ numInputDevices=1; inputDevices=new InputDevice*[numInputDevices]; /* Create new input device: */ std::string deviceName=configFileSection.retrieveString("./name"); inputDevices[0]=inputDeviceManager->createInputDevice(deviceName.c_str(),InputDevice::TRACK_POS|InputDevice::TRACK_DIR|InputDevice::TRACK_ORIENT,0,0,true); inputDevices[0]->setDeviceRayDirection(configFileSection.retrieveValue<Vector>("./deviceRayDirection",Vector(0,1,0))); /* Initialize the new device's glyph from the current configuration file section: */ Glyph& deviceGlyph=inputDeviceManager->getInputGraphManager()->getInputDeviceGlyph(inputDevices[0]); deviceGlyph.configure(configFileSection,"./deviceGlyphType","./deviceGlyphMaterial"); /* Set device's linear and angular velocities to zero, because we don't know any better: */ inputDevices[0]->setLinearVelocity(Vector::zero); inputDevices[0]->setAngularVelocity(Vector::zero); }
bool jdk_http_response_header::flatten( jdk_dynbuf &dest ) const { if( is_valid() ) { jdk_str<4096> line; dest.clear(); line.form( "%s %d %s\r\n", http_version.c_str(), http_response_code, http_response_text.c_str() ); dest.append_from_string( line ); // append the "Host:" entry first if there is one { int num = map.find( key_t("Host:") );; if( num!=-1 ) { line.form( "%s %s\r\n", map.get(num)->key.c_str(), map.get(num)->value.c_str() ); dest.append_from_string( line ); } } // now copy all other entries for( size_t j=0; j<map.count(); ++j ) { const pair_t *entry = map.get( j ); // is it a valid entry? if( entry && entry->key.len()>1 && entry->key.icmp("Host:")!=0) { // create the line for this key value pair line.form( "%s %s\r\n", entry->key.c_str(), entry->value.c_str() ); // only append lines that arent just full of white space if( line.len()>3 ) { dest.append_from_string( line ); } } } // thats it, finish it off with a blank line dest.append_from_string( "\r\n" ); return true; } else { return false; } }
sp<Assembly> CodeCache::lookup(const AssemblyKeyBase& keyBase) const { pthread_mutex_lock(&mLock); sp<Assembly> r; ssize_t index = mCacheData.indexOfKey(key_t(keyBase)); if (index >= 0) { const cache_entry_t& e = mCacheData.valueAt(index); e.when = mWhen++; r = e.entry; } pthread_mutex_unlock(&mLock); return r; }
int CodeCache::cache( const AssemblyKeyBase& keyBase, const sp<Assembly>& assembly) { pthread_mutex_lock(&mLock); const ssize_t assemblySize = assembly->size(); while (mCacheInUse + assemblySize > mCacheSize) { // evict the LRU size_t lru = 0; size_t count = mCacheData.size(); for (size_t i=0 ; i<count ; i++) { const cache_entry_t& e = mCacheData.valueAt(i); if (e.when < mCacheData.valueAt(lru).when) { lru = i; } } const cache_entry_t& e = mCacheData.valueAt(lru); mCacheInUse -= e.entry->size(); mCacheData.removeItemsAt(lru); } ssize_t err = mCacheData.add(key_t(keyBase), cache_entry_t(assembly, mWhen)); if (err >= 0) { mCacheInUse += assemblySize; mWhen++; // synchronize caches... #if defined(__arm__) const long base = long(assembly->base()); const long curr = base + long(assembly->size()); err = cacheflush(base, curr, 0); LOGE_IF(err, "__ARM_NR_cacheflush error %s\n", strerror(errno)); #endif } pthread_mutex_unlock(&mLock); return err; }
int ACE_TMAIN (int, ACE_TCHAR *[]) { long pid = long (ACE_OS::getpid ()); ACE_Typed_SV_Message_Queue<Message_Data> msgque (key_t (SRV_KEY)); Message_Data msg_data (pid, ACE_OS::cuserid (static_cast<char *> (0)), "did you get this?"); ACE_Typed_SV_Message<Message_Data> send_msg (msg_data, SRV_ID, msg_data.length ()), recv_msg (pid); if (msgque.send (send_msg) < 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("msgque.send")), 1); if (msgque.recv (recv_msg) < 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("msgque.recv")), 1); Message_Data &recv_msg_data = recv_msg.data (); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("a message of length %d") ACE_TEXT (" received from server %d") ACE_TEXT (" (user %C): %C\n"), recv_msg_data.length (), recv_msg_data.pid (), recv_msg_data.user (), recv_msg_data.text ())); return 0; }
InputDeviceAdapterTrackd::InputDeviceAdapterTrackd(InputDeviceManager* sInputDeviceManager,const Misc::ConfigurationFileSection& configFileSection) :InputDeviceAdapterIndexMap(sInputDeviceManager), sensorHeader((SensorHeader*)-1),controllerHeader((ControllerHeader*)-1), sensors(0),buttons(0),valuators(0), calibrationTransformation(OGTransform::identity), updateInterval(0.0), runSpinPollThread(false) { /* Retrieve the shared memory keys for the sensor and controller segments from the configuration file: */ key_t sensorMemoryKey=key_t(configFileSection.retrieveValue<int>("./sensorMemoryKey")); key_t controllerMemoryKey=key_t(configFileSection.retrieveValue<int>("./controllerMemoryKey")); /* Try attaching to the sensor shared memory segment: */ int sensorMemoryID=shmget(sensorMemoryKey,sizeof(SensorHeader),0); if(sensorMemoryID<0) Misc::throwStdErr("InputDeviceAdapterTrackd::InputDeviceAdapterTrackd: Unable to access shared sensor memory segment using key %x",int(sensorMemoryKey)); sensorHeader=static_cast<SensorHeader*>(shmat(sensorMemoryID,0,SHM_RDONLY)); if(sensorHeader==(SensorHeader*)-1) Misc::throwStdErr("InputDeviceAdapterTrackd::InputDeviceAdapterTrackd: Unable to attach to shared sensor memory segment using key %x",int(sensorMemoryKey)); /* Try attaching to the controller shared memory segment: */ int controllerMemoryID=shmget(controllerMemoryKey,sizeof(ControllerHeader),0); if(controllerMemoryID<0) { shmdt(sensorHeader); sensorHeader=(SensorHeader*)-1; Misc::throwStdErr("InputDeviceAdapterTrackd::InputDeviceAdapterTrackd: Unable to access shared controller memory segment using key %x",int(controllerMemoryKey)); } controllerHeader=static_cast<ControllerHeader*>(shmat(controllerMemoryID,0,SHM_RDONLY)); if(controllerHeader==(ControllerHeader*)-1) { shmdt(sensorHeader); sensorHeader=(SensorHeader*)-1; Misc::throwStdErr("InputDeviceAdapterTrackd::InputDeviceAdapterTrackd: Unable to attach to shared controller memory segment using key %x",int(controllerMemoryKey)); } /* Initialize the sensor data pointer array: */ sensors=new SensorData*[sensorHeader->numSensors]; for(unsigned int i=0;i<sensorHeader->numSensors;++i) { /* Set the i-th pointer to the start of the i-th sensor data, accounting for additional unknown entries at the ends of the sensor data structure: */ sensors[i]=reinterpret_cast<SensorData*>(reinterpret_cast<char*>(sensorHeader)+sensorHeader->sensorsOffset+sensorHeader->sensorDataSize*i); } /* Initialize the button and valuator array pointers: */ buttons=reinterpret_cast<Misc::SInt32*>(reinterpret_cast<char*>(controllerHeader)+controllerHeader->buttonsOffset); valuators=reinterpret_cast<Misc::Float32*>(reinterpret_cast<char*>(controllerHeader)+controllerHeader->valuatorsOffset); try { /* Initialize input device adapter: */ InputDeviceAdapterIndexMap::initializeAdapter(sensorHeader->numSensors,controllerHeader->numButtons,controllerHeader->numValuators,configFileSection); } catch(...) { /* Clean up and re-throw the exception: */ shmdt(sensorHeader); sensorHeader=(SensorHeader*)-1; shmdt(controllerHeader); controllerHeader=(ControllerHeader*)-1; delete[] sensors; throw; } /* Read the calibration transformation: */ calibrationTransformation=configFileSection.retrieveValue<OGTransform>("./calibrationTransformation",calibrationTransformation); /* Read the update interval: */ double updateRate=configFileSection.retrieveValue<double>("./updateRate",0.0); if(updateRate==0.0) updateInterval=0.0; else updateInterval=1.0/updateRate; /* Check if the configuration requested spin polling: */ if(configFileSection.retrieveValue<bool>("./spinPoll",false)) { /* Start the spin polling thread: */ runSpinPollThread=true; spinPollThread.start(this,&InputDeviceAdapterTrackd::spinPollThreadMethod); } }
static key_t _key_from_name(const char* name) { std::hash<std::string> str_hash; return key_t(str_hash(name)); }
KeybindManager::KeybindManager() : // TODO get this from a file instead of hardcoding it here keys {{ key_t(SDLK_ESCAPE), action_t::STOP_GAME }, { key_t(SDLK_F1), action_t::TOGGLE_HUD }, { key_t(SDLK_F2), action_t::SCREENSHOT }, { key_t(SDLK_F3), action_t::TOGGLE_DEBUG_OVERLAY }, { key_t(SDLK_F4), action_t::TOGGLE_DEBUG_GRID }, { key_t(SDLK_F5), action_t::QUICK_SAVE }, { key_t(SDLK_F9), action_t::QUICK_LOAD }, { key_t(SDLK_SPACE), action_t::TOGGLE_BLENDING }, { key_t(SDLK_F12), action_t::TOGGLE_PROFILER }, { key_t(SDLK_m), action_t::TOGGLE_CONSTRUCT_MODE }, { key_t(SDLK_p), action_t::TOGGLE_UNIT_DEBUG }, { key_t(SDLK_t), action_t::TRAIN_OBJECT }, { key_t(SDLK_y), action_t::ENABLE_BUILDING_PLACEMENT }, { key_t(SDLK_z, KMOD_LCTRL), action_t::DISABLE_SET_ABILITY }, { key_t(SDLK_x, KMOD_LCTRL), action_t::SET_ABILITY_MOVE }, { key_t(SDLK_c, KMOD_LCTRL), action_t::SET_ABILITY_GATHER }, { key_t(SDLK_BACKQUOTE), action_t::TOGGLE_CONSOLE}, { key_t(SDLK_v), action_t::SPAWN_VILLAGER}, { key_t(SDLK_DELETE), action_t::KILL_UNIT}, { key_t(SDLK_q), action_t::BUILDING_1}, { key_t(SDLK_w), action_t::BUILDING_2}, { key_t(SDLK_e), action_t::BUILDING_3}, { key_t(SDLK_r), action_t::BUILDING_4}, { key_t(SDLK_q, KMOD_LCTRL), action_t::BUILDING_1}, { key_t(SDLK_w, KMOD_LCTRL), action_t::BUILDING_2}, { key_t(SDLK_e, KMOD_LCTRL), action_t::BUILDING_3}, { key_t(SDLK_r, KMOD_LCTRL), action_t::BUILDING_4}, { key_t(SDLK_z), action_t::BUILDING_TOWN_CENTER}, { key_t(SDLK_1), action_t::SWITCH_TO_PLAYER_1}, { key_t(SDLK_2), action_t::SWITCH_TO_PLAYER_2}, { key_t(SDLK_3), action_t::SWITCH_TO_PLAYER_3}, { key_t(SDLK_4), action_t::SWITCH_TO_PLAYER_4}, { key_t(SDLK_5), action_t::SWITCH_TO_PLAYER_5}, { key_t(SDLK_6), action_t::SWITCH_TO_PLAYER_6}, { key_t(SDLK_7), action_t::SWITCH_TO_PLAYER_7}, { key_t(SDLK_8), action_t::SWITCH_TO_PLAYER_8}}, keymod{KMOD_NONE} { }
void fetchcb (vec<key_t *> *nkeys, str kn, sfskeyinfo *ki, sfskey *k) { nkeys->push_back (New key_t (kn, ki, k)); }
void addkey (const str &k) { keys.push_back (New key_t (k)); }