MCPcopy Create free account
hub / github.com/OpenPrinting/cups / soft_reset

Function soft_reset

backend/usb-libusb.c:2024–2087  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2022 */
2023
2024static void
2025soft_reset(void)
2026{
2027 fd_set input_set; /* Input set for select() */
2028 struct timeval tv; /* Time value */
2029 char buffer[2048]; /* Buffer */
2030 struct timespec cond_timeout; /* pthread condition timeout */
2031
2032
2033 /*
2034 * Send an abort once a second until the I/O lock is released by the main
2035 * thread...
2036 */
2037
2038 pthread_mutex_lock(&g.readwrite_lock_mutex);
2039 while (g.readwrite_lock)
2040 {
2041 gettimeofday(&tv, NULL);
2042 cond_timeout.tv_sec = tv.tv_sec + 1;
2043 cond_timeout.tv_nsec = tv.tv_usec * 1000;
2044
2045 while (g.readwrite_lock)
2046 {
2047 if (pthread_cond_timedwait(&g.readwrite_lock_cond,
2048 &g.readwrite_lock_mutex,
2049 &cond_timeout) != 0)
2050 break;
2051 }
2052 }
2053
2054 g.readwrite_lock = 1;
2055 pthread_mutex_unlock(&g.readwrite_lock_mutex);
2056
2057 /*
2058 * Flush bytes waiting on print_fd...
2059 */
2060
2061 g.print_bytes = 0;
2062
2063 FD_ZERO(&input_set);
2064 FD_SET(g.print_fd, &input_set);
2065
2066 tv.tv_sec = 0;
2067 tv.tv_usec = 0;
2068
2069 while (select(g.print_fd+1, &input_set, NULL, NULL, &tv) > 0)
2070 if (read(g.print_fd, buffer, sizeof(buffer)) <= 0)
2071 break;
2072
2073 /*
2074 * Send the reset...
2075 */
2076
2077 soft_reset_printer(g.printer);
2078
2079 /*
2080 * Release the I/O lock...
2081 */

Callers 1

sidechannel_threadFunction · 0.70

Calls 1

soft_reset_printerFunction · 0.85

Tested by

no test coverage detected