devdraw: can use libthread directly now on macOS
This commit is contained in:
parent
db20f89c32
commit
ce27d7babd
5 changed files with 13 additions and 79 deletions
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
#include <u.h>
|
#include <u.h>
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
#include "cocoa-thread.h"
|
#include <thread.h>
|
||||||
#include <draw.h>
|
#include <draw.h>
|
||||||
#include <memdraw.h>
|
#include <memdraw.h>
|
||||||
#include <keyboard.h>
|
#include <keyboard.h>
|
||||||
|
|
@ -41,8 +41,8 @@ usage(void)
|
||||||
threadexitsall("usage");
|
threadexitsall("usage");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@interface AppDelegate : NSObject<NSApplicationDelegate,NSWindowDelegate>
|
@interface AppDelegate : NSObject<NSApplicationDelegate,NSWindowDelegate>
|
||||||
+ (void)callservep9p:(id)arg;
|
|
||||||
+ (void)makewin:(NSValue *)v;
|
+ (void)makewin:(NSValue *)v;
|
||||||
+ (void)callkicklabel:(NSString *)v;
|
+ (void)callkicklabel:(NSString *)v;
|
||||||
+ (void)callsetNeedsDisplayInRect:(NSValue *)v;
|
+ (void)callsetNeedsDisplayInRect:(NSValue *)v;
|
||||||
|
|
@ -108,14 +108,18 @@ threadmain(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@implementation AppDelegate
|
|
||||||
|
|
||||||
+ (void)callservep9p:(id)arg
|
void
|
||||||
|
callservep9p(void *v)
|
||||||
{
|
{
|
||||||
|
USED(v);
|
||||||
|
|
||||||
servep9p();
|
servep9p();
|
||||||
[NSApp terminate:self];
|
[NSApp terminate:myApp];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@implementation AppDelegate
|
||||||
|
|
||||||
+ (void)makewin:(NSValue *)v
|
+ (void)makewin:(NSValue *)v
|
||||||
{
|
{
|
||||||
NSRect r, sr;
|
NSRect r, sr;
|
||||||
|
|
@ -331,9 +335,7 @@ struct Cursors {
|
||||||
[NSApp setApplicationIconImage:i];
|
[NSApp setApplicationIconImage:i];
|
||||||
[[NSApp dockTile] display];
|
[[NSApp dockTile] display];
|
||||||
|
|
||||||
[NSThread
|
proccreate(callservep9p, nil, 0);
|
||||||
detachNewThreadSelector:@selector(callservep9p:)
|
|
||||||
toTarget:[self class] withObject:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSApplicationPresentationOptions)window:(id)arg
|
- (NSApplicationPresentationOptions)window:(id)arg
|
||||||
|
|
@ -671,6 +673,7 @@ struct Cursors {
|
||||||
if(actualRange)
|
if(actualRange)
|
||||||
*actualRange = sr;
|
*actualRange = sr;
|
||||||
LOG(@"use range: %ld, %ld", sr.location, sr.length);
|
LOG(@"use range: %ld, %ld", sr.location, sr.length);
|
||||||
|
s = nil;
|
||||||
if(sr.length)
|
if(sr.length)
|
||||||
s = [[NSAttributedString alloc]
|
s = [[NSAttributedString alloc]
|
||||||
initWithString:[_tmpText substringWithRange:sr]];
|
initWithString:[_tmpText substringWithRange:sr]];
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include <u.h>
|
#include <u.h>
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
#include "cocoa-thread.h"
|
#include <thread.h>
|
||||||
#include <draw.h>
|
#include <draw.h>
|
||||||
#include <memdraw.h>
|
#include <memdraw.h>
|
||||||
#include <keyboard.h>
|
#include <keyboard.h>
|
||||||
|
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
#include <u.h>
|
|
||||||
#include <libc.h>
|
|
||||||
#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
|
|
||||||
|
|
@ -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 <thread.h>
|
|
||||||
#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
|
|
||||||
|
|
@ -53,7 +53,7 @@ if [ $WSYSTYPE = x11 ]; then
|
||||||
echo 'WSYSOFILES=$WSYSOFILES '$XO
|
echo 'WSYSOFILES=$WSYSOFILES '$XO
|
||||||
elif [ $WSYSTYPE = osx-cocoa ]; then
|
elif [ $WSYSTYPE = osx-cocoa ]; then
|
||||||
echo 'OBJCFLAGS=$OBJCFLAGS -fobjc-arc'
|
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'
|
echo 'MACARGV=macargv.o'
|
||||||
elif [ $WSYSTYPE = nowsys ]; then
|
elif [ $WSYSTYPE = nowsys ]; then
|
||||||
echo 'WSYSOFILES=nowsys.o'
|
echo 'WSYSOFILES=nowsys.o'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue