Professional Web Applications Themes

ringbuffers on os9 - Mac Programming

this is part of a program i am writing to receive data at interrupt time and put it into a ringbuffer. i am crashing! can somebody point out my mistake? does it have to do with Handles? here is my ringbuffer: typedef struct RINGBUFFER_Tag{ Handle buff; unsigned long buffSize; unsigned long buffCount; int wError; MYTHING* buffStart; MYTHING* buffEnd; MYTHING* buffHead; MYTHING* buffTail; } RINGBUFFER; on program start, i call MakeBuffer(500): long MakeBuffer(int size){ inbuffer = new RINGBUFFER; inbuffer->buff = NewHandle(size * sizeof(MYTHING)); HLock(inbuffer->buff); inbuffer->buffCount = 0L; inbuffer->buffSize = size; inbuffer->buffStart = (MYTHING *)inbuffer->buff; inbuffer->buffEnd = (MYTHING *)inbuffer->buff + inbuffer->buffSize; inbuffer->buffTail ...

  1. #1

    Default ringbuffers on os9

    this is part of a program i am writing to receive data at interrupt time and
    put it into a ringbuffer. i am crashing! can somebody point out my mistake?
    does it have to do with Handles?

    here is my ringbuffer:
    typedef struct RINGBUFFER_Tag{
    Handle buff;
    unsigned long buffSize;
    unsigned long buffCount;
    int wError;
    MYTHING* buffStart;
    MYTHING* buffEnd;
    MYTHING* buffHead;
    MYTHING* buffTail;
    } RINGBUFFER;


    on program start, i call MakeBuffer(500):

    long MakeBuffer(int size){
    inbuffer = new RINGBUFFER;
    inbuffer->buff = NewHandle(size * sizeof(MYTHING));
    HLock(inbuffer->buff);

    inbuffer->buffCount = 0L;
    inbuffer->buffSize = size;
    inbuffer->buffStart = (MYTHING *)inbuffer->buff;
    inbuffer->buffEnd = (MYTHING *)inbuffer->buff + inbuffer->buffSize;
    inbuffer->buffTail =(MYTHING *)inbuffer->buff;
    inbuffer->buffHead = (MYTHING *)inbuffer->buff;

    // i was DebugStr-ing here to see if there was MemErr(), and wasn't
    getting any errors
    // is there a better way of testing here than that?
    return 0;
    }



    at interrupt time, i receive: MYTHING* pkt in a callback.

    i process pkt like this at interrupt time in my callback proc:

    MYTHING incoming = (MYTHING)*pkt;
    (MYTHING)*inbuffer->buffHead = incoming;// i tried casting about 10 diff
    ways, no luck

    ++inbuffer->buffHead;
    ++inbuffer->buffCount;

    if(inbuffer->buffHead >=inbuffer->buffEnd)
    inbuffer->buffHead = inbuffer->buffStart;

    I crash at this point. help!

    vvvv




    vvvv Guest

  2. #2

    Default Re: ringbuffers on os9

    In article <2vg3b.61699$Sq.10740812twister.nyc.rr.com>,
    "vvvv" <noonenowhere.com> wrote:
    > this is part of a program i am writing to receive data at interrupt time and
    > put it into a ringbuffer. i am crashing! can somebody point out my mistake?
    > does it have to do with Handles?
    <http://developer.apple.com/doentation/mac/Memory/Memory-62.html>
    says:

    "Note that Memory Manager routines like HLock return their results via
    MemError and therefore should not be called in interrupt code."

    You have to be realy careful what you call at interrupt time.
    Sean McBride Guest

  3. #3

    Default Re: ringbuffers on os9

    i redid my ringbuffer to have NewPtr instead of newhandle, and all the
    problems went away.

    which begs the question...why?

    memory is NOT easy!

    vvvv


    "Manfred Lippert" <manimani.de> wrote in message
    news:BB7504AD.192B4%manimani.de...
    > > Handle buff;
    > > [...]
    > > MYTHING* buffStart;
    > > [...]
    > > inbuffer->buffStart = (MYTHING *)inbuffer->buff;
    >
    > A Mac Handle is a "pointer to a pointer", so I think you have to write the
    > following here (and on some other places):
    >
    > inbuffer->buffStart = (MYTHING *)*(inbuffer->buff);
    >
    > Bye,
    > Mani
    >

    vvvv Guest

  4. #4

    Default Re: ringbuffers on os9

    On 8/30/03 1:01, in article BB75A803.6CDE%dimamarkmanattbi.com, "Dmitry
    Markman" <dimamarkmanattbi.com> wrote:
    > typedef *Ptr Handle
    sorry should be

    typedef Ptr * Handle;

    Dmitry Markman

    Dmitry Markman Guest

  5. #5

    Default Re: ringbuffers on os9

    On Sat, 30 Aug 2003, vvvv wrote:
    > i redid my ringbuffer to have NewPtr instead of newhandle, and all the
    > problems went away.
    >
    > which begs the question...why?
    Because a pointer is not the same thing as a handle.

    Fred

    Frederick Cheung Guest

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139