Content¶
It’s finally time to get into the guts of the comment block: inputs, outputs, how to use the function. First, let’s look at the prototype itself.
UINT _tx_block_allocate(TX_BLOCK_POOL *pool_ptr, VOID **block_ptr, ULONG wait_option)
This is actually fine. The function has a sensible name; it’s clearly
allocating a block from a pool. Its first argument is the pool, which
is probably mutated in the allocation process. It returns a pointer to
the allocated block in the block_ptr argument. It also takes some
sort of option argument for how it behaves with respect to waiting? I
don’t know, maybe that’s about what to do if it can’t get one. The
return value is obviously a success/failure status of some sort.
So the questions I have after reading this are:
How can the function fail?
What does
wait_optiondo, and what are valid values for it?What happens to my block pointer if allocation fails?
Not too bad! One whole argument is entirely obvious, a second is
mostly obvious, and a third at least tells me I need to look at the
documentation to find out what to do with it. I’d be happier if its
return type and wait_option were enums, but this is far from
the worst I’ve seen.
Now let’s look at the docs and see what the answers to my questions are.
/* OUTPUT */
/* */
/* status Completion status */
So, my first question’s answer is…nowhere to be found. Really wishing you’d used an enumeration as a return type here William.
Well, maybe my second question will be answered in the inputs.
/* INPUT */
/* */
/* pool_ptr Pointer to pool control block */
/* block_ptr Pointer to place allocated block */
/* pointer */
/* wait_option Suspension option */
What the hell, Will? Are you trying to make me angry? While the rest
of this mess may be the result of a dysfunctional company style, this
is inexcusable. “Suspension option?” What kind of garbage is this?
What is block_ptr even doing here? It’s an output! It even says
so in the INPUT description! Not, like, explicitly, because that
would be too clear, but who’s placing things in pointers if not the
function being called, Willie? Who?
Alright. This is fine. There’s still the description. Maybe it can save us.
/* DESCRIPTION */
/* */
/* This function allocates a block from the specified memory block */
/* pool. */
Look. Bill. I know that it allocates a block. It’s called
block_allocate. I even know it uses the specified memory block
pool to do it. What I don’t know is anything else. Help me just a
little here. What side effects does it have? How does it behave when
it fails? What can cause it to fail? What in the name of Dennis
Ritchie is a wait option?
Breathe. It’s just software.
Alright, so if I cut out all the useless, misleading, and redundant information, here’s what’s left of our comment block:
/**************************************************************************/
/* */
/**************************************************************************/
UINT _tx_block_allocate(TX_BLOCK_POOL *pool_ptr, VOID **block_ptr, ULONG wait_option);
The comment rectangle is pretty silly; I would have said something earlier but there were other problems to tackle. I think you can figure out yourself what’s really left now, Billiam.
As I said, adding useful information is out of scope. Good documentation is not missing. Writing it is left as an exercize for the reader.