void statsThread(atomic<bool>& failed) { resetThreadAllocInfo(); for (uint32_t i = 1; i <= 1000; ++i) { void* mem = malloc(500); free(mem); ros::WallDuration(0.001).sleep(); AllocInfo info = getThreadAllocInfo(); if (info.mallocs != i) { ROS_ERROR_STREAM("mallocs is " << info.mallocs << " should be " << i); failed.store(true); return; } if (info.frees != i) { ROS_ERROR_STREAM("mallocs is " << info.frees << " should be " << i); failed.store(true); return; } } }
int CommandHandler(XPLMCommandRef inCommand, XPLMCommandPhase inPhase, void* inRefcon) { // if (!gPluginEnabled.load()) { // return IGNORED_EVENT; // } switch (reinterpret_cast<size_t>(inRefcon)) { case CMD_CONTACT_ATC: switch (inPhase) { case xplm_CommandBegin: case xplm_CommandContinue: gPTT_On.store(true); break; case xplm_CommandEnd: gPTT_On.store(false); break; default: break; } break; default: break; } return IGNORED_EVENT; }
void run_test(void) { freelist_type fl(std::allocator<int>(), 8); std::set<dummy*> nodes; dummy d; if (bounded) test_running.store(true); for (int i = 0; i != 4; ++i) { dummy * allocated = fl.template construct<threadsafe, bounded>(); BOOST_REQUIRE(nodes.find(allocated) == nodes.end()); nodes.insert(allocated); } BOOST_FOREACH(dummy * d, nodes) fl.template destruct<threadsafe>(d); nodes.clear(); for (int i = 0; i != 4; ++i) nodes.insert(fl.template construct<threadsafe, bounded>()); BOOST_FOREACH(dummy * d, nodes) fl.template destruct<threadsafe>(d); for (int i = 0; i != 4; ++i) nodes.insert(fl.template construct<threadsafe, bounded>()); if (bounded) test_running.store(false); }
void run(queue & stk) { BOOST_WARN(stk.is_lock_free()); running.store(true); thread_group writer; thread_group reader; BOOST_REQUIRE(stk.empty()); for (int i = 0; i != reader_threads; ++i) reader.create_thread(boost::bind(&queue_stress_tester::template get_items<queue>, this, boost::ref(stk))); for (int i = 0; i != writer_threads; ++i) writer.create_thread(boost::bind(&queue_stress_tester::template add_items<queue>, this, boost::ref(stk))); using namespace std; cout << "threads created" << endl; writer.join_all(); cout << "writer threads joined, waiting for readers" << endl; running = false; reader.join_all(); cout << "reader threads joined" << endl; BOOST_REQUIRE_EQUAL(data.count_nodes(), 0); BOOST_REQUIRE(stk.empty()); BOOST_REQUIRE_EQUAL(push_count, pop_count); BOOST_REQUIRE_EQUAL(push_count, writer_threads * node_count); }
void PstnThread::onJoinSuccess(const char *cname, unsigned uid, const char *msg) { (void)cname; (void)uid; joined_flag_.store(true); LOG(INFO, "Joined the channel %s: %s", cname, msg); }
void populate_queue() { unsigned const number_of_items=20; queue_data.clear(); for(unsigned i=0; i<number_of_items; ++i) { queue_data.push_back(i); } count.store(number_of_items,memory_order_release); }
void release( scope_buffer_pool & pool ) { bool allocated = _status.load( boost::memory_order_relaxed ) != free; if( !allocated ) return; pool.deallocate( _data.get() ); _status.store( free, boost::memory_order_release ); }
InvertedIndexBatch(std::shared_ptr<KVStore::IKVStore> store, shared_ptr<ISetFactory> setFactory) : store(store), setFactory(setFactory), cond_var(&m) { void consumer_main(); maxbatchsize = 2500000; batchsize = 0; store->Open(); producerVec.store(&postings); consumerVec.store(&postings2); consumerThread = std::thread([this](){ this->consumer_main(); }); }
void run() { running = true; if (bounded) test_running.store(true); boost::thread_group alloc_threads; boost::thread_group dealloc_threads; for (int i = 0; i != thread_count; ++i) dealloc_threads.create_thread(boost::bind(&freelist_tester::deallocate, this)); for (int i = 0; i != thread_count; ++i) alloc_threads.create_thread(boost::bind(&freelist_tester::allocate, this)); alloc_threads.join_all(); test_running.store(false); running = false; dealloc_threads.join_all(); }
void consumer_main(){ while (!done) { m.Lock(); if (batchsize > 0){ vector<std::pair<unsigned int,unsigned int>>* temp; temp = producerVec.load(); producerVec.store(consumerVec.load()); consumerVec.store(temp); batchsize = 0; cond_var.Signal(); } else { // sleep while (batchsize == 0 && !done){ cond_var.Wait(); } } m.Unlock(); flushInBackground(); } }
bool await(function<void()> cb = []{}) { int my_gen = generation.load(); if (count.fetch_add(1) == N_THREADS - 1) { if (cb) cb(); count.store(0); generation.fetch_add(1); return true; } else { do { } while (my_gen == generation.load()); return false; } }
void *sampleTimer(void*v){ srand( time(NULL) ); samplingOn = false; while(true){ /*Non-Sampling Period*/ usleep(NON_SAMPLE_PERIOD); /*Sample Generation is ordered by samplingOn's fence*/ unsigned long t = sampleGeneration.load(memory_order_acquire); sampleGeneration.store(t + 1, memory_order_release); samplingOn.store(true, memory_order_release); /*Non-Sampling Period*/ while( samplingOn.load(memory_order_acquire) ){ usleep(SAMPLE_QUANTUM); } } }
void IncrementSharedValue10000000Times(RandomDelay& randomDelay) { int count = 0; while (count < 10000000) { randomDelay.doBusyWork(); int expected = 0; if (flag.compare_exchange_strong(expected, 1, memory_order_relaxed)) { // Lock was successful sharedValue++; flag.store(0, memory_order_relaxed); count++; } } }
bool allocate( scope_buffer_pool & pool, unsigned int channels, unsigned int size ) { bool available = _status.load( boost::memory_order_relaxed ) == free; if( !available ) return false; _size = size; _channels = channels; unsigned int asset_size = channels * size; _data = (float*)pool.allocate( asset_size * 3 * sizeof(float) ); if (_data == NULL) return false; _state[0].data = _data; _state[1].data = _data + asset_size; _state[2].data = _data + asset_size + asset_size; _status.store( initialized, boost::memory_order_release ); return true; }
int ValueSet(int) { int t = 1; a.store(t, memory_order_relaxed); b.store(2, memory_order_relaxed); }
void initOwner() { owner.store(-1); }
int main() { int argc = 1; char** argv = NULL; /// linijka dodana na potrzeby funkcji async int n = 0; int use_ssl = 0; struct libwebsocket_context *context; int opts = 0; char interface_name[128] = ""; const char *iface = NULL; #ifndef WIN32 int syslog_options = LOG_PID | LOG_PERROR; #endif unsigned int oldus = 0; struct lws_context_creation_info info; int debug_level = 7; #ifndef LWS_NO_DAEMONIZE int daemonize = 0; #endif memset(&info, 0, sizeof info); info.port = 7681; while (n >= 0) { n = getopt_long(argc, argv, "ci:hsp:d:D", options, NULL); if (n < 0) continue; switch (n) { #ifndef LWS_NO_DAEMONIZE case 'D': daemonize = 1; #ifndef WIN32 syslog_options &= ~LOG_PERROR; #endif break; #endif case 'd': debug_level = atoi(optarg); break; case 's': use_ssl = 1; break; case 'p': info.port = atoi(optarg); break; case 'i': strncpy(interface_name, optarg, sizeof interface_name); interface_name[(sizeof interface_name) - 1] = '\0'; iface = interface_name; break; case 'c': close_testing = 1; fprintf(stderr, " Close testing mode -- closes on " "client after 50 dumb increments" "and suppresses lws_mirror spam\n"); break; case 'h': fprintf(stderr, "Usage: test-server " "[--port=<p>] [--ssl] " "[-d <log bitfield>]\n"); exit(1); } } #if !defined(LWS_NO_DAEMONIZE) && !defined(WIN32) /* * normally lock path would be /var/lock/lwsts or similar, to * simplify getting started without having to take care about * permissions or running as root, set to /tmp/.lwsts-lock */ if (daemonize && lws_daemonize("/tmp/.lwsts-lock")) { fprintf(stderr, "Failed to daemonize\n"); return 1; } #endif signal(SIGINT, sighandler); #ifndef WIN32 /* we will only try to log things according to our debug_level */ setlogmask(LOG_UPTO (LOG_DEBUG)); openlog("lwsts", syslog_options, LOG_DAEMON); #endif /* tell the library what debug level to emit and to send it to syslog */ lws_set_log_level(debug_level, lwsl_emit_syslog); lwsl_notice("libwebsockets test server - " "(C) Copyright 2010-2013 Andy Green <*****@*****.**> - " "licensed under LGPL2.1\n"); #ifdef EXTERNAL_POLL max_poll_elements = getdtablesize(); pollfds = malloc(max_poll_elements * sizeof (struct pollfd)); fd_lookup = malloc(max_poll_elements * sizeof (int)); if (pollfds == NULL || fd_lookup == NULL) { lwsl_err("Out of memory pollfds=%d\n", max_poll_elements); return -1; } #endif info.protocols = protocols; if (!use_ssl) { info.ssl_cert_filepath = NULL; info.ssl_private_key_filepath = NULL; } else { // info.ssl_cert_filepath = LOCAL_RESOURCE_PATH"/libwebsockets-test-server.pem"; // info.ssl_private_key_filepath = LOCAL_RESOURCE_PATH"/libwebsockets-test-server.key.pem"; } info.gid = -1; info.uid = -1; info.options = opts; context = libwebsocket_create_context(&info); if (context == NULL) { lwsl_err("libwebsocket init failed\n"); return -1; } n = 0; while (n >= 0 && !force_exit) { if(!have_to_run.load()) break; /// dodane struct timeval tv; gettimeofday(&tv, NULL); n = libwebsocket_service(context, 50); is_running.store(true); /// dodane } is_running.store(false); libwebsocket_context_destroy(context); lwsl_notice("libwebsockets-test-server exited cleanly\n"); closelog(); return 0; }
void MemRead(void *addr){ #if defined(SLCOPTEXC) num_reads++; #endif #if defined(SAMPLING) #if defined(COMMGRAPH) || defined(PLUGIN) if( !samplingOn.load(memory_order_acquire) ){ /*Not in a sampling period*/ return; } unsigned long gGen = sampleGeneration.load( memory_order_acquire ); if( myGeneration != gGen ){ myGeneration = gGen; sampleTicks = 0; } /*In a sampling period*/ if( ++sampleTicks > LOCAL_SAMPLE_TICKS ){ samplingOn.store(false,memory_order_release); } #endif #endif unsigned long index = ((unsigned long)addr) & ((unsigned long)LWT_SIZE); #ifdef USE_ATOMICS unsigned long e = LWT_table[index].load(memory_order_consume); #else LWT_Entry e = LWT_table[index]; #endif unsigned long you = (e & ((unsigned long)0xffff000000000000)); #if defined(RRRW) #if defined(STACKS) void *pc0 = __builtin_return_address( 0 ); void *pc1 = __builtin_return_address( 1 ); void *pc = (void*)((((unsigned long)pc1) << 24) | ((unsigned long)pc0)); #else void *pc = __builtin_return_address( 0 ); #endif #endif if( myTid != you){ void *oldPC = (void*)(0x0000ffffffffffff & e); #if defined(RRRW) cciprev->insert((unsigned long)oldPC); #endif #if !defined(RRRW) #if defined(STACKS) void *pc0 = __builtin_return_address( 0 ); void *pc1 = __builtin_return_address( 1 ); void *pc = (void*)((((unsigned long)pc1) << 24) | ((unsigned long)pc0)); #else void *pc = __builtin_return_address( 0 ); #endif #endif #if defined(PLUGIN) plugin_read_trap(addr,oldPC,you,pc,myTid); #endif #if defined(COMMGRAPH) addToCommunicationTable( oldPC, pc ); #endif } #ifdef RRRW unsigned long who = myTid; unsigned long where = (0x0000ffffffffffff & ((unsigned long)pc)); unsigned long newe = ( who | where ); #ifdef USE_ATOMICS LWT_table[index].store(newe, memory_order_relaxed); #else LWT_table[ index ] = newe; #endif #endif }
void DrawWindowCallback(XPLMWindowID inWindowID, void* inRefcon) { // RGB White 1.0, 1.0, 1.0, Green static float commviewer_color[] = {0.0, 1.0, 0.0}; static bool is_connected = false; if (inWindowID != gCommWindow) return; int left; int top; int right; int bottom; int rx_status; int tx_status; string conn_msg = ""; // XXX: are inWindowIDs our XPLMCreateWindow return pointers XPLMGetWindowGeometry(inWindowID, &left, &top, &right, &bottom); // printf("CommViewer, gCommWindow: %p, inWindowID: %p, left:%d, right:%d, top:%d, bottom:%d\n", // gCommWindow, inWindowID, left, right, top, bottom); XPLMDrawTranslucentDarkBox(left, top, right, bottom); if (!gPilotEdgePlugin.load()) { if ((XPLMFindPluginBySignature(PILOTEDGE_SIG)) != XPLM_NO_PLUGIN_ID) { gPilotEdgePlugin.store(true); pilotedge_rx_status_dataref = XPLMFindDataRef("pilotedge/radio/rx_status"); pilotedge_tx_status_dataref = XPLMFindDataRef("pilotedge/radio/tx_status"); pilotedge_connected_dataref = XPLMFindDataRef("pilotedge/status/connected"); } } stringstream str1; stringstream str2; stringstream str3; switch (reinterpret_cast<size_t>(inRefcon)) { case COMMVIEWER_WINDOW: #if 0 sprintf(str1,"%s\t\t\tCOM1: %d\t\t\tCOM2: %d", (char*)(gPTT_On.load() ? "PTT: ON" : "PTT: OFF"), XPLMGetDatai(audio_selection_com1_dataref), XPLMGetDatai(audio_selection_com2_dataref)); // text to window, NULL indicates no word wrap XPLMDrawString(commviewer_color, left+5, top-20, str1, NULL, xplmFont_Basic); #else rx_status = (pilotedge_rx_status_dataref ? XPLMGetDatai(pilotedge_rx_status_dataref) : false) ? 1 : 0; tx_status = (pilotedge_tx_status_dataref ? XPLMGetDatai(pilotedge_tx_status_dataref) : false) ? 1 : 0; conn_msg = (pilotedge_connected_dataref ? XPLMGetDatai(pilotedge_connected_dataref) : false) ? CONN_YES : CONN_NO; if (!is_connected && conn_msg == CONN_YES) { is_connected = true; ifstream infile; infile.open("./Resources/plugins/PilotEdge/VSPro Resources/VSProConnect.ini"); if (infile.is_open()) { int lines_read = 0; string sLine = ""; while (infile) { getline(infile, sLine); lines_read++; if (lines_read == 3) { if (sLine != "none") gNnumber = " " + sLine; } else if (lines_read == 4) { if (sLine != "none") gAircraftType = " " + sLine; break; } } // while infile.close(); } } else if (is_connected && conn_msg == CONN_NO) { is_connected = false; gNnumber = ""; gAircraftType = ""; } str1 << "PilotEdge Connected" << gAircraftType << gNnumber << ": " << conn_msg << '\n'; str2 << string(gPTT_On.load() ? "PTT : ON " : "PTT : OFF") << "\t\tTX: " << tx_status << "\t\t\tRX: " << rx_status << '\n'; str3 << "COM1: " << XPLMGetDatai(audio_selection_com1_dataref) << "\t\tCOM2: " << XPLMGetDatai(audio_selection_com2_dataref); // text to window, NULL indicates no word wrap XPLMDrawString(commviewer_color, left+4, top-10, (char*)str1.str().c_str(), NULL, xplmFont_Basic); XPLMDrawString(commviewer_color, left+4, top-23, (char*)str2.str().c_str(), NULL, xplmFont_Basic); XPLMDrawString(commviewer_color, left+4, top-35, (char*)str3.str().c_str(), NULL, xplmFont_Basic); #endif break; default: break; } #ifdef TOGGLE_TEST_FEATURE GLfloat x1 = (GLfloat)(right + 5); GLfloat y1 = (GLfloat)(top - 5); GLfloat x2; GLfloat y2; GLfloat radius = 0.1f; glDisable(GL_TEXTURE_2D); glColor3f(1.0f, 1.0f, 0.6f); glBegin(GL_TRIANGLE_FAN); glVertex2f(x1, y1); // x & y for (GLfloat angle = 1.0f; angle < 361.0f; angle += 0.2f) { x2 = x1 + (GLfloat)sin(angle) * radius; y2 = y1 + (GLfloat)cos(angle) * radius; glVertex2f(x2, y2); } glEnd(); glEnable(GL_TEXTURE_2D); //glDisable(GL_TEXTURE_2D); //glColor3f(0.7, 0.7, 0.7); //glBegin(GL_LINES); // glVertex2i(right-1, top-1); // glVertex2i(right-7, top-7); // glVertex2i(right-7, top-1); // glVertex2i(right-1, top-7); //glEnd(); //glEnable(GL_TEXTURE_2D); #endif }
PLUGIN_API int XPluginEnable(void) { gPluginEnabled.store(true); LPRINTF("CommViewer Plugin: XPluginEnable\n"); return PROCESSED_EVENT; }
PLUGIN_API void XPluginDisable(void) { gPluginEnabled.store(false); LPRINTF("CommViewer Plugin: XPluginDisable\n"); }
PLUGIN_API void XPluginStop(void) { gPluginEnabled.store(false); //XPLMUnregisterFlightLoopCallback(FlightLoopCallback, NULL); LPRINTF("CommViewer Plugin: XPluginStop\n"); }
void MemWrite(void *addr){ #if defined(SAMPLING) if( !samplingOn.load(memory_order_acquire) ){ /*Not in a sampling period*/ return; } unsigned long gGen = sampleGeneration.load( memory_order_acquire ); if( myGeneration != gGen ){ myGeneration = gGen; sampleTicks = 0; } /*In a sampling period*/ if( ++sampleTicks > LOCAL_SAMPLE_TICKS ){ samplingOn.store(false,memory_order_release); } #endif //unsigned long selfThd = (unsigned long)pthread_self(); unsigned long index = ((unsigned long)addr) & ((unsigned long)LWT_SIZE); #ifdef USE_ATOMICS unsigned long e = LWT_table[index].load(memory_order_consume ); #else LWT_Entry e = LWT_table[index]; #endif #if defined(STACKS) void *pc0 = __builtin_return_address( 0 ); void *pc1 = __builtin_return_address( 1 ); /*0x8... means "write"*/ void *pc = (void*)((((unsigned long)pc1) << 24) | ((unsigned long)pc0)); #else void *pc = __builtin_return_address( 0 ); #endif unsigned long who = myTid; unsigned long where = (0x0000ffffffffffff & ((unsigned long)pc)); unsigned long newe = ( who | where ); #if defined(PLUGIN) || defined(RRRW) || defined(COMMGRAPH) unsigned long you = (e & ((unsigned long)0xffff000000000000)); if( myTid != you ){ void *oldPC = (void*)(0x0000ffffffffffff & e); #if defined(RRRW) cciprev->insert((unsigned long)oldPC); #endif #if defined(PLUGIN) plugin_write_trap(addr,oldPC,you,pc,myTid); #endif #if defined(COMMGRAPH) addToCommunicationTable( oldPC, pc ); #endif } #endif #ifdef ARTIFACTEVAL fprintf(stderr,"LWT[%x]= (Thd 0x%x, PC 0x%x)\n",addr,pthread_self(),pc); #endif #ifdef USE_ATOMICS LWT_table[index].store(newe, memory_order_relaxed ); #else LWT_table[ index ] = newe; #endif #ifdef EVAL_TRACKMEMSIZE pthread_mutex_lock(&mset_lock); MSet.insert( (unsigned long)addr ); pthread_mutex_unlock(&mset_lock); #endif }
void deactivate_() { state_.store( DEACTIVE); }