<commit_before>use std::mem;
use std::ptr;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;

use winapi::um::winsock2::{
    fd_set, select, timeval, WSACleanup, WSAStartup, SOCKET_ERROR, WSADATA,
};

use c_ares;

use crate::error::Error;

// The EventLoop will use select() to check on the status of file descriptors that c-ares cares
// about.
pub struct EventLoop {
    pub ares_channel: Arc<Mutex<c_ares::Channel>>,
    quit: Arc<AtomicBool>,
}

impl EventLoop {
    // Create a new event loop.
    pub fn new(options: c_ares::Options) -> Result<Self, Error> {
        // Initialize sockets.
        unsafe {
            let mut wsadata: WSADATA = mem::uninitialized();
            WSAStartup(0x101, &mut wsadata);
        }

        // Create the c-ares channel.
        let ares_channel = c_ares::Channel::with_options(options)?;
        let locked_channel = Arc::new(Mutex::new(ares_channel));

        // Create and return the event loop.
        let event_loop = EventLoop {
            ares_channel: locked_channel,
            quit: Arc::new(AtomicBool::new(false)),
        };
        Ok(event_loop)
    }

    // Run the event loop.
    pub fn run(self) -> Arc<AtomicBool> {
        let stopper = Arc::clone(&self.quit);
        thread::spawn(|| self.event_loop_thread());
        stopper
    }

    // Event loop thread - waits for events, and handles them.
    fn event_loop_thread(self) {
        let mut read_fds: fd_set = unsafe { mem::uninitialized() };
        let mut write_fds: fd_set = unsafe { mem::uninitialized() };

        // Loop round, asking c-ares what it cares about and doing as asked.
        loop {<commit_msg>MaybeUninit<commit_after>use std::mem;
use std::ptr;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;

use winapi::um::winsock2::{
    fd_set, select, timeval, WSACleanup, WSAStartup, SOCKET_ERROR, WSADATA,
};

use c_ares;

use crate::error::Error;

// The EventLoop will use select() to check on the status of file descriptors that c-ares cares
// about.
pub struct EventLoop {
    pub ares_channel: Arc<Mutex<c_ares::Channel>>,
    quit: Arc<AtomicBool>,
}

impl EventLoop {
    // Create a new event loop.
    pub fn new(options: c_ares::Options) -> Result<Self, Error> {
        // Initialize sockets.
        unsafe {
            let mut wsadata = mem::MaybeUninit::<WSADATA>::uninit();
            WSAStartup(0x101, wsadata.as_mut_ptr());
        }

        // Create the c-ares channel.
        let ares_channel = c_ares::Channel::with_options(options)?;
        let locked_channel = Arc::new(Mutex::new(ares_channel));

        // Create and return the event loop.
        let event_loop = EventLoop {
            ares_channel: locked_channel,
            quit: Arc::new(AtomicBool::new(false)),
        };
        Ok(event_loop)
    }

    // Run the event loop.
    pub fn run(self) -> Arc<AtomicBool> {
        let stopper = Arc::clone(&self.quit);
        thread::spawn(|| self.event_loop_thread());
        stopper
    }

    // Event loop thread - waits for events, and handles them.
    fn event_loop_thread(self) {
        let mut read_fds: fd_set = unsafe { mem::MaybeUninit::zeroed().assume_init() };
        let mut write_fds: fd_set = unsafe { mem::MaybeUninit::zeroed().assume_init() };

        // Loop round, asking c-ares what it cares about and doing as asked.
        loop {
{'fraction_non_alphanumeric': 0.12944890929965558, 'fraction_numerical': 0.0028702640642939152, 'mean_word_length': 2.7962962962962963, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1275152', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1104, 'n_words': 298}