Exemplo n.º 1
0
static int rabin_delegate(RThread *th) {
	if (rabin_cmd && r_file_exists (r.file->desc->name)) {
		char *nptr, *ptr, *cmd = r_sys_cmd_str (rabin_cmd, NULL, NULL);
		ptr = cmd;
		if (ptr) {
			do {
				if (th) {
					r_th_lock_enter (th->user);
				}
				nptr = strchr (ptr, '\n');
				if (nptr) {
					*nptr = 0;
				}
				r_core_cmd (&r, ptr, 0);
				if (nptr) {
					ptr = nptr + 1;
				}
				if (th) {
					r_th_lock_leave (th->user);
				}
			} while (nptr);
		}
		//r_core_cmd (&r, cmd, 0);
		r_str_free (rabin_cmd);
		rabin_cmd = NULL;
	}
	if (th) eprintf ("rabin2: done\n");
	return 0;
}
Exemplo n.º 2
0
static RThreadFunctionRet rabin_delegate(RThread *th) {
	RIODesc *d = r_io_desc_get (r.io, r.file->fd);
	if (rabin_cmd && r_file_exists (d->name)) {
		char *nptr, *ptr, *cmd = r_sys_cmd_str (rabin_cmd, NULL, NULL);
		ptr = cmd;
		if (ptr) {
			do {
				if (th) {
					r_th_lock_enter (th->user);
				}
				nptr = strchr (ptr, '\n');
				if (nptr) {
					*nptr = 0;
				}
				r_core_cmd (&r, ptr, 0);
				if (nptr) {
					ptr = nptr + 1;
				}
				if (th) {
					r_th_lock_leave (th->user);
				}
			} while (nptr);
		}
		//r_core_cmd (&r, cmd, 0);
		free (rabin_cmd);
		rabin_cmd = NULL;
	}
	if (th) {
		eprintf ("rabin2: done\n");
	}
	return R_TH_STOP;
}
Exemplo n.º 3
0
static DWORD WINAPI _r_th_launcher(void *_th) {
#else
static void *_r_th_launcher(void *_th) {
#endif
	int ret;
	RThread *th = _th;
	th->ready = true;
#if __UNIX__
	if (th->delay > 0) {
		sleep (th->delay);
	} else if (th->delay < 0) {
		r_th_lock_wait (th->lock);
	}
#else
	if (th->delay < 0) {
		r_th_lock_wait (th->lock);
	}
#endif
	do {
		// CID 1378280:  API usage errors  (LOCK)
		// "r_th_lock_leave" unlocks "th->lock->lock" while it is unlocked.
		r_th_lock_leave (th->lock);
		th->running = true;
		ret = th->fun (th);
		th->running = false;
		r_th_lock_enter (th->lock);
	} while (ret);
#if HAVE_PTHREAD
	pthread_exit (&ret);
#endif
	return 0;
}
Exemplo n.º 4
0
static DWORD WINAPI _r_th_launcher(void *_th) {
#else
static void *_r_th_launcher(void *_th) {
#endif
	int ret;
	RThread *th = _th;
	th->ready = true;
#if __UNIX__
	if (th->delay > 0) {
		sleep (th->delay);
	} else if (th->delay < 0) {
		r_th_lock_wait (th->lock);
	}
#else
	if (th->delay < 0) {
		r_th_lock_wait (th->lock);
	}
#endif
	r_th_lock_enter (th->lock);
	do {
		r_th_lock_leave (th->lock);
		th->running = true;
		ret = th->fun (th);
		th->running = false;
		r_th_lock_enter (th->lock);
	} while (ret);
#if HAVE_PTHREAD
	pthread_exit (&ret);
#endif
	return 0;
}
Exemplo n.º 5
0
R_API int r_th_lock_wait(RThreadLock *thl) {
#if HAVE_PTHREAD
	r_th_lock_enter (thl); // locks here
	r_th_lock_leave (thl); // releases previous mutex
#elif __WIN32__ || __WINDOWS__ && !defined(__CYGWIN__)
	WaitForSingleObject (thl->lock, INFINITE);
#else
	while (r_th_lock_check (thl));
#endif
	return 0;
}
Exemplo n.º 6
0
R_API int r_th_lock_wait(struct r_th_lock_t *thl) {
#if HAVE_PTHREAD
	r_th_lock_enter (thl);
	r_th_lock_enter (thl); // locks here
	r_th_lock_leave (thl); // releases previous mutex
#elif __WIN32__
	WaitForSingleObject (thl->lock, INFINITE);
#else
	while (r_th_lock_check ());
#endif
	return 0;
}
Exemplo n.º 7
0
R_API bool r_th_start(RThread *th, int enable) {
	bool ret = true;
	if (enable) {
		if (!th->running) {
			// start thread
			while (!th->ready) {
				/* spinlock */
			}
			r_th_lock_leave (th->lock);
		}
	} else {
		if (th->running) {
			// stop thread
			//r_th_kill (th, 0);
			r_th_lock_enter (th->lock); // deadlock?
		}
	}
	th->running = enable;
	return ret;
}
Exemplo n.º 8
0
R_API int r_th_push_task(struct r_th_t *th, void *user) {
	int ret = true;
	th->user = user;
	r_th_lock_leave (th->lock);
	return ret;
}
Exemplo n.º 9
0
R_API int r_th_lock_wait(RThreadLock *thl) {
	r_th_lock_enter (thl); // locks here
	r_th_lock_leave (thl); // releases previous mutex
	return 0;
}