From 0907149b35a4474e9c985048d78a861eb9854be0 Mon Sep 17 00:00:00 2001 From: deuce <> Date: Tue, 29 Apr 2003 04:01:39 +0000 Subject: [PATCH] Define YIELD() macro to yield the CPU --- src/sbbs3/answer.cpp | 4 +--- src/sbbs3/inkey.cpp | 4 +--- src/sbbs3/main.cpp | 24 ++++++------------------ src/sbbs3/ringbuf.c | 12 +++--------- src/xpdev/genwrap.h | 4 ++-- src/xpdev/threadwrap.h | 6 ++++++ 6 files changed, 19 insertions(+), 35 deletions(-) diff --git a/src/sbbs3/answer.cpp b/src/sbbs3/answer.cpp index 5e0c29ce1d..8388eb4d79 100644 --- a/src/sbbs3/answer.cpp +++ b/src/sbbs3/answer.cpp @@ -132,9 +132,7 @@ bool sbbs_t::answer() strcat(str,COPYRIGHT_NOTICE); strip_ctrl(str); center(str); - #if defined(_PTH_H_) /* Cooperative multitasking! */ - pth_yield(NULL); - #endif + YIELD(); while(i++<50 && l<(int)sizeof(str)-1) { /* wait up to 5 seconds for response */ c=(incom()&0x7f); diff --git a/src/sbbs3/inkey.cpp b/src/sbbs3/inkey.cpp index f5604bdaad..90592c7ece 100644 --- a/src/sbbs3/inkey.cpp +++ b/src/sbbs3/inkey.cpp @@ -49,9 +49,7 @@ char sbbs_t::inkey(long mode) { uchar ch=0; - #if defined(_PTH_H_) /* Cooperative multitasking! */ - pth_yield(NULL); - #endif + YIELD(); if(keybuftop!=keybufbot) { ch=keybuf[keybufbot++]; diff --git a/src/sbbs3/main.cpp b/src/sbbs3/main.cpp index 37a7754d18..fbec34cbe7 100644 --- a/src/sbbs3/main.cpp +++ b/src/sbbs3/main.cpp @@ -985,9 +985,7 @@ void input_thread(void *arg) while(sbbs->online && sbbs->client_socket!=INVALID_SOCKET && node_socket[sbbs->cfg.node_num-1]!=INVALID_SOCKET) { - #if defined(_PTH_H_) /* Cooperative multitasking! */ - pth_yield(NULL); - #endif + YIELD(); pthread_mutex_lock(&sbbs->input_thread_mutex); #ifdef __unix__ @@ -1201,9 +1199,7 @@ void output_thread(void* arg) sbbs->console|=CON_R_ECHO; while(sbbs->client_socket!=INVALID_SOCKET && telnet_socket!=INVALID_SOCKET) { - #if defined(_PTH_H_) /* Cooperative multitasking! */ - pth_yield(NULL); - #endif + YIELD(); if(bufbot==buftop) avail=RingBufFull(&sbbs->outbuf); @@ -2722,9 +2718,7 @@ int sbbs_t::incom(void) { uchar ch; -#if defined(_PTH_H_) /* Cooperative multitasking! */ - pth_yield(NULL); -#endif + YIELD(); if(!RingBufRead(&inbuf, &ch, 1)) return(NOINP); #if 0 // removed Jan-2003 @@ -2743,9 +2737,7 @@ int sbbs_t::outcom(uchar ch) return(TXBOF); sem_post(&output_sem); return(0); -#if defined(_PTH_H_) /* Cooperative multitasking! */ - pth_yield(NULL); -#endif + YIELD(); } void sbbs_t::putcom(char *str, int len) @@ -3094,9 +3086,7 @@ void node_thread(void* arg) if(sbbs->exec(&sbbs->main_csi)) break; - #if defined(_PTH_H_) /* Cooperative multitasking! */ - pth_yield(NULL); - #endif + YIELD(); } } @@ -3824,9 +3814,7 @@ void DLLCALL bbs_thread(void* arg) } while(telnet_socket!=INVALID_SOCKET) { - #if defined(_PTH_H_) /* Cooperative multitasking! */ - pth_yield(NULL); - #endif + YIELD(); if(node_threads_running==0 && !event_mutex_locked) { /* check for re-run flags */ bool rerun=false; diff --git a/src/sbbs3/ringbuf.c b/src/sbbs3/ringbuf.c index f495907291..06eab9c925 100644 --- a/src/sbbs3/ringbuf.c +++ b/src/sbbs3/ringbuf.c @@ -186,9 +186,7 @@ DWORD RINGBUFCALL RingBufWrite( RingBuf* rb, BYTE* src, DWORD cnt ) pthread_mutex_unlock(&rb->mutex); #endif -#if defined(_PTH_H_) /* Cooperative multitasking! */ - pth_yield(NULL); -#endif + YIELD(); return(cnt); } @@ -198,9 +196,7 @@ DWORD RINGBUFCALL RingBufRead( RingBuf* rb, BYTE* dst, DWORD cnt ) { DWORD max, first, remain, len; -#if defined(_PTH_H_) /* Cooperative multitasking! */ - pth_yield(NULL); -#endif + YIELD(); len = RingBufFull( rb ); if( len == 0 ) @@ -252,9 +248,7 @@ DWORD RINGBUFCALL RingBufPeek( RingBuf* rb, BYTE* dst, DWORD cnt) { DWORD max, first, remain, len; -#if defined(_PTH_H_) /* Cooperative multitasking! */ - pth_yield(NULL); -#endif + YIELD(); len = RingBufFull( rb ); if( len == 0 ) diff --git a/src/xpdev/genwrap.h b/src/xpdev/genwrap.h index b8aedaf3cc..2b1da26dee 100644 --- a/src/xpdev/genwrap.h +++ b/src/xpdev/genwrap.h @@ -176,11 +176,11 @@ extern "C" { #ifndef SLEEP #ifndef SBBS - #define pthread_yield() + #define YIELD() #endif #define SLEEP(x) ({ int y=x; struct timeval tv; \ tv.tv_sec=(y/1000); tv.tv_usec=((y%1000)*1000); \ - pthread_yield(); \ + YIELD(); \ select(0,NULL,NULL,NULL,&tv); }) #endif #define BEEP(freq,dur) unix_beep(freq,dur) diff --git a/src/xpdev/threadwrap.h b/src/xpdev/threadwrap.h index 6f414977f5..104fd9b00e 100644 --- a/src/xpdev/threadwrap.h +++ b/src/xpdev/threadwrap.h @@ -49,6 +49,11 @@ extern "C" { #include <sys/param.h> #include <pthread.h> /* POSIX threads and mutexes */ +#ifdef __linux__ + #define YIELD() sched_yield() +#else + #define YIELD() pthread_yield() +#endif #if defined(_NEED_SEM) #include "sem.h" #else @@ -122,6 +127,7 @@ extern "C" { #define SLEEP(x) ({ int y=x; struct timeval tv; \ tv.tv_sec=(y/1000); tv.tv_usec=((y%1000)*1000); \ pth_nap(tv); }) +#define YIELD() pth_yield(NULL) #endif #endif /* Don't add anything after this line */ -- GitLab