| OpenSS7 SS7 for the Common Man | © Copyright 1997-2007 OpenSS7 Corporation All Rights Reserved. Last modified: Sat, 01 Nov 2008 10:41:55 GMT | ||||||||||||||||
| |||||||||||||||||
| Description: Manual PageKeywords: ss7 ss7/ip ss7 over ip ss7 mtp ss7 sccp ss7 tcap sigtran mtp sccp tcap openss7 acb56 linux telephony pstn linux telephony linux nebs linux compactpciPUTBQSection: Linux Fast-STREAMS DDI/DKI (9)Updated: 2008-10-31 Index Return to Main Contents NAMEputbq - put a message back on a STREAMS message queueSYNOPSIS#include <sys/stream.h>
ARGUMENTS
INTERFACEDESCRIPTIONputbq() places the message pointed to by mp back onto the queue pointed to by q. When the message is placed back on the queue, it is placed on the head of the queue, rather than the tail of the queue as would result from a call to putq(9). The message is placed in the proper order at the head of the priority, normal or specified band, queue counts are adjusted and queue enabling is performed if the message is a high priority message or if the queue has not been disabled with a call to noenable(9). putbq() is normally called from within queue qi_srvp(9) procedures to place a message back on the queue subsequent to a call to getq(9) that removes a message which it turns out cannot be processed at the moment due to flow restrictions from testing canput(9) or bcanput(9). When putbq() is executed following getq(9) for the same queue, it is guaranteed to succeed. Flow Controlputbq() enables the queue q under the following circumstances:
Because mp was typically removed from the queue with getq(9), the QWANTR flag will be clear (because a message was retrieved). The only event that will cause these flags to become set is if the current or another thread removes a message from the queue with getq(9) or rmvq(9). Because only one thread can be executing a queue's qi_srvp(9) service procedure at a time, if messages are removed from the message queue only in the queue's qi_srvp(9) service procedure, and putbq() is also only called from the procedure, which is normally the case, QWANTR will never be set when putbq() is called. So, usually, q is only enabled if a high priority message is placed back on the queue with putbq(). Because normal flow control procedures from the qi_srvp(9) procedure prohibit placing a high priority message back on the queue, properly placing a message back on a queue with putbq() will not result in the queue being enabled. This is in fitting with the purpose of the putbq() utility which is to suspsend operation of a queue qi_srvp(9) service procedure until the queue is back-enabled by a forward flow controlled queue. USAGEputbq() is intended to be used from within a STREAMS driver or module qi_srvp(9) procedure. The basic steps taken by a module qi_srvp(9) procedure are as follows:
Queues that have messages placed back with putbq() from the module qi_srvp(9) procedure will not normally be enabled again by putq(9), or insq(9). Therefore, when a message is placed back on a queue with putbq(), the qi_srvp(9) procedure is considered blocked. Some event is required to re-enable the queue when it is possible to resume processing messages. In the typical flow control case (see Example#1 , below), a back-enable is scheduled by a forward queue when bcanputnext(9) fails; however, this is not the only mechanism possible. Another example (see Example#2 , below), would be when a buffer cannot be allocated to perform processing (i.e., allocb(9) fails), an explicit call to qenable(9) could be scheduled with bufcall(9), and the message placed back on the queue with putbq(). When the buffer can be allocated, the queue will be enabled and another attempt will be made to allocated the buffer necessary for processing. RETURNUpon success, putbq() returns true (1) after placing the message mp back on the head of the queue. Upon failure, putbq() returns false (0) and the message pointed to by mp is unaltered. The return value from putbq() should always be examined. ERRORSUpon failure, putbq() returns false (0) and the message pointed to by mp is unaltered. It is the caller's responsibility to free mp if the caller so desires. CONTEXTputbq() can be called from any context, including process context, module procedures, callouts, callbacks, soft interrupts (tasklets and bottom halves), and interrupt service routines. putbq() can be called from a context asynchronous to STREAMS, such as an asynchronous callback, tasklet, bottom half, or interrupt service routine. MP-STREAMSputbq() is MP-safe; however, the caller is responsible for the validity of the passed in queue and message pointers, and exclusive access to the passed in messages. Validity for qThe caller is responsible for the validity of the passed in q. q is valid from all procedures synchronous on q, including qi_qopen(9), qi_qclose(9), qi_putp(9), and qi_srvp(9), procedures and synchronous callback functions. For process context, asynchronous callback functions, soft interrupts (tasklets and bottom halves), and interrupt service routines, that is, when calling putbq() from a non-STREAMS context, any valid queue pointer, q, can be passed to putbq(); however, the caller must ensure that the queue pointer remains valid across the call. In general, q is valid from the moment that qprocson(9) returns until the moment that qprocsoff(9) is called, so, if the non-STREAMS code sections are passed a pointer from q's qi_qopen() procedure and invalidated by its qi_qclose() procedure, validity can be ensured. (This is the case with timeout(9) and bufcall(9) asynchronous callbacks. These callbacks are passed a queue pointer only after qi_qopen and must be cancelled before qi_qclose returns.) Otherwise, from outside of STREAMS context, it is possible to derive a queue pointer from a validated queue pointer, provided that the Stream is frozen with a call to freezestr(9). Under Linux Fast-STREAMS, it is permissible to call putbq() on a Stream that is frozen with freezestr(9), and freezestr(9) can be called from any context. putbq() takes a recursive freeze lock that can be acquired by the caller when the Stream is frozen. If another thread has the Stream frozen with freezestr(9), the calling processor will spin until the Stream is thawed by the other thread with unfreezestr(9). Validity and Exclusion for mpValidity of the mp pointer and exclusive access to the message pointed to by mp is normally assured in the usual ways: If mp was just allocated using allocb(9) or esballoc(9), or, if mp was just removed from a message queue with getq(9) or rmvq(9), then exclusion and validity is assured. NOTICESputbq() only fails if a queue band for mp->b_band does not yet exist and the necessary queue band structures could not be allocated. It can be ensured that putbq() will not fail for the same q for which the message was obtained with getq(9). Otherwise, it can be ensured that the queue band exists by calling strqget(9) or strqset(9) for the band in question before calling putbq(). Whether a band is allocated for a queue can also be tested by examining the q_nband member of the queue structure. This member indicates the highest priority allocated band. If the band in question is less than or equal to q_nband then the band has already been allocated. Care should be taken not to return with putbq() a high priority message taken off of a queue in a qi_srvp(9) procedure with getq(9). This is because placing the high priority message back on the queue will cause the qi_srvp(9) procedure to re-execute at the earliest opportunity resulting in possible indefinite looping. EXAMPLESFollowing are two examples of the use of putbq(). The first is an example of putbq() where enabling of the queue is scheduled by bcanputnext(9). The second is an example of putbq() where enabling of the queue is scheduled by bufcall(9). Example #1Following is a stereotypical example of a null module qi_srvp(9) procedure that simply passes messages along to the next queue without processing:
1 static int
2 xxxsrv(queue_t *q)
3 {
4 mblk_t *mp;
5
6 while ((mp = getq(q))) {
7 if (mp->b_datap->db_type >= QPCTL)
8 putnext(q, mp);
9 else {
10 if (bcanputnext(q, mp->b_band))
11 putnext(q, mp);
12 else {
13 putbq(q, mp);
14 break;
15 }
16 }
17 }
18 return (0);
19 }
Notice that at Line 13, the return value from putbq() is not examined. This is because the message was removed from the queue using getq(9) and it is guaranteed that a band structure exists for the band of the message, and therefore putbq() cannot fail. Unless another thread intervenes with a call to getq(9) or (more likely) rmvq(9), placing the message back on the queue will not enable the queue. Also, messages enqueued with putq(9) from the qi_putp(9) procedure will not normally enable the queue in this situation. The queue will usually remain blocked on flow control until it is back-enabled by the forward queue that failed bcanput(9). Example #2Following is an example of how to handle a buffer allocation failure using bufcall(9) and putbq():
1 static int
2 xxxsrv(queue_t *q)
3 {
4 mblk_t *mp;
5
6 while ((mp = getq(q))) {
7 if (mp->b_datap->db_type >= QPCTL)
8 putnext(q, mp);
9 else {
10 if (bcanputnext(q, mp->b_band)) {
11 mblk_t *db;
12
13 if (!(db = allocb(64, BPRI_MED))) {
14 priv_t *p = (priv_t *) q->q_ptr;
15
16 putbq(q, mp);
17 p->bcid = bufcall(64, BPRI_MED,
18 (void (*)(long))
19 &qenable, (long) q);
20 break;
21 }
22 /* process mp with db */
23 linkb(mp, db);
24 putnext(q, mp);
25 } else {
26 putbq(q, mp);
27 break;
28 }
29 }
30 }
31 return (0);
32 }
If the allocation using allocb(9) fails at Line 13, then the message is placed back on the queue using putbq() at Line 16, and a buffer call is issued to enable the queue when a buffer becomes available using bufcall(9) at Line 17. When the buffer callback is called, the queue will be enabled with qenable(9), and the qi_srvp(9) procedure will execute again and attempt to allocate a buffer once more. SEE ALSOputq(9), noenable(9), getq(9), canput(9), bcanput(9), getqstr(9), setqstr(9), qprocsoff(9), freezestr(9), unfreezestr(9). BUGSCOMPATIBILITYputbq() is compatible with SVR 4.2 MP DDI/DKI[1], and implementations based on SVR 4[2], with the following portability considerations:
See STREAMS(9) for additional compatibility information. CONFORMANCEHISTORYputbq() appears as part of SVR 4.0 STREAMS[3]. putbq() first appeared in SVR 3[12]. putbq() was described in Dennis Ritchie's original paper[13]. REFERENCES
TRADEMARKS
Other trademarks are the property of their respective owners. IDENTIFICATION
Copyright©1997-2008OpenSS7 Corp.
All Rights Reserved.
Index
This document was created by man2html, using the manual pages. Time: 18:25:29 GMT, May 23, 2013 | ||||||||||||||||
| OpenSS7 SS7 for the Common Man |
| ||||||||||||||||
| Last modified: Sat, 01 Nov 2008 10:41:55 GMT © Copyright 1997-2007 OpenSS7 Corporation All Rights Reserved. |