• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Cocoa class for queuing operations?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa class for queuing operations?


  • Subject: Re: Cocoa class for queuing operations?
  • From: Sherm Pendley <email@hidden>
  • Date: Fri, 15 Jul 2005 10:38:23 -0400

On Jul 14, 2005, at 5:26 PM, Jonathan del Strother wrote:

I wrote a texture loading class for my current project that sits in a separate thread, loading textures (duh). The main application sends a request for a new texture, I lock the queue, push the texture request onto the end, and unlock the queue. Meanwhile, the texture loader loops round and round, finds the next texture to load, loads it, removes it from the queue, and moves onto the next...

Today I started writing some code to queue up requests to send off to Amazon, and it occurred to me that I was writing pretty much the same code as my texture loader, and it must be a pretty common thing - there are uses for procedures like this all over the place.

So, I was wondering if there was a generic Cocoa class that already existed that I should be using... I've been searching the docs without finding anything, but I've duplicated whole swaths of pre- existing Cocoa code before, so was wondering if I'd missed anything.

Couldn't you simply add a Category to NSMutableArray, and use @synchronized blocks within your methods to coordinate access?


@implementation NSMutableArray (SPThreadsafeQueuing)

-(void)threadsafePush:(id)obj {
    @synchronized(self) {
        [self addObject:obj];
    }
}

-(id)threadsafeShift {
    @synchronized(self) {
        id obj = [self objectAtIndex:0];
        [self removeObjectAtIndex:0];
        return obj;
    }
}

@end

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Cocoa class for queuing operations?
      • From: Shaun Wexler <email@hidden>
References: 
 >Cocoa class for queuing operations? (From: Jonathan del Strother <email@hidden>)

  • Prev by Date: Re: Displaying multiple NSView subclasses
  • Next by Date: Re: Displaying multiple NSView subclasses
  • Previous by thread: Re: Cocoa class for queuing operations?
  • Next by thread: Re: Cocoa class for queuing operations?
  • Index(es):
    • Date
    • Thread