gboolean arv_make_thread_high_priority (int nice_level) { GDBusConnection *bus; GError *error = NULL; bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); if (error != NULL) { arv_warning_misc ("Failed to connect to system bus: %s", error->message); g_error_free (error); return FALSE; } arv_rtkit_make_high_priority (bus, _gettid(), nice_level, &error); g_object_unref (bus); if (error != NULL) { arv_warning_misc ("Failed to connect high priority: %s", error->message); g_error_free (error); return FALSE; } arv_debug_misc ("Nice level successfully changed to %d", nice_level); return TRUE; }
static void arv_zip_build_file_list (ArvZip *zip) { ArvZipFile *zip_file; const void *ptr; ptrdiff_t offset; int i; offset = zip->directory_offset; for (i = 0; i < zip->n_files; i++) { ptr = zip->buffer + zip->header_size + offset; if (GUINT32_FROM_LE_PTR (ptr) != 0x02014b50) return; zip_file = g_new0 (ArvZipFile, 1); zip_file->compressed_size = GUINT32_FROM_LE_PTR (ptr + 20); zip_file->uncompressed_size = GUINT32_FROM_LE_PTR (ptr + 24); zip_file->offset = GUINT32_FROM_LE_PTR (ptr + 42); zip_file->name = g_strndup ((char *) (ptr + 46), GUINT16_FROM_LE_PTR (ptr + 28)); arv_debug_misc ("[Zip::list_files] %s", zip_file->name); zip->files = g_slist_prepend (zip->files, zip_file); offset += 0x2e + GUINT16_FROM_LE_PTR (ptr + 28) + /* filename size */ GUINT16_FROM_LE_PTR (ptr + 30) + /* extra field */ GUINT16_FROM_LE_PTR (ptr + 32); /* file comment */ } }
gboolean arv_make_thread_realtime (int priority) { arv_debug_misc ("SCHED API not supported on OSX"); return FALSE; }
static ptrdiff_t arv_zip_get_file_data (ArvZip *zip, ArvZipFile *zip_file) { const void *ptr; ptr = zip->buffer + zip_file->offset + zip->header_size; if (ARV_GUINT32_FROM_LE_PTR (ptr, 0) != 0x04034b50) { arv_debug_misc ("[Zip::get_file_data] Magic number for file header not found (0x04034b50)"); return -1; } return zip_file->offset + zip->header_size + ARV_GUINT16_FROM_LE_PTR (ptr, 26) + ARV_GUINT16_FROM_LE_PTR (ptr, 28) + 30; }
gboolean arv_make_thread_realtime (int priority) { struct sched_param p; memset(&p, 0, sizeof(p)); p.sched_priority = priority; if (sched_setscheduler(_gettid (), SCHED_RR|SCHED_RESET_ON_FORK, &p) < 0 && errno == EPERM) { struct rlimit rlim; GDBusConnection *bus; GError *error = NULL; memset(&rlim, 0, sizeof(rlim)); rlim.rlim_cur = rlim.rlim_max = 100000000ULL; /* 100ms */ if ((setrlimit(RLIMIT_RTTIME, &rlim) < 0)) { arv_warning_misc ("Failed to set RLIMIT_RTTIME: %s", strerror (errno)); return FALSE; } bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); if (error != NULL) { arv_warning_misc ("Failed to connect to system bus: %s", error->message); g_error_free (error); return FALSE; } arv_rtkit_make_realtime(bus, _gettid (), p.sched_priority, &error); g_object_unref (bus); if (error != NULL) { arv_warning_misc ("Failed to connect make realtime: %s", error->message); g_error_free (error); return FALSE; } arv_debug_misc ("Thread became realtime with priority %d", priority); return TRUE; } return TRUE; }