//Communication with the server //Using buffers: buffer, receive void* message_client(void* arg){ //Define thread priority if(((struct thread_args*)arg)->which_thread == 0){ set_priority(22); printf("I HAVE PRIORITY 22\n"); } else if(((struct thread_args*)arg)->which_thread == 1){ set_priority(21); printf("I HAVE PRIORITY 21\n"); } else if(((struct thread_args*)arg)->which_thread == 2){ set_priority(19); printf("I HAVE PRIORITY 19\n"); } else{ set_priority(18); printf("I HAVE PRIORITY 18\n"); } //Perform communication int channelID, status; channelID = ConnectAttach(0, ((struct thread_args*)arg)->pid, 1, 0, 0); //Sends data in buffer. Puts returned data in receive buffer status = MsgSend(channelID, &buffer, sizeof buffer, &receive, sizeof receive); printf("SERVER REPLY: %c\n", receive[0]); //Detach from server ConnectDetach(channelID); return 0; }
void Scanner::load_strand_machines(unsigned int within) { // comments and strings, take that! // add nested strings and comments feature using within variable auto comment_machine = FSMachinePtr( new FiniteMachineContainer(get_token_info(TokType::MP_COMMENT).first, true)); // add states comment_machine->add_state("0", true, false); comment_machine->add_state("1", false, false); comment_machine->add_state("2", false, true); // for state 1 comment_machine->add_alphabet("1", "1"); comment_machine->add_symbols("1", "1"); comment_machine->add_digits("1", "1"); comment_machine->add_transition("1", ' ', "1"); comment_machine->add_transition("1", '\n', "1"); comment_machine->add_transition("1", '\t', "1"); comment_machine->add_transition("1", '\v', "1"); comment_machine->add_transition("1", '\r', "1"); comment_machine->add_transition("1", '\f', "1"); comment_machine->remove_transition("1", '{'); comment_machine->remove_transition("1", '}'); comment_machine->add_transition("0", '{', "1"); comment_machine->add_transition("1", '}', "2"); // new machine auto string_machine = FSMachinePtr( new FiniteMachineContainer(get_token_info(TokType::MP_STRING_LITERAL).first, true)); // add states string_machine->add_state("0", true, false); string_machine->add_state("1", false, false); string_machine->add_state("2", false, true); // add transitions string_machine->add_transition("0", '\'', "1"); string_machine->add_alphabet("1", "1"); string_machine->add_symbols("1", "1"); string_machine->add_digits("1", "1"); string_machine->add_transition("1", ' ', "1"); string_machine->remove_transition("1", '\''); string_machine->remove_transition("1", '\''); string_machine->add_transition("1", '\'', "2"); // set machine priority comment_machine->set_priority(1); string_machine->set_priority(1); // add the machines to our FSMachines list this->fsmachines->push_back(comment_machine); this->fsmachines->push_back(string_machine); }
static void set_low_priority(void) { // Run timed backups with lower priority. I found that this has to be // done after the snapshot, or the snapshot never finishes. At least, I // waited 30 minutes with nothing happening. #if defined(B_VSS_XP) || defined(B_VSS_W2K3) set_priority(THREAD_PRIORITY_LOWEST, "thread_priority_lowest"); #else set_priority(THREAD_MODE_BACKGROUND_BEGIN, "thread_mode_background_begin"); #endif }
int main(int argc, char *argv[]) { // Creating shared memory /*int skynetDesc = shm_open("/skynetcore", O_RDWR, S_IRWXU); struct skynetCore_t* skynetCore = mmap(0, sizeof(struct skynetCore_t), PROT_READ|PROT_WRITE, MAP_SHARED, skynetDesc, 0); pthread_mutex_lock(&skynetCore->protector); int corePid = skynetCore->pid; pthread_mutex_unlock(&skynetCore->protector); printf("Skynet PID is: %i\n", corePid); int skynetChannelId = ConnectAttach(0, corePid, 1, 0, 0); int huehue = 5; MsgSend(skynetChannelId, &huehue, sizeof(int), &huehue, sizeof(int)); printf("I sent %i and got %i back!\n", 5, huehue); ConnectDetach(skynetChannelId);*/ set_priority(6); int i; pthread_t naggers[NUM_NAGGERS]; int ids[NUM_NAGGERS] = { 1, 2, 4, 5 }; for (i = 0; i < NUM_NAGGERS; i++) { pthread_create(&naggers[i], 0, nagger, &ids[i]); } for (i = 0; i < NUM_NAGGERS; i++) { pthread_join(naggers[i], 0); } return 0; }
// load automata for scanning valid identifiers void Scanner::load_id_machine() { // create the id scan automata auto id_machine = FSMachinePtr( new FiniteMachineContainer(get_token_info(TokType::MP_ID).first, true)); // detects ids without two underscores id_machine->add_state("0", true, false); id_machine->add_state("1", false, true); id_machine->add_state("2", false, true); id_machine->add_state("3", false, false); id_machine->add_state("4", false, false); // add transitions id_machine->add_alphabet("0", "1"); id_machine->add_alphabet("1", "1"); id_machine->add_digits("1", "1"); id_machine->add_transition("1", '_', "4"); id_machine->add_alphabet("4", "1"); id_machine->add_digits("4", "1"); // other part id_machine->add_transition("0", '_', "3"); id_machine->add_alphabet("3", "2"); id_machine->add_digits("3", "2"); id_machine->add_alphabet("2", "2"); id_machine->add_digits("2", "2"); id_machine->add_transition("2", '_', "3"); // set priority id_machine->set_priority(2); // add to finite machines this->fsmachines->push_back(FSMachinePtr(id_machine)); }
static int lock_db(const char *dbpath, const char *dbflags) { struct tdb_context *tdb; int tdb_flags; /* No error checking since CTDB always passes sane values */ tdb_flags = strtol(dbflags, NULL, 0); tdb = tdb_open(dbpath, 0, tdb_flags, O_RDWR, 0600); if (tdb == NULL) { fprintf(stderr, "%s: Error opening database %s\n", progname, dbpath); return 1; } set_priority(); if (tdb_lockall(tdb) < 0) { fprintf(stderr, "%s: Error getting db lock (%s)\n", progname, tdb_errorstr(tdb)); return 1; } reset_priority(); return 0; }
static ssize_t set_values_channel(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { struct hidma_chan_attr *chattr; struct hidma_mgmt_dev *mdev; unsigned long tmp; int rc; chattr = container_of(attr, struct hidma_chan_attr, attr); mdev = chattr->mdev; rc = kstrtoul(buf, 0, &tmp); if (rc) return rc; if (strcmp(attr->attr.name, "priority") == 0) { rc = set_priority(mdev, chattr->index, tmp); if (rc) return rc; } else if (strcmp(attr->attr.name, "weight") == 0) { rc = set_weight(mdev, chattr->index, tmp); if (rc) return rc; } return count; }
TEST_F(FailureFixture, ExistingDiskMessageOnDestructTest) { std::random_device generator; std::uniform_int_distribution<unsigned long long> distribution(1, DEFAULT_MAX_MEMORY_SIZE); auto number_to_create = distribution(generator); { PriorityBuffer<PriorityMessage> buffer{get_priority}; // Push DEFAULT_MAX_MEMORY_SIZE messages into the buffer with 0 priority for (int i = 0; i < DEFAULT_MAX_MEMORY_SIZE; ++i) { auto message = std::unique_ptr<PriorityMessage>{ new PriorityMessage{} }; message->set_priority(0); ASSERT_TRUE(message->IsInitialized()); buffer.Push(std::move(message)); } std::stringstream stream; stream << "SELECT hash FROM " << table_name_ << " ORDER BY priority LIMIT " << number_to_create << ";"; auto response = execute_(stream.str()); ASSERT_EQ(number_to_create, response.size()); for (auto& record : response) { auto file_path = buffer_path_ / fs::path{record["hash"]}; std::ofstream file_out{file_path.native()}; file_out << "hello world"; } } // Let the buffer drop and try to push memory messages to disk EXPECT_EQ(DEFAULT_MAX_MEMORY_SIZE - number_to_create, number_of_files_()); }
static void* fn_rd(void *arg) { int rc = 0; int priority; rd_thread_state = ENTERED_THREAD; priority = (long)arg; set_priority(pthread_self(), TRD_POLICY, priority); printf("rd_thread: attempt read lock\n"); rc = pthread_rwlock_rdlock(&rwlock); if(rc != 0) { printf("Test FAILED: rd_thread failed to get read lock, Error code:%d\n" , rc); exit(PTS_FAIL); } else printf("rd_thread: acquired read lock\n"); sleep(1); printf("rd_thread: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("rd_thread: Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } rd_thread_state = EXITING_THREAD; pthread_exit(0); return NULL; }
static void reset(test_context *ctx) { rtems_status_code sc; size_t i; for (i = 0; i < TASK_COUNT; ++i) { set_priority(ctx->task_ids[i], P(i)); set_affinity(ctx->task_ids[i], A(1, 1)); } for (i = CPU_COUNT; i < TASK_COUNT; ++i) { sc = rtems_task_suspend(ctx->task_ids[i]); rtems_test_assert(sc == RTEMS_SUCCESSFUL || sc == RTEMS_ALREADY_SUSPENDED); } for (i = 0; i < CPU_COUNT; ++i) { sc = rtems_task_resume(ctx->task_ids[i]); rtems_test_assert(sc == RTEMS_SUCCESSFUL || sc == RTEMS_INCORRECT_STATE); } /* Order the idle threads explicitly */ for (i = 0; i < CPU_COUNT; ++i) { const Per_CPU_Control *c; const Thread_Control *h; c = _Per_CPU_Get_by_index(CPU_COUNT - 1 - i); h = c->heir; sc = rtems_task_suspend(h->Object.id); rtems_test_assert(sc == RTEMS_SUCCESSFUL); } }
int main(int argc, char *argv[]) { period = DEFAULT_PERIOD*NS_PER_MS; prio = DEFAULT_PRIO; calc_loops = DEFAULT_CALC_LOOPS; setup(); rt_init("f:hi:r:t:l:", parse_args, argc, argv); if (iterations < 100) { printf("Number of iterations cannot be less than 100\n"); exit(1); } if (!period || !prio | !calc_loops) { usage(); exit(1); } set_priority(prio); printf("------------------------------------\n"); printf("Periodic CPU Load Execution Variance\n"); printf("------------------------------------\n\n"); printf("Running %d iterations\n", iterations); printf("priority: %d\n", prio); printf(" period: %d ms\n", period/NS_PER_MS); printf(" loops: %d\n", calc_loops); printf(" logs: %s*\n", filename_prefix); ret = periodic_thread(period, iterations, calc_loops); return ret; }
int main(int argc, char *argv[]) { printf("Welcome to the QNX Momentics IDE\n"); //This program reads from a shared memory location //and prints content //Access shared memory int f_desc = shm_open("/dev/shmem/sharedpid", O_RDWR, S_IRWXU); struct pid_data* voidy = mmap(0, (sizeof(struct pid_data)), (PROT_READ | PROT_WRITE), MAP_SHARED, f_desc, 0); //Extract info from shared memory pid_t result = 0; pthread_mutex_lock(&voidy->pid_mutex); result = voidy->pid; pthread_mutex_unlock(&voidy->pid_mutex); printf("The pid of the other program is %d \n", result); buffer[0] = 'G'; struct thread_args arg1; struct thread_args arg2; struct thread_args arg3; struct thread_args arg4; arg1.pid = result; arg2.pid = result; arg3.pid = result; arg4.pid = result; arg1.which_thread = 0; arg2.which_thread = 1; arg3.which_thread = 2; arg4.which_thread = 3; set_priority(60); //Perform communication through THREADSSSS, LOTS OF THREADSSSS pthread_t t1, t2, t3, t4; //main thread needs highest priority if(pthread_create(&t1, NULL, message_client, (void*)&arg1)) printf("FAILED TO CREATE THREAD\n"); if(pthread_create(&t2, NULL, message_client, (void*)&arg2)) printf("FAILED TO CREATE THREAD\n"); if(pthread_create(&t3, NULL, message_client, (void*)&arg3)) printf("FAILED TO CREATE THREAD\n"); if(pthread_create(&t4, NULL, message_client, (void*)&arg4)) printf("FAILED TO CREATE THREAD\n"); pthread_join(t1, NULL); pthread_join(t2, NULL); pthread_join(t3, NULL); pthread_join(t4, NULL); return EXIT_SUCCESS; }
static void *fn_rd(void *arg) { int rc = 0; int priority; rd_thread_state = ENTERED_THREAD; priority = (long)arg; set_priority(pthread_self(), TRD_POLICY, priority); printf("reader: attempt read lock\n"); rc = pthread_rwlock_rdlock(&rwlock); if (rc != 0) { printf ("Error: rd_thread failed to get read lock, Error code:%d\n", rc); exit(PTS_UNRESOLVED); } rd_thread_state = PASSED_LOCK; printf("reader: acquired read lock\n"); /* Wait for main to wake us up */ do { sleep(1); } while (rd_thread_state != EXITING_THREAD); printf("reader: unlock read lock\n"); if (pthread_rwlock_unlock(&rwlock) != 0) { printf("rd_thread: Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } pthread_exit(0); return NULL; }
static void *fn_wr_2(void *arg) { int rc = 0; int priority; wr_thread_state_2 = ENTERED_THREAD; priority = (long)arg; set_priority(pthread_self(), TRD_POLICY, priority); printf("writer2: attempt write lock\n"); rc = pthread_rwlock_wrlock(&rwlock); if (rc != 0) { printf ("Error: wr_thread failed to get write lock, Error code:%d\n", rc); exit(PTS_UNRESOLVED); } wr_thread_state_2 = PASSED_LOCK; printf("writer2: acquired writer lock\n"); /* Wait for main to wake us up */ do { sleep(1); } while (wr_thread_state_2 != EXITING_THREAD); printf("writer2: unlock writer lock\n"); if (pthread_rwlock_unlock(&rwlock) != 0) { printf("wr_thread: Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } pthread_exit(0); return NULL; }
void heap_increase_priority(heap_t *heap, heap_item_t* item, double new_priority, double (*compute_priority)(heap_item_t*), void (*set_priority)(heap_item_t*,double)) { // assumes that priority and node mass are one and the same double new_mass; if (new_priority < compute_priority(item)) { fprintf(stderr,"New priority is smaller than current priority.\n"); return; } new_mass = new_priority - item->node_mass; set_priority(item,new_priority); item->node_mass = new_priority; item->subtree_mass += new_mass; while (item->index > 0 && compute_priority(heap_parent(heap, item)) < compute_priority(item)) { heap_parent(heap,item)->subtree_mass += new_mass; heap_exchange(heap, item, heap_parent(heap, item)); item = heap_parent(heap, item); } while (item->index > 0) { heap_parent(heap,item)->subtree_mass += new_mass; item = heap_parent(heap, item); } }
static void* fn_wr(void *arg) { int rc = 0; int priority; wr_thread_state = ENTERED_THREAD; priority = (long)arg; set_priority(pthread_self(), TRD_POLICY, priority); printf("wr_thread: attempt write lock\n"); rc = pthread_rwlock_wrlock(&rwlock); if(rc != 0) { printf("Error: wr_thread failed to get write lock, Error code:%d\n" , rc); exit(PTS_UNRESOLVED); } else printf("wr_thread: acquired write lock\n"); sleep(1); printf("wr_thread: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("wr_thread: Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } wr_thread_state = EXITING_THREAD; pthread_exit(0); return NULL; }
static void thread_recompute_priority( thread_t thread) { integer_t priority; if (thread->sched_mode & TH_MODE_REALTIME) priority = BASEPRI_RTQUEUES; else { if (thread->importance > MAXPRI) priority = MAXPRI; else if (thread->importance < -MAXPRI) priority = -MAXPRI; else priority = thread->importance; priority += thread->task_priority; if (priority > thread->max_priority) priority = thread->max_priority; else if (priority < MINPRI) priority = MINPRI; } set_priority(thread, priority); }
TEST_F(FailureFixture, ExistingDiskMessageTest) { PriorityBuffer<PriorityMessage> buffer{get_priority}; // Push DEFAULT_MAX_MEMORY_SIZE messages into he buffer with 0 priority for (int i = 0; i < DEFAULT_MAX_MEMORY_SIZE; ++i) { auto message = std::unique_ptr<PriorityMessage>{ new PriorityMessage{} }; message->set_priority(0); ASSERT_TRUE(message->IsInitialized()); buffer.Push(std::move(message)); } std::random_device generator; std::uniform_int_distribution<unsigned long long> distribution(1, DEFAULT_MAX_MEMORY_SIZE); auto number_to_create = distribution(generator); std::stringstream stream; stream << "SELECT hash FROM " << table_name_ << " ORDER BY priority LIMIT " << number_to_create << ";"; auto response = execute_(stream.str()); ASSERT_EQ(number_to_create, response.size()); for (auto& record : response) { auto file_path = buffer_path_ / fs::path{record["hash"]}; std::ofstream file_out{file_path.native()}; file_out << "hello world"; } // Push DEFAULT_MAX_MEMORY_SIZE messages into he buffer with 1 priority, pushing all the // previous messages out for (int i = 0; i < DEFAULT_MAX_MEMORY_SIZE; ++i) { auto message = std::unique_ptr<PriorityMessage>{ new PriorityMessage{} }; message->set_priority(1); ASSERT_TRUE(message->IsInitialized()); buffer.Push(std::move(message)); } for (int i = 0; i < 100 - number_to_create; ++i) { auto message = buffer.Pop(); ASSERT_TRUE(message->IsInitialized()); ASSERT_GE(1, message->priority()); } EXPECT_EQ(nullptr, buffer.Pop()); }
void main_maxspeed() { conf.sound.enabled ^= 1; temp.frameskip = conf.sound.enabled? conf.frameskip : conf.frameskipmax; if (conf.sound.enabled) sound_play(); else sound_stop(); sprintf(statusline, "Max speed: %s", conf.sound.enabled ? "NO" : "YES"); statcnt = 50; set_priority(); }
void Scanner::load_num_machines() { // create floating point automata for scanning numeric literals auto float_machine = FSMachinePtr( new FiniteMachineContainer(get_token_info(TokType::MP_FLOAT_LITERAL).first, true)); // add states to this DFA, first and final float_machine->add_state("0", true, false); float_machine->add_state("1", false, false); float_machine->add_state("2", false, true); float_machine->add_state("3", false, false); float_machine->add_state("4", false, false); float_machine->add_state("5", false, true); float_machine->add_digits("0", "1"); float_machine->add_digits("1", "1"); float_machine->add_transition("1", '.', "2"); float_machine->add_digits("2", "2"); float_machine->add_transition("2", 'e', "3"); float_machine->add_transition("2", 'E', "3"); float_machine->add_transition("3", '+', "4"); float_machine->add_transition("3", '-', "4"); float_machine->add_digits("3", "5"); float_machine->add_digits("4", "5"); float_machine->add_digits("5", "5"); // create integer automata auto integer_machine = FSMachinePtr( new FiniteMachineContainer(get_token_info(TokType::MP_INT_LITERAL).first, true)); // add states to this DFA integer_machine->add_state("0", true, false); integer_machine->add_state("1", false, true); integer_machine->add_digits("0", "1"); integer_machine->add_digits("1", "1"); // reset both float_machine->reset(); integer_machine->reset(); // set machine priorities float_machine->set_priority(1); integer_machine->set_priority(1); // add both to the finite machines list this->fsmachines->push_back(FSMachinePtr(float_machine)); this->fsmachines->push_back(FSMachinePtr(integer_machine)); }
int main(int argc, char *argv[]) { printf("Server started \n"); /* Create shared memory */ int file_descriptor; file_descriptor = shm_open("/sharedpid", O_RDWR | O_CREAT, S_IRWXU); /* Resize shared memory */ ftruncate(file_descriptor, sizeof(pid_data)); /* Map shared memory into address space */ void* shared_memory; shared_memory = mmap(0, sizeof(pid_data), PROT_READ | PROT_WRITE, MAP_SHARED, file_descriptor, 0); /* Create struct */ pid_data data; data.pid = getpid(); /* Create Mutex */ pthread_mutex_t lock = ((pid_data*)shared_memory)->pid_mutex; pthread_mutexattr_t myattr; pthread_mutexattr_init(&myattr); pthread_mutexattr_setpshared(&myattr, PTHREAD_PROCESS_SHARED); pthread_mutex_init(&lock, &myattr ); /* Set pid in shared memory */ pthread_mutex_lock(&lock); *((pid_data*)shared_memory) = data; pthread_mutex_unlock(&lock); printf("Pid stored in shared memory \n"); /* Create channel */ int ch_id = ChannelCreate(0); printf("Channel %d created \n", ch_id); int rcv_id; int buffer_recv; int buffer_resp; struct _msg_info msg_info; /* Set priority */ set_priority(SERVER_PRIORITY); /* Listen for client */ printf("Server listening... \n"); while(1){ printf("Server priority: %d\n", get_priority()); rcv_id = MsgReceive(ch_id, &buffer_recv, sizeof(buffer_recv), &msg_info); buffer_resp = buffer_recv + 1; printf("Received: %d, Responding: %d \n", buffer_recv, buffer_resp); if(MsgReply(rcv_id, EOK, &buffer_resp, sizeof(buffer_resp)) != EOK){ printf("ERROR: failed to reply to message: %d \n", buffer_recv); } } return EXIT_SUCCESS; }
Thread::Thread(int priority,Tim::ExecuteDone *_done) { end=false; terminate=false; threadhandle=CreateThread(NULL,0,Execute,this,CREATE_SUSPENDED,&ThreadID); //threadhandle=CreateThread(NULL,0,Execute,this,0,&ThreadID); thread_start=false; set_priority(priority); done=_done; }
task_entry load_elf (char *elf_start, int idx) { Elf32_Ehdr *hdr = NULL; Elf32_Phdr *phdr = NULL; Elf32_Shdr *shdr = NULL; Elf32_Sym *syms = NULL; char *strings = NULL; char *start = NULL; char *taddr = NULL; task_entry entry = NULL; int i = 0; char buff[32]; hdr = (Elf32_Ehdr *) elf_start; exec = (char *)(USER_CODE_BASE + idx*USER_CODE_GAP); phdr = (Elf32_Phdr *)(elf_start + hdr->e_phoff); for(i=0; i < hdr->e_phnum; ++i) { if(phdr[i].p_type != PT_LOAD) { continue; } if(phdr[i].p_filesz > phdr[i].p_memsz) { print_msg("load_elf:: p_filesz > p_memsz\n"); return 0; } if(!phdr[i].p_filesz) { continue; } start = elf_start + phdr[i].p_offset; taddr = phdr[i].p_vaddr + exec; /* copy program to 0x1600000 */ memmove(taddr,start,phdr[i].p_filesz); } shdr = (Elf32_Shdr *)(elf_start + hdr->e_shoff); for (i=0 ; i<hdr->e_shnum ; i++) { if (shdr[i].sh_type == SHT_SYMTAB) { syms = (Elf32_Sym *)(elf_start + shdr[i].sh_offset); strings = elf_start + shdr[shdr[i].sh_link].sh_offset; entry = find_sym("main", shdr + i, strings, elf_start, exec); break; } } /* user task is not inserted to rq. it should be called explicitly*/ sprintf(buff,"user%d",idx); upt[idx]= do_forkyi(buff, (task_entry)entry, idx); set_priority(upt[idx], 4); rb_init_node(&(upt[idx]->se).run_node); enqueue_se_to_runq(runq, &(upt[idx]->se), true); return entry; }
/* * Use a timer to execute the actions, since it runs with thread dispatching * disabled. This is necessary to check the expected processor allocations. */ static void timer(rtems_id id, void *arg) { test_context *ctx; rtems_status_code sc; size_t i; ctx = arg; i = ctx->action_index; if (i == 0) { sc = rtems_task_suspend(ctx->master_id); rtems_test_assert(sc == RTEMS_SUCCESSFUL); } if (i < RTEMS_ARRAY_SIZE(test_actions)) { const test_action *action = &test_actions[i]; rtems_id task; ctx->action_index = i + 1; task = ctx->task_ids[action->index]; switch (action->kind) { case KIND_SET_PRIORITY: set_priority(task, action->data.priority); break; case KIND_SET_AFFINITY: set_affinity(task, action->data.cpu_set); break; case KIND_BLOCK: sc = rtems_task_suspend(task); rtems_test_assert(sc == RTEMS_SUCCESSFUL); break; case KIND_UNBLOCK: sc = rtems_task_resume(task); rtems_test_assert(sc == RTEMS_SUCCESSFUL); break; default: rtems_test_assert(action->kind == KIND_RESET); reset(ctx); break; } check_cpu_allocations(ctx, action); sc = rtems_timer_reset(id); rtems_test_assert(sc == RTEMS_SUCCESSFUL); } else { sc = rtems_task_resume(ctx->master_id); rtems_test_assert(sc == RTEMS_SUCCESSFUL); sc = rtems_event_transient_send(ctx->master_id); rtems_test_assert(sc == RTEMS_SUCCESSFUL); } }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { //Use Real-time Scheduling class if possible set_priority(); try { CORBA::ORB_var sorb = CORBA::ORB_init (argc, argv); if (parse_args (argc,argv) == -1) return -1; ACE_Manual_Event wait_for_event; Server_Task server_task (sorb.in (), wait_for_event, ACE_Thread_Manager::instance ()); if (server_task.activate (THR_NEW_LWP | THR_JOINABLE, 1, 1) == -1) { ACE_ERROR ((LM_ERROR, "Error activating server task\n")); } // Wait for the server thread to do some processing wait_for_event.wait (); // Obtain the object reference Test::Roundtrip_var reference = server_task.get_reference (); Client_Task client_task (reference.in (), niterations, ACE_Thread_Manager::instance ()); if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, 1, 1) == -1) { ACE_ERROR ((LM_ERROR, "Error activating client task\n")); } ACE_Thread_Manager::instance ()->wait (); } catch (const CORBA::Exception&) { // Ignore exceptions.. } return 0; }
void PulsingColorAnimation::loadFromJSON(const QJsonObject & obj) { if (obj.contains("fromStart")) set_fromStart(obj["fromStart"].toDouble()); if (obj.contains("duration")) set_duration(obj["duration"].toDouble()); if (obj.contains("lowerColor") and obj.contains("upperColor")) { QColor lowerColor = QColor(obj["lowerColor"].toString()); QColor upperColor = QColor(obj["upperColor"].toString()); set_meanColor(QColor((upperColor.red() + lowerColor.red()) / 2, (upperColor.green() + lowerColor.green()) / 2, (upperColor.blue() + lowerColor.blue()) / 2)); set_varColor(QColor((upperColor.red() - lowerColor.red()) / 2, (upperColor.green() - lowerColor.green()) / 2, (upperColor.blue() - lowerColor.blue()) / 2)); } if (obj.contains("frequency")) set_pulsation(obj["frequency"].toDouble() * 2 * M_PI); if (obj.contains("delay")) set_delay(obj["delay"].toDouble()); if (obj.contains("pulseSignal")) set_pulseSignal(obj["pulseSignal"].toString()); if (obj.contains("priority")) set_priority(obj["priority"].toInt()); }
CompEventSource::CompEventSource (Display *dpy, int fd) : Glib::Source (), mDpy (dpy), mConnectionFD (fd) { mPollFD.set_fd (mConnectionFD); mPollFD.set_events (Glib::IO_IN); set_priority (G_PRIORITY_DEFAULT); add_poll (mPollFD); set_can_recurse (true); connect (sigc::mem_fun <bool, CompEventSource> (this, &CompEventSource::callback)); }
web_connection_base::web_connection_base( session_impl& ses , boost::weak_ptr<torrent> t , boost::shared_ptr<socket_type> s , tcp::endpoint const& remote , std::string const& url , policy::peer* peerinfo , std::string const& auth , web_seed_entry::headers_t const& extra_headers) : peer_connection(ses, t, s, remote, peerinfo) , m_parser(http_parser::dont_parse_chunks) , m_external_auth(auth) , m_extra_headers(extra_headers) , m_first_request(true) , m_ssl(false) , m_body_start(0) { INVARIANT_CHECK; // we only want left-over bandwidth set_priority(1); // since this is a web seed, change the timeout // according to the settings. set_timeout(ses.settings().urlseed_timeout); std::string protocol; error_code ec; boost::tie(protocol, m_basic_auth, m_host, m_port, m_path) = parse_url_components(url, ec); TORRENT_ASSERT(!ec); if (m_port == -1 && protocol == "http") m_port = 80; #ifdef TORRENT_USE_OPENSSL if (protocol == "https") { m_ssl = true; if (m_port == -1) m_port = 443; } #endif if (!m_basic_auth.empty()) m_basic_auth = base64encode(m_basic_auth); m_server_string = "URL seed @ "; m_server_string += m_host; }
void nagger(void *arg){ set_priority(*(int*)arg); // Creating shared memory int skynetDesc = shm_open("/skynetcore", O_RDWR, S_IRWXU); struct skynetCore_t* skynetCore = mmap(0, sizeof(struct skynetCore_t), PROT_READ|PROT_WRITE, MAP_SHARED, skynetDesc, 0); pthread_mutex_lock(&skynetCore->protector); int corePid = skynetCore->pid; pthread_mutex_unlock(&skynetCore->protector); int message = *(int*)arg; int skynetChannelId = ConnectAttach(0, corePid, 1, 0, 0); MsgSend(skynetChannelId, &message, sizeof(int), &message, sizeof(int)); printf("I sent %i and got %i back!\n", *(int*)arg, message); ConnectDetach(skynetChannelId); }
int halide_hexagon_runtime_set_thread_priority(int priority) { if (priority < 0) { return 0; } // Find the halide_set_default_thread_priority function in the shared runtime, // which we loaded with RTLD_GLOBAL. void (*set_priority)(int) = (void (*)(int)) halide_get_symbol("halide_set_default_thread_priority"); if (set_priority) { set_priority(priority); } else { // This code being run is old, doesn't have set priority feature, do nothing. } return 0; }