discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GWorkspace porting troubles


From: Enrico Sersale
Subject: Re: GWorkspace porting troubles
Date: Tue, 30 Oct 2001 12:55:56 +0200 (EET)

On Tue, 30 Oct 2001, Nicola Pero wrote:

>
> > I need a shared istance of the principal class of gworkspace to be
> > accessible through all the app.
> > So, since, when I started all the stuff, I was not thinking at any kind of
> > port :-) , I've used this method, (probably copied from a library class):
> >
> > ...
> >
>
> <untested, just as it comes from the heart>
>
> static volatile GWorkspace *gworkspace = nil;
> static NSLock *lock = nil;
>
> @implementation GWorkspace
>
> + (void) initialize
> {
>   lock = [NSLock new];
> }
>
> + (GWorkspace *)gworkspace
> {
>   if (gworkspace == nil)
>     {
>        [lock lock];
>        if (gworkspace == nil)
>          {
>            /* Make sure alloc/init never calls this
>               method otherwise you get a deadlock */
>            gworkspace = [[GWorkspace alloc] init];
>          }
>        [lock unlock];
>     }
>   return (GWorkspace *)gworkspace;
> }
> ...

This doesn't work because the GWorkspace class is subclass of NSWorkspace
and "you may not allocate a workspace directly".

It works if I change

gworkspace = [[GWorkspace alloc] init];

with:

gworkspace = (GWorkspace*)NSAllocateObject(self, 0, NSDefaultMallocZone());

is this acceptable for the porting?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]