commit ce27d7babdf2ee09ff6d1f8d4a166c2208995774 from: Russ Cox date: Mon Jan 13 21:46:14 2020 UTC devdraw: can use libthread directly now on macOS commit - db20f89c3286f277945ac4307f789a9980d31bf6 commit + ce27d7babdf2ee09ff6d1f8d4a166c2208995774 blob - 984ede03385731021a5e00263c5ffec54a7f1341 blob + 64b2bf4c581c63789f8cff04c5e4671d3aaef464 --- src/cmd/devdraw/cocoa-screen.m +++ src/cmd/devdraw/cocoa-screen.m @@ -12,7 +12,7 @@ #include #include -#include "cocoa-thread.h" +#include #include #include #include @@ -41,8 +41,8 @@ usage(void) threadexitsall("usage"); } + @interface AppDelegate : NSObject -+ (void)callservep9p:(id)arg; + (void)makewin:(NSValue *)v; + (void)callkicklabel:(NSString *)v; + (void)callsetNeedsDisplayInRect:(NSValue *)v; @@ -108,13 +108,17 @@ threadmain(int argc, char **argv) } } -@implementation AppDelegate -+ (void)callservep9p:(id)arg +void +callservep9p(void *v) { - servep9p(); - [NSApp terminate:self]; + USED(v); + + servep9p(); + [NSApp terminate:myApp]; } + +@implementation AppDelegate + (void)makewin:(NSValue *)v { @@ -331,9 +335,7 @@ struct Cursors { [NSApp setApplicationIconImage:i]; [[NSApp dockTile] display]; - [NSThread - detachNewThreadSelector:@selector(callservep9p:) - toTarget:[self class] withObject:nil]; + proccreate(callservep9p, nil, 0); } - (NSApplicationPresentationOptions)window:(id)arg @@ -671,6 +673,7 @@ struct Cursors { if(actualRange) *actualRange = sr; LOG(@"use range: %ld, %ld", sr.location, sr.length); + s = nil; if(sr.length) s = [[NSAttributedString alloc] initWithString:[_tmpText substringWithRange:sr]]; blob - dcb1801ac2c6f9947469959a9b5f7fefbc3291ba blob + 2211a06f75a0cbb29313c811a4940a86371b5605 --- src/cmd/devdraw/cocoa-srv.c +++ src/cmd/devdraw/cocoa-srv.c @@ -4,7 +4,7 @@ #include #include -#include "cocoa-thread.h" +#include #include #include #include blob - 92b92d2cf855ea4625d82bd89f297a8cf82d7449 (mode 644) blob + /dev/null --- src/cmd/devdraw/cocoa-thread.c +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include "cocoa-thread.h" - -#ifndef TRY_LIBTHREAD - -static pthread_mutex_t initlock = PTHREAD_MUTEX_INITIALIZER; - -void -qlock(QLock *q) -{ - if(q->init == 0){ - pthread_mutex_lock(&initlock); - if(q->init == 0){ - pthread_mutex_init(&q->m, nil); - q->init = 1; - } - pthread_mutex_unlock(&initlock); - } - pthread_mutex_lock(&q->m); -} - -void -qunlock(QLock *q) -{ - pthread_mutex_unlock(&q->m); -} - -int -threadid(void) -{ - return pthread_mach_thread_np(pthread_self()); -} - -#endif blob - d5793f0a70a3e9cefd6c220217aaf53792945130 (mode 644) blob + /dev/null --- src/cmd/devdraw/cocoa-thread.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * I am too ignorant to know if Cocoa and Libthread - * can coexist: if I try to include thread.h, now - * that Devdraw uses Cocoa's threads (and timers), it - * crashes immediately; when Devdraw was using - * proccreate(), it could run a little while before to - * crash; the origin of those crashes is hard to - * ascertain, because other programs using Libthread - * (such as 9term, Acme, Plumber, and Sam) currently - * don't run when compiled with Xcode 4.1. - */ -//#define TRY_LIBTHREAD - -#ifdef TRY_LIBTHREAD - #include -#else - #define QLock DQLock - #define qlock dqlock - #define qunlock dqunlock - #define threadexitsall exits - #define threadmain main - - typedef struct QLock QLock; - - struct QLock - { - int init; - pthread_mutex_t m; - }; - - void qlock(QLock*); - void qunlock(QLock*); - int threadid(void); -#endif blob - 8ab67f76f4bb3459f79a30b561fc2be2230d77d6 blob + 839ebab302b429750cd357476a333c990f65a5b7 --- src/cmd/devdraw/mkwsysrules.sh +++ src/cmd/devdraw/mkwsysrules.sh @@ -53,7 +53,7 @@ if [ $WSYSTYPE = x11 ]; then echo 'WSYSOFILES=$WSYSOFILES '$XO elif [ $WSYSTYPE = osx-cocoa ]; then echo 'OBJCFLAGS=$OBJCFLAGS -fobjc-arc' - echo 'WSYSOFILES=$WSYSOFILES osx-draw.o cocoa-screen.o cocoa-srv.o cocoa-thread.o' + echo 'WSYSOFILES=$WSYSOFILES osx-draw.o cocoa-screen.o cocoa-srv.o' echo 'MACARGV=macargv.o' elif [ $WSYSTYPE = nowsys ]; then echo 'WSYSOFILES=nowsys.o'