int main() { printf("Expected result: Program should print \"deadlock prevented!\" and exit.\n"); printf("... valgrind won't run clean if exit() is called without calls to _destroy(). This is fine.\n"); printf("... this program should print right away and exit. If it takes longer than a second, it likely deadlocked.\n"); drm_setmode(DEADLOCK_PREVENTION); drm_init(&m1); drm_init(&m2); pthread_t t1, t2; pthread_create(&t1, NULL, count_up, NULL); pthread_create(&t2, NULL, count_down, NULL); pthread_join(t1, NULL); pthread_join(t2, NULL); drm_destroy(&m1); drm_destroy(&m2); drm_cleanup(); printf("%d\n", x); return 0; }
int main() { printf("Expected result: Program should print \"Deadlock detected! Edges: 1 -> 2, 2 -> 1\", where 1 and 2 will be specific thread_ids.\n"); printf("... after that, the program should output a non-zero number (usually a number close to 100000 or -100000).\n"); printf("... as you run your program multiple times, the number should vary between positive and negative.\n"); printf(" ...remember, the thread you send the signal to should be random, so you will be switching between killing the\n"); printf(" count_up() and the count_down() threads.\n"); printf("\n"); printf("... this program should exit within a second or two and exit. If it takes longer than 5 seconds, it likely deadlocked.\n"); printf("... due to how valgrind handles signals, the tester may not work under valgrind.\n"); printf("\n"); drm_setmode(DEADLOCK_DETECTION); drm_init(&m1); drm_init(&m2); pthread_t t1, t2; pthread_create(&t1, NULL, count_up, NULL); pthread_create(&t2, NULL, count_down, NULL); pthread_join(t1, NULL); pthread_join(t2, NULL); drm_destroy(&m1); drm_destroy(&m2); drm_cleanup(); printf("%d\n", x); return 0; }
void __exit drm_exit(struct drm_driver *driver) { int i; drm_device_t *dev = NULL; drm_head_t *head; DRM_DEBUG("\n"); if (drm_fb_loaded) { for (i = 0; i < cards_limit; i++) { head = drm_heads[i]; if (!head) continue; if (!head->dev) continue; if (head->dev->driver != driver) continue; dev = head->dev; } if (dev) { /* release the pci driver */ if (dev->pdev) pci_dev_put(dev->pdev); drm_cleanup(dev); } } else pci_unregister_driver(&driver->pci_driver); DRM_INFO("Module unloaded\n"); }
bool drm_init() { union drm_psb_extension_arg video_getparam_arg; const char video_getparam_ext[] = "lnc_video_getparam"; memset(&gDrmCxt,0,sizeof(drmContext)); gDrmCxt.hdmiConnector = NULL; gDrmCxt.drmFD = open(DRM_DEVICE_NAME, O_RDWR, 0); if (gDrmCxt.drmFD <= 0) { LOGE("%s: Failed to open %s", __func__, DRM_DEVICE_NAME); return false; } strncpy(video_getparam_arg.extension, video_getparam_ext, sizeof(video_getparam_arg.extension)); int ret = drmCommandWriteRead(gDrmCxt.drmFD, DRM_PSB_EXTENSION, &video_getparam_arg, sizeof(video_getparam_arg)); if (ret != 0) { LOGE("Failed to get ioctl offset."); drm_cleanup(); return false; } gDrmCxt.ioctlOffset = video_getparam_arg.rep.driver_ioctl_offset; drmModeConnectorPtr connector = getConnector(gDrmCxt.drmFD, DRM_MODE_CONNECTOR_DVID); gDrmCxt.hdmiSupported = (connector != NULL); if (connector) { drmModeFreeConnector(connector); connector = NULL; } return true; }
void __exit drm_cleanup_pci(struct pci_dev *pdev) { drm_device_t *dev = pci_get_drvdata(pdev); pci_set_drvdata(pdev, NULL); pci_release_regions(pdev); if (dev) drm_cleanup(dev); }