bool saveFile(const char *name) { mutex.wait(); saving = false; Sound total; total.resize(samples,channels); long int at = 0; while (!sounds.is_empty()) { Sound tmp; sounds.dequeue_head(tmp); for (int i=0; i<channels; i++) { for (int j=0; j<tmp.getSamples(); j++) { total.set(tmp.get(j,i),at+j,i); } } total.setFrequency(tmp.getFrequency()); at += tmp.getSamples(); } mutex.post(); bool ok = write(total,name); if (ok) { printf("Wrote audio to %s\n", name); } samples = 0; channels = 0; return ok; }
// Listing 1 // Listing 2 code/ch05 int QueueExample::runHeapUnboundedQueue (void) { ACE_TRACE ("QueueExample::runHeapUnboundedQueue"); ACE_Unbounded_Queue<DataElement*> queue; for (int i = 0; i < 20; i++) { DataElement *elem; ACE_NEW_RETURN(elem, DataElement (i), -1); queue.enqueue_head (elem); } for (ACE_Unbounded_Queue_Iterator<DataElement*> iter = queue.begin (); !iter.done (); iter.advance ()) { DataElement **elem = 0; iter.next(elem); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d:"), (*elem)->getData ())); delete (*elem); } return 0; }
void Gadget_Part_Impl::remove_from_owner (void) { // Need to guarantee the existence of the owner for the duration of this call. Gadget_var owner = owner_; // Weak pointers are automatically set to NULL if the object they refer to // is deleted. We can use this fact to check that our owner still exists. if (owner == 0) return; // Take all existing parts from the owner and build up a temporary list. If // we find ourselves then we won't add ourselves to the list. ACE_Unbounded_Queue<Gadget_Part_var> parts; for (;;) { Gadget_Part_var part = owner->remove_part (); if (part == 0) break; if (part != this) parts.enqueue_tail (part); } // Add the remaining parts back to the gadget. while (!parts.is_empty ()) { Gadget_Part_var part; parts.dequeue_head (part); owner->add_part (part); } }
// Listing 1 code/ch05 int QueueExample::runStackUnboundedQueue (void) { ACE_TRACE ("QueueExample::runStackUnboundedQueue"); ACE_Unbounded_Queue<DataElement> queue; DataElement elem1[10]; int i; for (i = 0; i < 10; i++) { elem1[i].setData (9-i); queue.enqueue_head (elem1[i]); } DataElement elem2[10]; for (i = 0; i < 10; i++) { elem2[i].setData (i+10); queue.enqueue_tail (elem2[i]); } for (ACE_Unbounded_Queue_Iterator<DataElement> iter (queue); !iter.done (); iter.advance ()) { DataElement *elem = 0; iter.next (elem); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d:"), elem->getData ())); } return 0; }
void saveFrame(Sound& sound) { sounds.enqueue_tail(sound); samples += sound.getSamples(); channels = sound.getChannels(); printf(" %ld sound frames buffered in memory (%ld samples)\n", (long int) sounds.size(), (long int) samples); }
void be_visitor_typecode_defn:: queue_reset (ACE_Unbounded_Queue <be_visitor_typecode_defn::QNode *> & queue) { while (!queue.is_empty ()) { be_visitor_typecode_defn::QNode * qnode = 0; (void) queue.dequeue_head (qnode); delete qnode; } }
void FE_extract_env_include_paths (ACE_Unbounded_Queue<ACE_CString> &list) { ACE_Env_Value<char*> incl_paths (ACE_TEXT ("INCLUDE"), (char *) 0); const char *aggr_str = incl_paths; if (aggr_str != 0) { char separator; #if defined (ACE_WIN32) separator = ';'; #else separator = ':'; #endif ACE_CString aggr_cstr (aggr_str); ACE_CString::size_type pos; do { pos = aggr_cstr.find (separator); list.enqueue_tail (aggr_cstr.substr (0, pos)); aggr_cstr = aggr_cstr.substr (pos + 1); } while (pos != ACE_CString::npos); } }
// Listing 3 // Listing 5 code/ch16 int LF_ThreadPool::elect_new_leader (void) { ACE_TRACE (ACE_TEXT ("LF_ThreadPool::elect_new_leader")); ACE_GUARD_RETURN (ACE_Thread_Mutex, leader_mon, this->leader_lock_, -1); leader_active (0); // Wake up a follower if (!followers_.is_empty ()) { ACE_GUARD_RETURN (ACE_Thread_Mutex, follower_mon, this->followers_lock_, -1); // Get the old follower. Follower *fw; if (this->followers_.dequeue_head (fw) != 0) return -1; ACE_DEBUG ((LM_ERROR, ACE_TEXT ("(%t) Resigning and Electing %d\n"), fw->owner ())); return (fw->signal () == 0) ? 0 : -1; } else { ACE_DEBUG ((LM_ERROR, ACE_TEXT ("(%t) Oops no followers left\n"))); return -1; } }
ssize_t Socket_Impl:: size_ (ACE_Time_Value const* timeout) { ACE_Time_Value abs_time; if (timeout) abs_time = ACE_OS::gettimeofday () + *timeout; Lock l (mutex_); while (queue_.is_empty ()) { if (timeout) { if (cond_.wait (&abs_time) != -1) break; } else { if (cond_.wait () != -1) break; } return -1; // errno is already set } // I can't get the head of the queue without actually dequeuing // the element. // Message_ptr m; if (queue_.dequeue_head (m) == -1) ACE_OS::abort (); if (queue_.enqueue_head (m) == -1) ACE_OS::abort (); if (m->find (NoData::id) != 0) { errno = ENOENT; return -1; } Data const* d = static_cast<Data const*>(m->find (Data::id)); return static_cast<ssize_t> (d->size ()); }
void Socket_Impl::recv (Message_ptr m) { if (m->find (Data::id) != 0 || m->find (NoData::id) != 0) { if (!loop_) { Address to (static_cast<To const*> (m->find (To::id))->address ()); Address from ( static_cast<From const*> (m->find (From::id))->address ()); if (to == from) return; } Lock l (mutex_); //if (queue_.size () != 0) // cerr << "recv socket queue size: " << queue_.size () << endl; //FUZZ: disable check_for_lack_ACE_OS bool signal (queue_.is_empty ()); //FUZZ: enable check_for_lack_ACE_OS queue_.enqueue_tail (m); if (signal) { // Also write to the pipe. if (signal_pipe_.write_handle () != ACE_INVALID_HANDLE) { char c; if (signal_pipe_.send (&c, 1) != 1) { // perror ("write: "); ACE_OS::abort (); } } cond_.signal (); } } }
void TAO_InterfaceDef_i::inherited_operations ( ACE_Unbounded_Queue<ACE_Configuration_Section_Key> &key_queue ) { ACE_Unbounded_Queue<CORBA::DefinitionKind> kind_queue; ACE_Unbounded_Queue<ACE_TString> path_queue; this->base_interfaces_recursive (kind_queue, path_queue); size_t size = path_queue.size (); ACE_Configuration_Section_Key base_key, ops_key, op_key; int status = 0; ACE_TString path_name; u_int count = 0; for (size_t i = 0; i < size; ++i) { path_queue.dequeue_head (path_name); status = this->repo_->config ()->expand_path (this->repo_->root_key (), path_name, base_key, 0); if (status == 0) { this->repo_->config ()->open_section (base_key, "ops", 0, ops_key); this->repo_->config ()->get_integer_value (ops_key, "count", count); for (u_int j = 0; j < count; ++j) { char *stringified = TAO_IFR_Service_Utils::int_to_string (j); this->repo_->config ()->open_section (ops_key, stringified, 0, op_key); key_queue.enqueue_tail (op_key); } } } }
// Are we or the parameter node involved in any recursion? bool AST_Exception::in_recursion (ACE_Unbounded_Queue<AST_Type *> &list) { bool self_test = (list.size () == 0); // We should calculate this only once. If it has already been // done, just return it. if (self_test && this->in_recursion_ != -1) { return (this->in_recursion_ == 1); } if (list.size () > 1) { if (match_names (this, list)) { // this happens when we are not recursed ourselves but instead // are part of another recursive type return false; } } list.enqueue_tail(this); // Proceed if the number of members in our scope is greater than 0. if (this->nmembers () > 0) { // Continue until each element is visited. for (UTL_ScopeActiveIterator i (this, IK_decls);!i.is_done ();i.next ()) { AST_Field *field = AST_Field::narrow_from_decl (i.item ()); if (field == 0) // This will be an enum value or other legitimate non-field // member - in any case, no recursion. { continue; } AST_Type *type = field->field_type (); if (type->node_type () == AST_Decl::NT_typedef) { AST_Typedef *td = AST_Typedef::narrow_from_decl (type); type = td->primitive_base_type (); } if (type == 0) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("(%N:%l) AST_Exception::") ACE_TEXT ("in_recursion - ") ACE_TEXT ("bad field type\n")), 0); } if (type->in_recursion (list)) { if (self_test) this->in_recursion_ = 1; idl_global->recursive_type_seen_ = true; return true; } } } // Not in recursion. if (self_test) this->in_recursion_ = 0; return 0; //this->in_recursion_; }
void TAO_InterfaceDef_i::base_interfaces_recursive ( ACE_Unbounded_Queue<CORBA::DefinitionKind> &kind_queue, ACE_Unbounded_Queue<ACE_TString> &path_queue ) { ACE_Configuration_Section_Key inherited_key; int status = this->repo_->config ()->open_section (this->section_key_, "inherited", 0, inherited_key); // No base interfaces. if (status != 0) { return; } int index = 0; u_int kind = 0; ACE_Configuration::VALUETYPE type; ACE_TString section_name, inherited_path; CORBA::DefinitionKind def_kind = CORBA::dk_none; ACE_Configuration_Section_Key base_key; while (this->repo_->config ()->enumerate_values (inherited_key, index++, section_name, type) == 0) { this->repo_->config ()->get_string_value (inherited_key, section_name.c_str (), inherited_path); status = this->repo_->config ()->expand_path (this->repo_->root_key (), inherited_path, base_key, 0); if (status == 0) { TAO_InterfaceDef_i tmp (this->repo_); tmp.section_key (base_key); tmp.base_interfaces_recursive (kind_queue, path_queue); path_queue.enqueue_tail (inherited_path); this->repo_->config ()->get_integer_value (base_key, "def_kind", kind); def_kind = static_cast<CORBA::DefinitionKind> (kind); kind_queue.enqueue_tail (def_kind); } } }
void TAO_InterfaceDef_i::interface_contents ( ACE_Unbounded_Queue<CORBA::DefinitionKind> &kind_queue, ACE_Unbounded_Queue<ACE_TString> &path_queue, CORBA::DefinitionKind limit_type, CORBA::Boolean exclude_inherited ) { ACE_TString id; this->repo_->config ()->get_string_value (this->section_key_, "id", id); ACE_TString path; this->repo_->config ()->get_string_value (this->repo_->repo_ids_key (), id.c_str (), path); ACE_TString section_name; int index = 0; int status = 0; // Attributes if (limit_type == CORBA::dk_Attribute || limit_type == CORBA::dk_all) { ACE_Configuration_Section_Key attrs_key; status = this->repo_->config ()->open_section (this->section_key_, "attrs", 0, attrs_key); // Only if we have any. if (status == 0) { while (this->repo_->config ()->enumerate_sections (attrs_key, index++, section_name) == 0) { kind_queue.enqueue_tail (CORBA::dk_Attribute); path_queue.enqueue_tail ( path + "\\attrs\\" + section_name.c_str () ); } } } // Operations if (limit_type == CORBA::dk_Operation || limit_type == CORBA::dk_all) { index = 0; ACE_Configuration_Section_Key ops_key; status = this->repo_->config ()->open_section (this->section_key_, "ops", 0, ops_key); // Only if we have any. if (status == 0) { while (this->repo_->config ()->enumerate_sections (ops_key, index++, section_name) == 0) { kind_queue.enqueue_tail (CORBA::dk_Operation); path_queue.enqueue_tail ( path + "\\ops\\" + section_name.c_str () ); } } } if (exclude_inherited == 0) { // Must recurse through the base interfaces. ACE_Configuration_Section_Key inherited_key; status = this->repo_->config ()->open_section (this->section_key_, "inherited", 0, inherited_key); if (status == 0) { ACE_TString base_path; ACE_Configuration_Section_Key base_key; ACE_Configuration::VALUETYPE type; index = 0; while (this->repo_->config ()->enumerate_values (inherited_key, index++, section_name, type) == 0) { this->repo_->config ()->get_string_value (inherited_key, section_name.c_str (), base_path); this->repo_->config ()->expand_path (this->repo_->root_key (), base_path, base_key, 0); TAO_InterfaceDef_i base_iface (this->repo_); base_iface.section_key (base_key); base_iface.interface_contents (kind_queue, path_queue, limit_type, exclude_inherited); } } } }
ssize_t Socket_Impl:: recv_ (void* buf, size_t s, ACE_Time_Value const* timeout, ACE_INET_Addr* from) { ACE_Time_Value abs_time; if (timeout) abs_time = ACE_OS::gettimeofday () + *timeout; Lock l (mutex_); while (queue_.is_empty ()) { if (timeout) { if (cond_.wait (&abs_time) != -1) break; } else { if (cond_.wait () != -1) break; } return -1; // errno is already set } Message_ptr m; if (queue_.dequeue_head (m) == -1) ACE_OS::abort (); if (queue_.is_empty ()) { // Remove data from the pipe. // if (signal_pipe_.read_handle () != ACE_INVALID_HANDLE) { char c; if (signal_pipe_.recv (&c, 1) != 1) { ACE_OS::perror ("read: "); ACE_OS::abort (); } } } if (from) *from = static_cast<From const*> (m->find (From::id))->address (); if (m->find (NoData::id) != 0) { errno = ENOENT; return -1; } Data const* d = static_cast<Data const*>(m->find (Data::id)); ssize_t r (static_cast<ssize_t> (d->size () < s ? d->size () : s)); ACE_OS::memcpy (buf, d->buf (), r); return r; }
void Event_Supplier::load_schedule_data (ACE_Unbounded_Queue<Schedule_Viewer_Data *> &schedule_data) { Schedule_Viewer_Data *data = 0; if (this->input_file_name_) { // Open the scheduler data input file and read its contents into // a queue. FILE *input_file; int scan_count = 0; input_file = ACE_OS::fopen(this->input_file_name_, "r"); if (input_file) { // Get a line at a time from the data file and parse it. char input_buf[BUFSIZ]; while (ACE_OS::fgets (input_buf, BUFSIZ, input_file)) { // Run through leading whitespace. char *temp = input_buf; while (*temp && ACE_OS::ace_isspace (*temp)) ++temp; // If there is anything besides whitespace in the line // read, scan its fields into the scheduling data // structure. if (ACE_OS::strlen (temp) > 0) { ACE_NEW (data, Schedule_Viewer_Data); scan_count = sscanf (temp, "%s %lf %lf %lu %lu %lu %lu", data->operation_name, &data->utilitzation, &data->overhead, &data->arrival_time, &data->deadline_time, &data->completion_time, &data->computation_time); if (scan_count != 7) { ACE_ERROR ((LM_ERROR, "Event_Supplier::start_generating_events: " "scanned incorrect number of data elements: %d\n", scan_count)); delete data; return; } // Insert the data into the queue. schedule_data.enqueue_tail (data); } } } else { ACE_ERROR ((LM_ERROR, "Event_Supplier::start_generating_events: " "could not open input file [%s].\n", this->input_file_name_)); return; } } else { u_long last_completion = 0; // Just create 10 dummy scheduling records and use them. for (int i = 0; i < 10; ++i) { ACE_NEW (data, Schedule_Viewer_Data); const char *oper_name = 0; switch (i % 4) { case 0: oper_name = "high_20"; break; case 1: oper_name = "low_20"; break; case 2: oper_name = "high_10"; break; case 3: default: oper_name = "low_10"; break; } ACE_OS::strncpy (data->operation_name, oper_name, BUFSIZ-1); data->utilitzation = (double)(20.0+ACE_OS::rand() %10); data->overhead = (double)(ACE_OS::rand() %20); data->arrival_time = ACE_OS::rand() % 200; data->computation_time = (ACE_OS::rand() % 100) + 10; data->completion_time = last_completion + (ACE_OS::rand() % 100) + 100; data->completion_time = data->completion_time < data->arrival_time + data->computation_time ? data->arrival_time + data->computation_time : data->completion_time; last_completion = data->completion_time; data->deadline_time = data->completion_time + (ACE_OS::rand() % 200) - 50; // insert the data into the queue. schedule_data.enqueue_tail (data); } } }