bool MultiLocker::ReadUnlock() { #if TIMING bigtime_t start = system_time(); #endif bool unlocked = false; if (IsWriteLocked()) { //writers simply decrement the nesting count fWriterNest--; unlocked = true; } else { //decrement and retrieve the read counter int32 current_count = atomic_add(&fReadCount, -1); if (current_count < 0) { //a writer is waiting for the lock so release fWriteSem unlocked = (release_sem_etc(fWriteSem, 1, B_DO_NOT_RESCHEDULE) == B_OK); } else unlocked = true; //unregister if we released the lock and are debugging if (fDebugArray && unlocked) unregister_thread(); } #if TIMING bigtime_t end = system_time(); ru_time += (end - start); ru_count++; #endif return unlocked; }
void mono_thread_info_dettach (void) { MonoThreadInfo *info = mono_native_tls_get_value (thread_info_key); if (info) { THREADS_DEBUG ("detaching %p\n", info); unregister_thread (info); } }
static void thread_info_key_dtor (void *arg) { /* Put the MonoThreadInfo back for the duration of the * unregister code. In some circumstances the thread needs to * take the GC lock which may block which requires a coop * state transition. */ mono_native_tls_set_value (thread_info_key, arg); unregister_thread (arg); mono_native_tls_set_value (thread_info_key, NULL); }
void file_thread_handler(gpointer *NotUsed){ register_thread("Disk I/O Thread"); while(1){ gpointer *data = g_async_queue_pop (file_async_queue); if (data){ if (data == THREAD_EXIT){ unregister_thread(); g_thread_exit (NULL); } queue_function_data *function_data = (queue_function_data*) data; function_data->func(function_data->data); g_free(function_data); } } }
void gui_thread_handler(gpointer* NotUsed){ register_thread("GUI Thread"); while(1){ gpointer *data = g_async_queue_pop (gui_async_queue); if (data){ if (data == THREAD_EXIT) { //TODO Save ListStore save_liststore_to_file(NULL); unregister_thread(); g_thread_exit (NULL); } queue_function_data *function_data = (queue_function_data*) data; function_data->func(function_data->data); g_free(function_data); } } }
void mono_thread_info_dettach (void) { MonoThreadInfo *info; if (!mono_threads_inited) { /* This can happen from DllMain(THREAD_DETACH) on Windows, if a thread * is created before an embedding API user initialized Mono. */ THREADS_DEBUG ("mono_thread_info_dettach called before mono_threads_init\n"); return; } info = mono_native_tls_get_value (thread_info_key); if (info) { THREADS_DEBUG ("detaching %p\n", info); unregister_thread (info); } }
static void *live_inspector(void *arg) { li_data *data = (li_data *)arg; register_thread("Live Inspector"); unsigned long endtime = (unsigned long)time(NULL) + data->time_to_live; while(!stop) { unsigned long curtime = (unsigned long)time(NULL); int status = api_jobs_status(data->build_id); if(status || curtime > endtime) { kill(data->pid, SIGKILL); canceled = 1; break; } for (int i = 0; !stop && i < 3; i++) { sleep(1); } } free(data); unregister_thread(li_thread); return NULL; }
int main(int argc, char *argv[]) { char proc_path[50], kernel_name[MAX_KERNEL_NAME_LENGTH]; int kmux_command, proc_desc, ret_val; long thread_id; thread_register *thread_info = (thread_register*)malloc(sizeof(thread_register)); ret_val = sprintf(proc_path, "/proc/%s", KMUX_PROC_NAME); // Sanitize input if (argc != 4) { printf("Usage: threadregistrar command kernel_name, thread_id"); exit(-1); } if (strlen(argv[1]) > 1) { printf("Invalid kmux command: %s", argv[2]); exit(-1); } else { kmux_command = atoi(argv[1]); if (!kmux_command || (kmux_command != KMUX_IOCTL_CMD_REGISTER_THREAD && kmux_command != KMUX_IOCTL_CMD_UNREGISTER_THREAD)) { printf("Invalid kmux command: %s", argv[1]); exit(-1); } } if (strlen(argv[2]) > 50) { printf("Kernel name too long: %s", argv[1]); exit(-1); } else { strcpy(kernel_name, argv[2]); } thread_id = atol(argv[3]); if (!thread_id) { printf("Invalid thread ID: %s", argv[3]); exit(-1); } printf("kmux command: %d\n", kmux_command); printf("Kernel name: %s\n", kernel_name); printf("Thread ID: %u\n", (unsigned int)thread_id); strcpy(thread_info->kernel_name, kernel_name); thread_info->thread_id = (unsigned int)thread_id; proc_desc = open(proc_path, O_RDONLY); if (proc_desc < 0) { printf("Can't open proc: %s\n", KMUX_PROC_NAME); exit(-1); } if (kmux_command == KMUX_IOCTL_CMD_REGISTER_THREAD) { register_thread(proc_desc, thread_info); } else { unregister_thread(proc_desc, thread_info); } close(proc_desc); return 0; }