• 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: Threading Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Threading Question


  • Subject: Re: Threading Question
  • From: Gregory Wieber <email@hidden>
  • Date: Tue, 31 Jan 2012 22:15:35 -0800

Oh, and clearly if you're in a .mm file, you want to be careful about using "release" as a method name... (I believe you said c++, but, just making sure)

Sent from my iPhone

On Jan 31, 2012, at 6:00 AM, Morgan Packard <email@hidden> wrote:

Yeah, this is more or less what I do. Thanks Robert.
-Morgan

On Tue, Jan 31, 2012 at 4:05 AM, Robert Bielik <email@hidden> wrote:
ben kamen skrev 2012-01-31 03:09:

Morgan, if you are willing to share a simple example of what that looks like, I would be grateful. What exactly goes into the queue? Function pointers?

One simple SWSR implementation (single writer-single reader)  would be to have a Message class:

class Message {
public:
 Message() {;}
 enum Type {
   Type_kAttack,
   ...
 } type;

 int param1;
 int param2;
 ...
};

unsigned char fifoQueue[256 * sizeof(Message)] = {0};
unsigned fifoWritePtr = 0;
unsigned fifoReadPtr = 0;

Message* getMessageToWrite()
{
 Message* base = (Message*)fifoQueue;
 return new(base + (fifoWritePtr & 255)) Message();
}

void postMessageToFifo()
{
 ++fifoWritePtr;
}

bool fifoHasMessages() {
 return (fifoWritePtr != fifoReadPtr);
}

const Message* getMessageFromFifo()
{
 const Message* base = (const Message*)fifoQueue;
 return base + (fifoReadPtr & 255);
}

void fifoAdvanceRead() {
 ++fifoReadPtr;
}

To post messages to the fifo:

Message* pMessage = getMessageToWrite();
pMessage->type = Message::Type_kAttack;
pMessage->param1 = 42;
postMessageToFifo();

Reading/processing messages in render callback:

while(fifoHasMessages()) {
 const Message *pMessage = getMessageFromFifo();
 // TODO: Process the message

 // Next message...
 fifoAdvanceRead();
}

That should roughly get you started.

Regards,
/Rob

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

This email sent to email@hidden



--
===============
Morgan Packard
cell: (720) 891-0122
aim: mpackardatwork

Do not post admin requests to the list. They will be ignored. Coreaudio-api mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Threading Question (From: ben kamen <email@hidden>)
 >Re: Threading Question (From: Gregory Wieber <email@hidden>)
 >Re: Threading Question (From: Gregory Wieber <email@hidden>)
 >Re: Threading Question (From: Gregory Wieber <email@hidden>)
 >Re: Threading Question (From: ben kamen <email@hidden>)
 >Re: Threading Question (From: Robert Bielik <email@hidden>)
 >Re: Threading Question (From: Morgan Packard <email@hidden>)

  • Prev by Date: Re: Threading Question
  • Previous by thread: Re: Threading Question
  • Next by thread: RE: Threading Question
  • Index(es):
    • Date
    • Thread