Program 10-4 QueueObjc: The Queue Management Functions in Visual Studio .NET

Maker Quick Response Code in Visual Studio .NET Program 10-4 QueueObjc: The Queue Management Functions
Program 10-4 QueueObjc: The Queue Management Functions
QR Code Maker In .NET Framework
Using Barcode generation for .NET framework Control to generate, create QR Code 2d barcode image in VS .NET applications.
/* 10 QueueObjc */ /* Queue function */ #include "EvryThngh" #include "SynchObjh" /* Finite bounded queue management functions */ DWORD q_get (queue_t *q, PVOID msg, DWORD msize, DWORD MaxWait) { if (q_destroyed (q)) return 1; WaitForSingleObject (q->q_guard, INFINITE); while (q_empty (q) { SignalObjectAndWait (q->q_guard, q->q_ne, INFINITE, FALSE); WaitForSingleObject (q->q_guard, INFINITE); } /* Remove the message from the queue */ q_remove (q, msg, msize); /* Signal that queue is not full as we've removed a message */ PulseEvent (q->q_nf); ReleaseMutex (q->q_guard); return 0; } DWORD q_put (queue_t *q, PVOID msg, DWORD msize, DWORD MaxWait) { if (q_destroyed (q)) return 1; WaitForSingleObject (q->q_guard, INFINITE); while (q_full (q) { SignalObjectAndWait (q->q_guard, q->q_nf, INFINITE, FALSE); WaitForSingleObject (q->q_guard, INFINITE); } /* Put the message in the queue */ q_insert (q, msg, msize);
QR Code Reader In .NET Framework
Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
/* Signal that queue is not empty; we've inserted a message */ PulseEvent (q->q_ne); /* Broadcast CV model */ ReleaseMutex (q->q_guard); return 0; } DWORD q_initialize (queue_t *q, DWORD msize, DWORD nmsgs) { /* Initialize queue, including its mutex and events */ /* Allocate storage for all messages */ q->q_first = q->q_last = 0; q->q_size = nmsgs; q->q_destroyed = 0; q->q_guard = CreateMutex (NULL, FALSE, NULL); q->q_ne = CreateEvent (NULL, TRUE, FALSE, NULL); q->q_nf = CreateEvent (NULL, TRUE, FALSE, NULL); if ((q->msg_array = calloc (nmsgs, msize)) == NULL) return 1; return 0; /* No error */ } DWORD q_destroy (queue_t *q) { if (q_destroyed (q)) return 1; /* Free all the resources created by q_initialize */ WaitForSingleObject (q->q_guard, INFINITE); q->q_destroyed = 1; free (q->msg_array); CloseHandle (q->q_ne); CloseHandle (q->q_nf); ReleaseMutex (q->q_guard); CloseHandle (q->q_guard); return 0; } DWORD q_destroyed (queue_t *q) { return (q->q_destroyed); } DWORD q_empty (queue_t *q) { return (q->q_first == q->q_last); } DWORD q_full (queue_t *q) { return ((q->q_last - q->q_first) == 1 || (q->q_first == q->q_size-1 && q->q_last == 0)); } DWORD q_remove (queue_t *q, PVOID msg, DWORD msize) { char *pm; pm = (char *)q->msg_array; /* Remove oldest ("first") message */ memcpy (msg, pm + (q->q_first * msize), msize); q->q_first = ((q->q_first + 1) % q->q_size); return 0; /* No error */
Bar Code Generator In .NET Framework
Using Barcode drawer for Visual Studio .NET Control to generate, create barcode image in Visual Studio .NET applications.
} DWORD q_insert (queue_t *q, PVOID msg, DWORD msize) { char *pm; pm = (char *) q->msg_array; /* Add a new youngest ("last") message */ if (q_full (q)) return 1; /* Error - Q is full */ memcpy (pm + (q->q_last * msize), msg, msize); q->q_last = ((q->q_last + 1) % q->q_size); return 0; }
Barcode Reader In VS .NET
Using Barcode scanner for VS .NET Control to read, scan read, scan image in .NET applications.
Comments on the Queue Management Functions and Performance
Paint QR Code In C#.NET
Using Barcode encoder for Visual Studio .NET Control to generate, create QR Code JIS X 0510 image in .NET applications.
Appendix C contains performance data, based on Program 10-5, which uses the queue management functions The following comments that refer to performance are based on that data The book's Web site contains code for all the implementation variations
QR Code ISO/IEC18004 Printer In .NET Framework
Using Barcode generator for ASP.NET Control to generate, create QR Code JIS X 0510 image in ASP.NET applications.
This implementation uses the broadcast model (manual-reset/PulseEvent) to allow for the general case in which multiple messages may be requested or created by a single thread The signal model (auto-reset/SetEvent) will work if this generality is not required, and there are significant performance advantages because only a single thread is released to test the predicate The Web site contains QueueObj_Sigc, a source file that uses signaling rather than broadcasting Using a CRITICAL_SECTION, rather than a mutex, to protect the queue object can also improve performance However, you must use an EnterCriticalSection followed by an event wait rather than SignalObjectAndWait Two files provided on the Web site, QueueObjCSc and QueueObjCS_Sigc, illustrate this alternative approach QueueObj_noSOAWc and QueueObj_noSOAWc are two additional source files provided on the Web site that build executable programs that will run on Windows 9x and do not use SignalObjectAndWait Appendix C also shows the nonlinear performance impact when a large number of threads contend for a queue The Web site contains projects for each of the alternative strategies; the projects are variations of the ThreeStage pipeline system described in the following sections In summary, the queues can be extended to be process-sharable and to get and put multiple messages atomically Some performance gains may be realized, however, by using the signal model, a CRITICAL_SECTION, or SignalObjectAndWait Appendix C gives some performance results
QR Code ISO/IEC18004 Maker In Visual Basic .NET
Using Barcode encoder for .NET Control to generate, create QR Code JIS X 0510 image in .NET applications.
Data Matrix Generation In .NET Framework
Using Barcode generator for Visual Studio .NET Control to generate, create ECC200 image in VS .NET applications.
Creating GTIN - 12 In VS .NET
Using Barcode encoder for .NET Control to generate, create Universal Product Code version A image in .NET framework applications.
International Standard Serial Number Generator In Visual Studio .NET
Using Barcode generation for Visual Studio .NET Control to generate, create ISSN - 10 image in .NET framework applications.
Barcode Encoder In C#
Using Barcode generator for Visual Studio .NET Control to generate, create barcode image in VS .NET applications.
ECC200 Drawer In C#.NET
Using Barcode maker for .NET framework Control to generate, create ECC200 image in Visual Studio .NET applications.
Bar Code Generation In VS .NET
Using Barcode generation for ASP.NET Control to generate, create bar code image in ASP.NET applications.
Barcode Creation In Java
Using Barcode maker for Java Control to generate, create bar code image in Java applications.