Further improve ipv4.games server

This commit is contained in:
Justine Tunney 2022-10-03 15:05:33 -07:00
parent 3b4fcd8575
commit 32321ab1e9
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
9 changed files with 307 additions and 113 deletions

View file

@ -52,6 +52,9 @@ enum PosixThreadStatus {
// - kPosixThreadZombie -> _pthread_free() will happen whenever
// convenient, e.g. pthread_create() entry or atexit handler.
kPosixThreadZombie,
// special main thread
kPosixThreadMain,
};
struct PosixThread {

View file

@ -36,7 +36,8 @@
*/
wontreturn void pthread_exit(void *rc) {
struct PosixThread *pt;
if ((pt = (struct PosixThread *)__get_tls()->tib_pthread)) {
pt = (struct PosixThread *)pthread_self();
if (pt->status != kPosixThreadMain) {
pt->rc = rc;
_gclongjmp(pt->exiter, 1);
} else {

View file

@ -29,7 +29,7 @@
*/
int pthread_join(pthread_t thread, void **value_ptr) {
struct PosixThread *pt;
if (thread == __get_tls()->tib_pthread) {
if (thread == pthread_self()) {
return EDEADLK;
}
if (!(pt = (struct PosixThread *)thread) || //

View file

@ -16,6 +16,8 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/thread/posixthread.internal.h"
#include "libc/thread/thread.h"
#include "libc/thread/tls.h"
@ -25,3 +27,10 @@
pthread_t pthread_self(void) {
return __get_tls()->tib_pthread;
}
static struct PosixThread pthread_main;
__attribute__((__constructor__)) static void pthread_self_init(void) {
pthread_main.tid = gettid();
pthread_main.status = kPosixThreadMain;
__get_tls()->tib_pthread = (pthread_t)&pthread_main;
}