discuss-gnustep
[Top][All Lists]
Advanced

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

Re: GWorkspace porting troubles


From: Nicola Pero
Subject: Re: GWorkspace porting troubles
Date: Tue, 30 Oct 2001 09:47:07 +0000 (GMT)

> 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):
> 
> static GWorkspace *gworkspace = nil;
> 
> @implementation GWorkspace
> + (GWorkspace *)gworkspace
> {
>   if (gworkspace == nil) {
>     [gnustep_global_lock lock];
>     if (gworkspace == nil) {
>       gworkspace = (GWorkspace*)NSAllocateObject(self, 0,
> NSDefaultMallocZone());
>     }
>     [gnustep_global_lock unlock];
>   }
> 
>       return gworkspace;
> }
> 
> 
> I'm going to release a new version, with a recycler and more.
> If somebody suggest the right solution, I'll put in the new release.

<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;
}

...

@end





reply via email to

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