Remove pthreads from shell.c and update bsd build.

This commit is contained in:
Calvin Rose 2020-12-06 13:51:06 -06:00
parent 01120dfc46
commit 785757f2f6
2 changed files with 30 additions and 46 deletions

View File

@ -5,27 +5,27 @@ packages:
- gmake
- meson
tasks:
- build: |
cd janet # Makefile testing on BSD.
- gmake: |
cd janet
gmake
gmake test
doas gmake install
gmake test-install
doas gmake uninstall
rm -rf build # clean up
meson setup build --buildtype=release -Dsingle_threaded=true -Dnanbox=false -Ddynamic_modules=false -Ddocstrings=false -Dnet=false -Dsourcemaps=false -Dpeg=false -Dassembler=false -Dint_types=false -Dtyped_array=false -Dreduced_os=true # meson minimum build
cd build
ninja # will not pass tests but should build
cd ..
rm -rf build # clean up
meson setup build --buildtype=release -Dprf=true # meson (with prf)
cd build
- meson_min: |
cd janet
meson setup build_meson_min --buildtype=release -Dsingle_threaded=true -Dnanbox=false -Ddynamic_modules=false -Ddocstrings=false -Dnet=false -Dsourcemaps=false -Dpeg=false -Dassembler=false -Dint_types=false -Dtyped_array=false -Dreduced_os=true
cd build_meson_min
ninja
- meson_prf: |
cd janet
meson setup build_meson_prf --buildtype=release -Dprf=true
cd build_meson_prf
ninja
ninja test
cd ..
rm -rf build
meson setup build --buildtype=release # meson (default build)
cd build
- meson_default: |
cd janet
meson setup build_meson_default --buildtype=release
cd build_meson_default
ninja
ninja test
doas ninja install

View File

@ -126,28 +126,21 @@ https://github.com/antirez/linenoise/blob/master/linenoise.c
#define JANET_LINE_MAX 1024
#define JANET_MATCH_MAX 256
#define JANET_HISTORY_MAX 100
static int gbl_israwmode = 0;
static const char *gbl_prompt = "> ";
static int gbl_plen = 2;
static char gbl_buf[JANET_LINE_MAX];
static int gbl_len = 0;
static int gbl_pos = 0;
static int gbl_cols = 80;
static char *gbl_history[JANET_HISTORY_MAX];
static int gbl_history_count = 0;
static int gbl_historyi = 0;
static int gbl_sigint_flag = 0;
static struct termios gbl_termios_start;
static JanetByteView gbl_matches[JANET_MATCH_MAX];
static int gbl_match_count = 0;
static int gbl_lines_below = 0;
/* Put a lock around this global state so we don't screw up
* the terminal in a multithreaded situation */
#ifndef JANET_SINGLE_THREADED
#include <pthread.h>
static pthread_mutex_t gbl_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
JANET_THREAD_LOCAL static int gbl_israwmode = 0;
JANET_THREAD_LOCAL static const char *gbl_prompt = "> ";
JANET_THREAD_LOCAL static int gbl_plen = 2;
JANET_THREAD_LOCAL static char gbl_buf[JANET_LINE_MAX];
JANET_THREAD_LOCAL static int gbl_len = 0;
JANET_THREAD_LOCAL static int gbl_pos = 0;
JANET_THREAD_LOCAL static int gbl_cols = 80;
JANET_THREAD_LOCAL static char *gbl_history[JANET_HISTORY_MAX];
JANET_THREAD_LOCAL static int gbl_history_count = 0;
JANET_THREAD_LOCAL static int gbl_historyi = 0;
JANET_THREAD_LOCAL static int gbl_sigint_flag = 0;
JANET_THREAD_LOCAL static struct termios gbl_termios_start;
JANET_THREAD_LOCAL static JanetByteView gbl_matches[JANET_MATCH_MAX];
JANET_THREAD_LOCAL static int gbl_match_count = 0;
JANET_THREAD_LOCAL static int gbl_lines_below = 0;
/* Unsupported terminal list from linenoise */
static const char *badterms[] = {
@ -169,9 +162,6 @@ static char *sdup(const char *s) {
/* Ansi terminal raw mode */
static int rawmode(void) {
struct termios t;
#ifndef JANET_SINGLE_THREADED
pthread_mutex_lock(&gbl_lock);
#endif
if (!isatty(STDIN_FILENO)) goto fatal;
if (tcgetattr(STDIN_FILENO, &gbl_termios_start) == -1) goto fatal;
t = gbl_termios_start;
@ -185,9 +175,6 @@ static int rawmode(void) {
return 0;
fatal:
errno = ENOTTY;
#ifndef JANET_SINGLE_THREADED
pthread_mutex_unlock(&gbl_lock);
#endif
return -1;
}
@ -195,9 +182,6 @@ fatal:
static void norawmode(void) {
if (gbl_israwmode && tcsetattr(STDIN_FILENO, TCSADRAIN, &gbl_termios_start) != -1)
gbl_israwmode = 0;
#ifndef JANET_SINGLE_THREADED
pthread_mutex_unlock(&gbl_lock);
#endif
}
static int curpos(void) {