links

lynx-like text mode web browser
git clone anongit@rnpnr.xyz:links.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 379afe935c0c4c8873748ca522b336eabd553cce
Parent: 8f066a6faa646ec951139aedee90405d47462445
Author: opask
Date:   Fri, 27 Jul 2018 21:56:26 -0600

remove PoSix threads (finish removal of config.h)

Diffstat:
MTODO | 2--
Dconfig.h | 5-----
Mconfig.mk | 2+-
Mlinks.h | 51---------------------------------------------------
Mos_dep.c | 220+++----------------------------------------------------------------------------
Mselect.c | 10+++++-----
6 files changed, 12 insertions(+), 278 deletions(-)

diff --git a/TODO b/TODO @@ -6,8 +6,6 @@ - pledge(2) for OpenBSD -- finish removal of config.h so it can be used for actual configuration - - cleanup empty functions - finish language cleanup diff --git a/config.h b/config.h @@ -1,5 +0,0 @@ -/* Define if you have the pthread_sigmask function. */ -#define HAVE_PTHREAD_SIGMASK 1 - -/* */ -#define HAVE_SIGFILLSET 1 diff --git a/config.mk b/config.mk @@ -10,7 +10,7 @@ INCS = -I. -I/usr/include -I$(X11INC) LIBS = -L$(X11LIB) -L/usr/lib -lX11 -levent -lpng -ljpeg -lcrypto -lssl -lz CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_BSD_SOURCE -CFLAGS = -O2 -std=c99 -Wall -pedantic -include config.h \ +CFLAGS = -O2 -std=c99 -Wall -pedantic \ -DG=1 \ -DHAVE_JPEG=1 -DHAVE_LIBJPEG=1 -DHAVE_JPEGLIB_H=1 \ -DHAVE_PNG_H=1 -DHAVE_LIBPNG=1 -DHAVE_LIBPNG_PNG_H=1 diff --git a/links.h b/links.h @@ -115,57 +115,6 @@ do { \ (ret_) = (call_); \ } while (!(ret_) && errno == EINTR) -#if defined(HAVE_PTHREAD_SIGMASK) -static inline int do_sigprocmask(int how, const sigset_t *set, sigset_t *oset) -{ - int r; - r = pthread_sigmask(how, set, oset); - if (r) { - errno = r; - return -1; - } - return 0; -} -#else /* if !defined(HAVE_PTHREAD_SIGMASK) */ -#define do_sigprocmask sigprocmask -#define sigset_t int -#ifndef SIG_BLOCK -#define SIG_BLOCK 0 -#endif -#ifndef SIG_SETMASK -#define SIG_SETMASK 2 -#endif -static inline int do_sigprocmask(int how, const sigset_t *set, sigset_t *oset) -{ - sigset_t old = 0; - switch (how) { - case SIG_BLOCK: - old = sigblock(*set); - break; - case SIG_SETMASK: - old = sigsetmask(*set); - break; - } - if (oset) - *oset = old; - return 0; -} -#ifdef sigdelset -#undef sigdelset -#endif -#define sigdelset(x, s) (*(x) &= ~(1 << (s)), 0) -#ifdef HAVE_SIGFILLSET -#undef HAVE_SIGFILLSET -#endif -#endif /* defined(HAVE_PTHREAD_SIGMASK) */ - -#ifdef HAVE_SIGFILLSET -static inline void sig_fill_set(sigset_t *set) -{ - sigfillset(set); -} -#endif - #define option option_dirty_workaround_for_name_clash_with_include_on_cygwin #define table table_dirty_workaround_for_name_clash_with_libraries_on_macos #define scroll scroll_dirty_workaround_for_name_clash_with_libraries_on_macos diff --git a/os_dep.c b/os_dep.c @@ -7,32 +7,8 @@ #include <sys/ioctl.h> -#ifdef HAVE_PTHREADS -#include <pthread.h> - -static pthread_mutex_t pth_mutex; -static void fd_lock(void); -static void fd_unlock(void); -static void fd_init(void) -{ - int r; - r = pthread_mutex_init(&pth_mutex, NULL); - if (r) - fatal_exit("pthread_mutex_create failed: %s", strerror(r)); -} -#endif - void init_os(void) { -#if defined(HAVE_PTHREADS) - { - int r; - fd_init(); - r = pthread_atfork(fd_lock, fd_unlock, fd_init); - if (r) - fatal_exit("pthread_atfork failed: %s", strerror(r)); - } -#endif } int is_safe_in_shell(unsigned char c) @@ -196,31 +172,9 @@ int get_terminal_size(int fd, int *x, int *y) return 0; } -#if defined(HAVE_PTHREADS) - -static void fd_lock(void) -{ - int r; - r = pthread_mutex_lock(&pth_mutex); - if (r) - fatal_exit("pthread_mutex_lock failed: %s", strerror(r)); -} - -static void fd_unlock(void) -{ - int r; - r = pthread_mutex_unlock(&pth_mutex); - if (r) - fatal_exit("pthread_mutex_lock failed: %s", strerror(r)); -} - -#else - #define fd_lock() do { } while (0) #define fd_unlock() do { } while (0) -#endif - static void new_fd_cloexec(int fd) { int rs; @@ -469,130 +423,6 @@ unsigned char *get_window_title(void) /* Threads */ -#if defined(HAVE_PTHREADS) - -struct tdata { - void (*fn)(void *, int); - int h; - int counted; - unsigned char data[1]; -}; - -static void bgt(void *t_) -{ - struct tdata *t = t_; - int rs; - ignore_signals(); - t->fn(t->data, t->h); - EINTRLOOP(rs, (int)write(t->h, "x", 1)); - EINTRLOOP(rs, close(t->h)); - free(t); -} - -#endif - -#if defined(HAVE_PTHREADS) - -static unsigned thread_count = 0; - -static inline void reset_thread_count(void) -{ - fd_lock(); - thread_count = 0; - fd_unlock(); -} - -static void inc_thread_count(void) -{ - fd_lock(); - thread_count++; - fd_unlock(); -} - -static void dec_thread_count(void) -{ - fd_lock(); - if (!thread_count) - internal("thread_count underflow"); - thread_count--; - fd_unlock(); -} - -static inline unsigned get_thread_count(void) -{ - unsigned val; - fd_lock(); - val = thread_count; - fd_unlock(); - return val; -} - -static void *bgpt(void *t) -{ - int counted = ((struct tdata *)t)->counted; - bgt(t); - if (counted) dec_thread_count(); - return NULL; -} - -int start_thread(void (*fn)(void *, int), void *ptr, int l, int counted) -{ - pthread_attr_t attr; - pthread_t thread; - struct tdata *t; - int p[2]; - int rs; - if (c_pipe(p) < 0) return -1; - retry1: - if (!(t = malloc(sizeof(struct tdata) + l))) { - if (out_of_memory(0, NULL, 0)) - goto retry1; - goto err1; - } - t->fn = fn; - t->h = p[1]; - t->counted = counted; - memcpy(t->data, ptr, l); - retry2: - if (pthread_attr_init(&attr)) { - if (out_of_memory(0, NULL, 0)) - goto retry2; - goto err2; - } - retry3: - if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED)) { - if (out_of_memory(0, NULL, 0)) - goto retry3; - goto err3; - } -#ifdef THREAD_NEED_STACK_SIZE - retry4: - if (pthread_attr_setstacksize(&attr, THREAD_NEED_STACK_SIZE)) { - if (out_of_memory(0, NULL, 0)) - goto retry4; - goto err3; - } -#endif - if (counted) inc_thread_count(); - if (pthread_create(&thread, &attr, bgpt, t)) { - if (counted) dec_thread_count(); - goto err3; - } - pthread_attr_destroy(&attr); - return p[0]; - - err3: - pthread_attr_destroy(&attr); - err2: - free(t); - err1: - EINTRLOOP(rs, close(p[0])); - EINTRLOOP(rs, close(p[1])); - return -1; -} - -#else /* HAVE_BEGINTHREAD */ - int start_thread(void (*fn)(void *, int), void *ptr, int l, int counted) { int p[2]; @@ -617,8 +447,6 @@ int start_thread(void (*fn)(void *, int), void *ptr, int l, int counted) return p[0]; } -#endif - void want_draw(void) {} void done_draw(void) {} @@ -626,35 +454,11 @@ int get_output_handle(void) { return 1; } int get_ctl_handle(void) { return 0; } -#if defined(HAVE_BEGINTHREAD) && defined(HAVE__READ_KBD) - -int get_input_handle(void) -{ - int rs; - int fd[2]; - if (ti != -1) return ti; - if (is_xterm()) return 0; - if (c_pipe(fd) < 0) return 0; - ti = fd[0]; - tp = fd[1]; - if (_beginthread(input_thread, NULL, 0x10000, (void *)tp) == -1) { - EINTRLOOP(rs, close(fd[0])); - EINTRLOOP(rs, close(fd[1])); - return 0; - } - return fd[0]; -} - -#else - int get_input_handle(void) { return 0; } -#endif /* defined(HAVE_BEGINTHREAD) && defined(HAVE__READ_KBD) */ - - static void exec_new_links(struct terminal *term, unsigned char *xterm, unsigned char *exe, unsigned char *param) { unsigned char *str; @@ -781,23 +585,11 @@ void os_seed_random(unsigned char **pool, int *pool_size) void os_detach_console(void) { #if !defined(NO_FORK_ON_EXIT) - { - pid_t rp; - EINTRLOOP(rp, fork()); - if (!rp) { - reinit_child(); -#if defined(HAVE_PTHREADS) - reset_thread_count(); -#endif - } - if (rp > 0) { -#if defined(HAVE_PTHREADS) - while (get_thread_count()) { - portable_sleep(1000); - } -#endif - _exit(0); - } - } + pid_t rp; + EINTRLOOP(rp, fork()); + if (!rp) + reinit_child(); + if (rp > 0) + _exit(0); #endif } diff --git a/select.c b/select.c @@ -677,7 +677,7 @@ void install_signal_handler(int sig, void (*fn)(void *), void *data, int critica } if (!fn) sa.sa_handler = SIG_IGN; else sa.sa_handler = (void (*)(int))got_signal; - sig_fill_set(&sa.sa_mask); + sigfillset(&sa.sa_mask); sa.sa_flags = SA_RESTART; if (!fn) EINTRLOOP(rs, sigaction(sig, &sa, NULL)); @@ -699,7 +699,7 @@ void interruptible_signal(int sig, int in) } if (!signal_handlers[sig].fn) return; sa.sa_handler = (void (*)(int))got_signal; - sig_fill_set(&sa.sa_mask); + sigfillset(&sa.sa_mask); if (!in) sa.sa_flags = SA_RESTART; EINTRLOOP(rs, sigaction(sig, &sa, NULL)); #endif @@ -712,7 +712,7 @@ void block_signals(int except1, int except2) { int rs; sigset_t mask; - sig_fill_set(&mask); + sigfillset(&mask); if (except1) sigdelset(&mask, except1); if (except2) sigdelset(&mask, except2); #ifdef SIGILL @@ -730,7 +730,7 @@ void block_signals(int except1, int except2) #ifdef SIGBUS sigdelset(&mask, SIGBUS); #endif - EINTRLOOP(rs, do_sigprocmask(SIG_BLOCK, &mask, &sig_old_mask)); + EINTRLOOP(rs, sigprocmask(SIG_BLOCK, &mask, &sig_old_mask)); if (!rs) sig_unblock = 1; } @@ -738,7 +738,7 @@ void unblock_signals(void) { int rs; if (sig_unblock) { - EINTRLOOP(rs, do_sigprocmask(SIG_SETMASK, &sig_old_mask, NULL)); + EINTRLOOP(rs, sigprocmask(SIG_SETMASK, &sig_old_mask, NULL)); sig_unblock = 0; } }