/* Producer - Resolve an IP address and add it to the queue. */ void dns_resolver (char *addr) { pthread_mutex_lock (&gdns_thread.mutex); /* queue is not full and the IP address is not in the queue */ if (!gqueue_full (gdns_queue) && !gqueue_find (gdns_queue, addr)) { /* add the IP to the queue */ gqueue_enqueue (gdns_queue, addr); pthread_cond_broadcast (&gdns_thread.not_empty); } pthread_mutex_unlock (&gdns_thread.mutex); }
// WV: This is the function you need to select/adapt static void put_pd(FreePacketDescriptorStore fpds, PacketDescriptor pd) { int response = 0; real_fpds rfpds = (real_fpds) fpds; pthread_mutex_lock(&rfpds->lock); response = gqueue_enqueue(rfpds->basic_store, (GQueueElement) pd); if (response) { rfpds->current_length++; pthread_cond_init(rfpds->non_empty, 1); } else DIAGNOSTICS("BUG: Failed to insert element into FPDS\n"); pthread_mutex_unlock(&rfpds->lock); }
void blocking_get_pd(FreePacketDescriptorStore fpds, PacketDescriptor *pd_ptr) { int response = 0; real_fpds rfpds = (real_fpds) fpds; pthread_mutex_unlock(&rfpds->lock); while (rfpds->current_length == 0) { } response = gqueue_enqueue(rfpds->basic_store, (GQueueElement *) pd_ptr); if (response) rfpds->current_length++; else DIAGNOSTICS("BUG: Failed to recover element from non-empty FPDS\n"); pthread_mutex_lock(&rfpds->unlock); }