示例#1
0
void *run(int tid, void (*lock_function)(type *),
		void (*unlock_function)(type *), int *lock_accesses,
		int lock_accesses_size) {
	if (pin && stick_this_thread_to_core(tid % num_cores) != 0)
		printf("Could not pin thread\n");

	int ops = 0; // use local variable, otherwise we're potentially in the same cache line as other threads
	int i = 0;
	while (!stop_run) {
		int access = lock_accesses[i];
		type* mutex_ptr = &mutexes[access].value;
#if DEBUG == 1
		printf("[T#%d] Locking %d (%p)\n", tid, access, mutex_ptr);
#endif
		lock_function(mutex_ptr);
		nop_wait(sleep_time);
#if DEBUG == 1
		printf("[T#%d] Unlocking %d (%p)\n", tid, access, mutex_ptr);
#endif
		unlock_function(mutex_ptr);

		ops++;
		i++;
		i = i % lock_accesses_size;
	}
	operations_count[tid] = ops;
}
示例#2
0
void Fl::lock()
{
    if (!main_thread)
        InitializeCriticalSection(&cs);
    lock_function();
    if (!main_thread)
    {
        fl_lock_function = lock_function;
        fl_unlock_function = unlock_function;
        main_thread = GetCurrentThreadId();
    }
}
示例#3
0
void Fl::lock()
{
    lock_function();
    if (!thread_filedes[1])      // initialize the mt support
    {
        // Init threads communication pipe to let threads awake FLTK from wait
        pipe(thread_filedes);
        Fl::add_fd(thread_filedes[0], FL_READ, thread_awake_cb);
        fl_lock_function = lock_function;
        fl_unlock_function = Fl::unlock;
    }
}