The program manifest L6.21 is the source code for the Osqcreate () function. The function requires an array of pointers to hold pointers to individual messages.
The array of pointers must be known as the void type. Osqcreate () first obtains an event control block from the list of idle event control blocks (see figure F6.3) [L6.21 (1)] and adjusts the pointer to the remaining idle event control block lists to point to the next idle event control block [L6.21 (2)]. The Osqcreate () function then extracts a queue control block from the list of control blocks of the idle queue [L6.21 (3)]. If an idle queue control block is available, initialize it [L6.21 (4)]. The function then sets the type of the event control block to Os_event_type_q [L6.21 (5)] and makes it. The oseventptr pointer points to the queue control block [L6.21 (6)]. Osqcreate () also calls the Oseventwaitlistinit () function to initialize the wait task list for the event control block [see section 6.01, initialize an event control block, Oseventwaitlistinit ()] [L6.21 (7)]. Because Message Queuing is initializing at this point, it's clear that its waiting list is empty. Finally, Osqcreate () returns to its calling function a pointer to the event control block [L6.21 (9)]. The pointer will be used when calling Osqpend (), Osqpost (), Osqpostfront (), Osqflush (), osqaccept (), and osqquery () for Message Queuing processing functions. Therefore, the pointer can be treated as a handle to the corresponding message queue. It is worth noting that if there is no idle event control block at this time, the Osqcreate () function returns a null pointer.
If no queue control block is available, in order not to waste the event control block resource, the Osqcreate () function will return the event control block just taken to the list of idle event control blocks [L6.21 (8)]. In addition, once a message queue is established, it cannot be deleted.
Imagine that it would be dangerous to have a task waiting for a message in a message queue and then deleting the message queue.
Program Manifest L6.21 establishes a message queue os_event *osqcreate (void **start, int16u size) {os_event *pevent;
Os_q *PQ;
Os_enter_critical (); pevent = oseventfreelist; (1) if (oseventfreelist! = (Os_event *) 0) {oseventfreelist = (os_event *) oseventfreelist->oseventptr;
(2)} os_exit_critical ();
if (pevent! = (Os_event *) 0) {os_enter_critical (); PQ = osqfreelist;
(3) if (osqfreelist! = (Os_q *) 0) {osqfreelist = osqfreelist->osqptr;
} os_exit_critical (); if (PQ! = (Os_q *) 0) {Pq->osqstart = start;
(4) Pq->osqend = &start[size];
Pq->osqin = start;
Pq->osqout = start;
pq->osqsize = size;
pq->osqentries = 0; Pevent->oseventtype = os_event_type_q; (5) pevent->oseventptr = PQ; (6) Oseventwaitlistinit (pevent); (7)
} else {os_enter_critical (); Pevent->oseventptr = (void *) oseventfreelist;
(8) oseventfreelist = pevent;
Os_exit_critical ();
pevent = (Os_event *) 0; }} return (pevent); (9)}