00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 #include "vxWorks.h"
00189 #include "semLib.h"
00190 #include "memLib.h"
00191 #include "taskLib.h"
00192 #include "stdarg.h"
00193 #include "fioLib.h"
00194 #include "stdio.h"
00195 #include "logLib.h"
00196 #include "string.h"
00197
00198 #include "bbd.h"
00199 #include "dbg_mem.h"
00200
00201
00202
00203
00204
00205
00206
00207
00208 #define BBD_MASTER (BBD_WRITER *) NULL
00209
00210
00211
00212 LOCAL void bbdLock (BBD_WRITER * id);
00213 LOCAL void bbdUnlock (BBD_WRITER * id);
00214 LOCAL BBD_WRITER *bbdCreateWriterStruct (char *bbdName, BBD_TYPE bbdType,
00215 int bufSize);
00216 LOCAL BOOL bbdDeleteWriterStruct (BBD_WRITER * id);
00217 LOCAL BBD_READER *bbdCreateReaderStruct (char *name, BBD_TYPE type,
00218 int bufSize, BBD_WRITER * bbd);
00219 LOCAL BBD_WRITER *bbdFindWriter (char *name);
00220 LOCAL BBD_WRITER *bbdLinkWriter (BBD_WRITER * id);
00221 LOCAL BBD_WRITER *bbdConnectWriter (BBD_WRITER * id, BBD_TYPE type,
00222 int bufSize);
00223 STATUS bbdDelete (BBD id);
00224
00225
00226 LOCAL BBD_WRITER *bbdList = NULL;
00227 LOCAL SEM_ID bbdMasterSem = NULL;
00228
00229
00230
00231 LOCAL void
00232 bbdSuspend (char *format, ...)
00233 {
00234 char st[300];
00235
00236 va_list args;
00237 va_start (args, format);
00238
00239 vsprintf (st, format, args);
00240 logMsg (st, 0, 0, 0, 0, 0, 0);
00241 logMsg ("Suspending task\n", 0, 0, 0, 0, 0, 0);
00242 taskSuspend (0);
00243
00244 va_end (args);
00245 }
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 LOCAL void
00256 bbdLock (BBD_WRITER * id)
00257 {
00258 char st[100 + BBD_NAME_SIZE];
00259
00260 if (id == BBD_MASTER)
00261 {
00262 if (bbdMasterSem == NULL)
00263 {
00264 if (NULL == (bbdMasterSem = semMCreate (SEM_Q_PRIORITY |
00265 SEM_DELETE_SAFE |
00266 SEM_INVERSION_SAFE)))
00267 {
00268 bbdSuspend ("Can't create BBD master semaphore!\n");
00269 }
00270 }
00271 if (semTake (bbdMasterSem, 100) == ERROR)
00272 {
00273 bbdSuspend ("Bulletin Board master semaphore timed out!\n");
00274
00275 }
00276 }
00277 else
00278 {
00279 if (semTake (id->sem, 100) == ERROR)
00280 {
00281 sprintf (st, "BBD >%s< semaphore timed out!\n", id->name);
00282 bbdSuspend (st);
00283 }
00284 }
00285 }
00286
00287 LOCAL void
00288 bbdUnlock (BBD_WRITER * id)
00289 {
00290 if (id == BBD_MASTER)
00291 semGive (bbdMasterSem);
00292 else
00293 semGive (id->sem);
00294 }
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 LOCAL BBD_WRITER *
00308 bbdCreateWriterStruct (char *bbdName, BBD_TYPE bbdType, int bufSize)
00309 {
00310 BBD_WRITER *id;
00311
00312 if (NULL == (id = (BBD_WRITER *) DEBUG_MALLOC (sizeof (BBD_WRITER))))
00313 bbdSuspend ("Can't allocate memory for BBD!\n");
00314 id->type = bbdType;
00315 id->sem =
00316 semMCreate (SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE);
00317 strncpy (id->name, bbdName, BBD_NAME_SIZE);
00318 id->name[BBD_NAME_SIZE] = 0;
00319 if (NULL == (id->buf = (char *) DEBUG_MALLOC (bufSize)))
00320 bbdSuspend ("Can't allocate memory for BBD data buffer!\n");
00321
00322 id->size = bufSize;
00323 id->writeCnt = 0;
00324 id->readCnt = 0;
00325 id->waitingToWriteSem = semBCreate (SEM_Q_FIFO, SEM_FULL);
00326 id->waitingToReadSem = semBCreate (SEM_Q_FIFO, SEM_EMPTY);
00327 id->taskId = taskIdSelf ();
00328 id->readers = NULL;
00329
00330
00331
00332 if (NULL == id->sem ||
00333 NULL == id->waitingToWriteSem || NULL == id->waitingToReadSem)
00334 {
00335 bbdSuspend ("Can't create BBD semaphores!\n");
00336 }
00337
00338 return id;
00339 }
00340
00341
00342
00343 LOCAL BOOL
00344 bbdDeleteWriterStruct (BBD_WRITER * id)
00345 {
00346 BOOL stat;
00347 if (id == NULL)
00348 return ERROR;
00349 DEBUG_FREE ((char *) id->buf);
00350 stat = semDelete (id->sem) &&
00351 semDelete (id->waitingToWriteSem) && semDelete (id->waitingToReadSem);
00352
00353 DEBUG_FREE ((char *) id);
00354 return stat;
00355 }
00356
00357
00358
00359 LOCAL BBD_READER *
00360 bbdCreateReaderStruct (char *bbdName, BBD_TYPE bbdType, int bufSize,
00361 BBD_WRITER * bbd)
00362 {
00363 BBD_READER *id;
00364
00365 if (bufSize != bbd->size)
00366 bbdSuspend ("Can't attach bbd reader to \"%s\".\n"
00367 "Wrong buffer size %d. Must be %d\n",
00368 bbd->name, bufSize, bbd->size);
00369
00370
00371 if (NULL == (id = (BBD_READER *) DEBUG_MALLOC (sizeof (BBD_READER))))
00372 bbdSuspend ("Can't allocate memory for reader BBD!\n");
00373
00374 id->type = bbdType;
00375 id->bbd = bbd;
00376 id->readCnt = 0;
00377 id->taskId = taskIdSelf ();
00378
00379 bbdLock (bbd);
00380 {
00381
00382 id->next = bbd->readers;
00383 bbd->readers = id;
00384 }
00385 bbdUnlock (bbd);
00386 return id;
00387 }
00388
00389
00390
00391 LOCAL BBD_WRITER *
00392 bbdFindWriter (char *name)
00393 {
00394 BBD_WRITER *tId;
00395 for (tId = bbdList; tId != NULL; tId = tId->next)
00396 {
00397 if (0 == strncmp (tId->name, name, BBD_NAME_SIZE - 1))
00398 break;
00399 }
00400 return tId;
00401 }
00402
00403
00404
00405
00406
00407
00408
00409 LOCAL BBD_WRITER *
00410 bbdLinkWriter (BBD_WRITER * id)
00411 {
00412 BBD_WRITER *tId;
00413
00414 bbdLock (BBD_MASTER);
00415 {
00416
00417
00418
00419
00420 if (NULL == (tId = bbdFindWriter (id->name)))
00421 {
00422 id->next = bbdList;
00423 bbdList = id;
00424 }
00425 }
00426 bbdUnlock (BBD_MASTER);
00427 if (tId != NULL)
00428 {
00429
00430 bbdConnectWriter (tId, id->type, id->size);
00431 (void) bbdDeleteWriterStruct (id);
00432 id = tId;
00433 }
00434 return id;
00435 }
00436
00437
00438
00439 LOCAL BBD_WRITER *
00440 bbdConnectWriter (BBD_WRITER * id, BBD_TYPE type, int bufSize)
00441 {
00442 BBD_READER *readId;
00443
00444 if (NULL == id)
00445 bbdSuspend ("Cannot connect to NULL bbd.\n");
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456 if (id->size != bufSize)
00457 bbdSuspend ("Can't attach bbd writter to \"%s\".\n"
00458 "Wrong buffer size %d. Must be %d\n",
00459 id->name, bufSize, id->size);
00460
00461
00462 bbdLock (id);
00463 {
00464 id->type = type;
00465 id->taskId = taskIdSelf ();
00466 if (type == BBD_SOLE_WRITER)
00467 {
00468
00469
00470
00471
00472 for (readId = id->readers; readId != NULL; readId = readId->next)
00473 {
00474
00475 readId->readCnt = id->writeCnt;
00476 }
00477 id->readCnt = id->writeCnt;
00478
00479
00480
00481
00482 semFlush (id->waitingToWriteSem);
00483 }
00484 }
00485 bbdUnlock (id);
00486 return id;
00487 }
00488
00489
00490
00491 BBD bbdConnect (char *bbdName, BBD_TYPE bbdType, int bufSize)
00492 {
00493 BBD id;
00494 BBD_WRITER *wId;
00495 switch (bbdType)
00496 {
00497 case BBD_SOLE_WRITER:
00498 case BBD_MULT_WRITER:
00499 if (NULL == (wId = bbdFindWriter (bbdName)))
00500 {
00501
00502 wId = bbdCreateWriterStruct (bbdName, bbdType, bufSize);
00503 wId = bbdLinkWriter (wId);
00504 }
00505 else
00506 {
00507
00508 bbdConnectWriter (wId, bbdType, bufSize);
00509 }
00510 id = (BBD) wId;
00511 break;
00512 case BBD_MULT_READER:
00513 if (NULL == (wId = bbdFindWriter (bbdName)))
00514 {
00515
00516
00517
00518
00519 wId = bbdCreateWriterStruct (bbdName, BBD_MULT_WRITER, bufSize);
00520 wId = bbdLinkWriter (wId);
00521 }
00522 id = (BBD) bbdCreateReaderStruct (bbdName, bbdType, bufSize, wId);
00523 break;
00524 default:
00525 bbdSuspend ("Can't connect. Unknown BBD type.\n");
00526 }
00527 return id;
00528 }
00529
00530
00531
00532 STATUS bbdDelete (BBD id)
00533 {
00534 STATUS stat;
00535 BBD_WRITER *wId;
00536 BBD_READER *rId;
00537
00538 if (NULL == id)
00539 return ERROR;
00540
00541 switch (*(BBD_TYPE *) id)
00542 {
00543 case BBD_MULT_READER:
00544 stat = ERROR;
00545 wId = ((BBD_READER *) id)->bbd;
00546
00547 bbdLock (wId);
00548 {
00549
00550 if (wId->readers == (BBD_READER *) id)
00551 {
00552 wId->readers = wId->readers->next;
00553 stat = OK;
00554 }
00555 else
00556 {
00557
00558 for (rId = wId->readers; rId != NULL; rId = rId->next)
00559 {
00560 if (rId->next == (BBD_READER *) id)
00561 {
00562
00563 rId->next = ((BBD_READER *) id)->next;
00564 stat = OK;
00565 break;
00566 }
00567 }
00568 }
00569 }
00570 bbdUnlock (wId);
00571 if (OK == stat)
00572 {
00573
00574 (*(BBD_TYPE *) id) = BBD_NULL;
00575
00576 DEBUG_FREE ((char *) id);
00577 }
00578 break;
00579 default:
00580 stat = ERROR;
00581 break;
00582 }
00583 return stat;
00584 }
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605 STATUS bbdClear (BBD id)
00606 {
00607 STATUS stat;
00608 BBD_WRITER *wId;
00609 BBD_READER *rId;
00610
00611 if (NULL == id)
00612 return ERROR;
00613
00614 switch (*(BBD_TYPE *) id)
00615 {
00616 case BBD_MULT_READER:
00617 stat = OK;
00618 wId = ((BBD_READER *) id)->bbd;
00619 bbdLock (wId);
00620 {
00621
00622 ((BBD_READER *) id)->readCnt = wId->readCnt = wId->writeCnt;
00623 semGive (wId->waitingToWriteSem);
00624 }
00625 bbdUnlock (wId);
00626 break;
00627 case BBD_MULT_WRITER:
00628 stat = OK;
00629 wId = (BBD_WRITER *) id;
00630 bbdLock (wId);
00631 {
00632
00633 wId->readCnt = wId->writeCnt;
00634 semGive (wId->waitingToWriteSem);
00635 }
00636 bbdUnlock (wId);
00637 break;
00638
00639 case BBD_SOLE_WRITER:
00640 stat = OK;
00641 wId = (BBD_WRITER *) id;
00642 bbdLock (wId);
00643 {
00644 if (wId->taskId != taskIdSelf ())
00645 {
00646
00647 stat = ERROR;
00648 }
00649 else
00650 {
00651
00652 wId->readCnt = wId->writeCnt = 0;
00653 for (rId = wId->readers; rId != NULL; rId = rId->next)
00654 {
00655 rId->readCnt = 0;
00656 }
00657 semGive (wId->waitingToWriteSem);
00658 }
00659 }
00660 bbdUnlock (wId);
00661 break;
00662
00663 default:
00664 stat = ERROR;
00665 break;
00666 }
00667 return stat;
00668 }
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679 STATUS bbdRead (BBD id, void *buf, BBD_READ_TYPE type, int timeout)
00680 {
00681 STATUS stat;
00682 BBD_WRITER *wId;
00683 BBD_READER *rId;
00684
00685 if (NULL == id)
00686 return ERROR;
00687
00688 switch (*(BBD_TYPE *) id)
00689 {
00690 case BBD_MULT_READER:
00691 rId = (BBD_READER *) id;
00692 wId = rId->bbd;
00693 stat = OK;
00694
00695
00696
00697
00698
00699
00700
00701 taskLock ();
00702 {
00703 if (wId->writeCnt == 0)
00704 {
00705
00706 stat = semTake (wId->waitingToReadSem, timeout);
00707 }
00708 else if (type == BBD_FRESH_READ && wId->writeCnt <= rId->readCnt)
00709 {
00710
00711 stat = semTake (wId->waitingToReadSem, timeout);
00712 }
00713 }
00714 taskUnlock ();
00715 if (stat == OK)
00716 {
00717 bbdLock (wId);
00718 {
00719 bcopy (wId->buf, buf, wId->size);
00720
00721 if (type != BBD_SPY_READ)
00722 {
00723 wId->readCnt = wId->writeCnt;
00724 rId->readCnt = wId->writeCnt;
00725 semGive (wId->waitingToWriteSem);
00726 }
00727 }
00728 bbdUnlock (wId);
00729 }
00730 break;
00731 default:
00732 stat = ERROR;
00733 break;
00734 }
00735 return stat;
00736 }
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746 LOCAL STATUS
00747 bbdPlainWrite (BBD_WRITER * id, void *buf)
00748 {
00749 STATUS stat;
00750
00751 stat = OK;
00752 bbdLock (id);
00753 {
00754 if (BBD_SOLE_WRITER == id->type && taskIdSelf () != id->taskId)
00755 {
00756
00757 stat = ERROR;
00758 if (id->writeCnt <= id->readCnt)
00759 {
00760
00761
00762
00763
00764 semGive (id->waitingToWriteSem);
00765
00766 }
00767 }
00768 else
00769 {
00770
00771
00772
00773
00774
00775 bcopy (buf, id->buf, id->size);
00776
00777 id->writeCnt++;
00778 semTake (id->waitingToWriteSem, NO_WAIT);
00779 semFlush (id->waitingToReadSem);
00780 }
00781 bbdUnlock (id);
00782
00783 return stat;
00784 }
00785 }
00786
00787 STATUS bbdWrite (BBD id, void *buf, BBD_WRITE_TYPE type,...)
00788 {
00789 STATUS stat;
00790 BBD_WRITER *wId;
00791 int timeout;
00792 va_list ap;
00793
00794 if (NULL == id)
00795 return ERROR;
00796
00797 switch (*(BBD_TYPE *) id)
00798 {
00799 case BBD_SOLE_WRITER:
00800 case BBD_MULT_WRITER:
00801 wId = (BBD_WRITER *) id;
00802 if (BBD_WAIT_WRITE == type)
00803 {
00804 va_start (ap, type);
00805 timeout = va_arg (ap, int);
00806
00807 stat = semTake (wId->waitingToWriteSem, timeout);
00808 if (ERROR != stat)
00809 {
00810 bbdLock (wId);
00811 {
00812 if (wId->writeCnt > wId->readCnt)
00813 {
00814
00815
00816
00817
00818
00819
00820
00821 stat = ERROR;
00822 }
00823 else
00824 {
00825 stat = bbdPlainWrite (wId, buf);
00826 }
00827 }
00828 bbdUnlock (wId);
00829 }
00830 va_end (ap);
00831 }
00832 else
00833 {
00834 stat = bbdPlainWrite (wId, buf);
00835 }
00836
00837 break;
00838 default:
00839 stat = ERROR;
00840 break;
00841 }
00842 return stat;
00843 }
00844
00845
00846
00847
00848
00849
00850 char bbdHelpHelpStr[] = "\
00851 bbdHelp Msg passing between tasks on one cpu\n";
00852
00853 LOCAL char bbdHelpString[] = "\
00854 bbdConnect name,type,size Connects to a bbd \n\
00855 bbdClear id Flush data buffer \n\
00856 bbdRead id,buf,type,timeout Read from bbd \n\
00857 bbdWrite id,buf,type[,timeout]Write to bbd \n\
00858 bbdName id Returns name of bbd \n\
00859 bbdNameToId name Returns id of writer\n\
00860 bbdShow [id [,name]] Show info on bbds. If id=0, uses name\n\
00861 \n\
00862 bbd types: multi-reader = 2, sole_writer = 3, multi-writer = 4 \n\
00863 read types: plain = 1, only fresh data = 2, spy = 3 \n\
00864 write types: plain = 1, blocking = 2 \n\
00865 ";
00866
00867
00868 int
00869 bbdHelp ()
00870 {
00871 printf (bbdHelpString);
00872 return 0;
00873 }
00874
00875
00876 char *
00877 bbdName (BBD id)
00878 {
00879 if (NULL == id)
00880 return NULL;
00881
00882 switch (*(BBD_TYPE *) id)
00883 {
00884 case BBD_SOLE_WRITER:
00885 case BBD_MULT_WRITER:
00886 return ((BBD_WRITER *) id)->name;
00887 case BBD_MULT_READER:
00888 return ((BBD_READER *) id)->bbd->name;
00889 default:
00890 break;
00891 }
00892 return NULL;
00893 }
00894
00895
00896 BBD bbdNameToId (char *name)
00897 {
00898 return (BBD) bbdFindWriter (name);
00899 }
00900
00901
00902 LOCAL void
00903 bbdPrintTaskName (int taskId, int maxChars)
00904 {
00905 int len, i;
00906 char *name;
00907 name = taskName (taskId);
00908 if (NULL != name)
00909 len = strlen (name);
00910 else
00911 {
00912 name = "***";
00913 len = 3;
00914 }
00915 for (i = maxChars - len; i > 0; i--)
00916 printf (" ");
00917 if (maxChars < len)
00918 for (i = 0; i < maxChars; i++)
00919 printf ("%c", name[i]);
00920 else
00921 for (i = 0; i < len; i++)
00922 printf ("%c", name[i]);
00923 }
00924
00925
00926 LOCAL STATUS
00927 bbdShowReaders (BBD_WRITER * wId)
00928 {
00929 int cnt;
00930 BBD_READER *rId, *r;
00931
00932 if (BBD_SOLE_WRITER != wId->type && BBD_MULT_WRITER != wId->type)
00933 return ERROR;
00934 if (NULL == wId->readers)
00935 printf ("no readers\n----------\n");
00936 for (rId = wId->readers; NULL != rId;)
00937 {
00938
00939
00940
00941
00942
00943
00944 printf ("id ");
00945 for (cnt = 0, r = rId; NULL != r && cnt != 6; cnt++, r = r->next)
00946 printf ("%10p ", r);
00947 printf ("\ntask ");
00948 for (cnt = 0, r = rId; NULL != r && cnt != 6; cnt++, r = r->next)
00949 {
00950 bbdPrintTaskName (r->taskId, 10);
00951 printf (" ");
00952 }
00953 printf ("\ncnt ");
00954 for (cnt = 0, r = rId; NULL != r && cnt != 6; cnt++, r = r->next)
00955 printf ("%10d ", r->readCnt);
00956
00957 for (printf ("\n-----"); cnt--; printf ("-----------"));
00958 printf ("\n");
00959 rId = r;
00960 }
00961 return OK;
00962 }
00963
00964
00965 LOCAL STATUS
00966 bbdShowWriter (BBD_WRITER * wId)
00967 {
00968 char *name, st[61];
00969
00970 if (BBD_SOLE_WRITER != wId->type && BBD_MULT_WRITER != wId->type)
00971 return ERROR;
00972
00973 if (BBD_SOLE_WRITER == wId->type)
00974 printf ("Sole writer: ");
00975 else
00976 printf ("Mult writer: ");
00977 strncpy (st, wId->name, 60);
00978 st[60] = 0;
00979 printf ("\"%s\"\n", st);
00980 printf ("bbd semaphore (%p) is ", wId->sem);
00981 if (ERROR == semTake (wId->sem, NO_WAIT))
00982 printf ("blocked\n");
00983 else
00984 {
00985 printf ("clear\n");
00986 semGive (wId->sem);
00987 }
00988 printf ("waitingToWriteSem (%p) is ", wId->waitingToWriteSem);
00989 if (ERROR == semTake (wId->waitingToWriteSem, NO_WAIT))
00990 printf ("blocked\n");
00991 else
00992 {
00993 printf ("clear\n");
00994 semGive (wId->waitingToWriteSem);
00995 }
00996 printf ("waitingToReadSem (%p)\n", wId->waitingToReadSem);
00997 printf ("Buffer: %p\n", wId->buf);
00998 printf ("Size: %d\n", wId->size);
00999 printf ("Owner Task: 0x%x: ", wId->taskId);
01000 if (NULL != (name = taskName (wId->taskId)))
01001 {
01002 printf (name);
01003 printf ("\n");
01004 }
01005 printf ("Write Cnt: %d\n", wId->writeCnt);
01006 printf ("Read Cnt: %d\n", wId->readCnt);
01007 return OK;
01008 }
01009
01010
01011
01012 int
01013 bbdShow (BBD id, char *name)
01014 {
01015 char st[100];
01016 BBD_WRITER *wId, *wId2;
01017 BBD_READER *rId;
01018
01019 if (NULL == id && NULL != name)
01020 {
01021 id = bbdFindWriter (name);
01022 if (NULL == id)
01023 {
01024 printf ("Bad name or id\n");
01025 name = NULL;
01026 }
01027 }
01028
01029 if (id == NULL)
01030 {
01031 printf ("Master semaphore (%p) is ", bbdMasterSem);
01032 if (NULL != bbdMasterSem)
01033 {
01034 if (ERROR == semTake (bbdMasterSem, NO_WAIT))
01035 printf ("blocked\n");
01036 else
01037 {
01038 printf ("clear\n");
01039 semGive (bbdMasterSem);
01040 }
01041 }
01042 else
01043 printf ("NOT initialized\n");
01044
01045
01046 printf (" write id|write task|name => read tasks\n");
01047 for (wId = NULL; wId != bbdList; wId = wId2)
01048 {
01049 for (wId2 = bbdList; wId2->next != wId; wId2 = wId2->next);
01050 strncpy (st, wId2->name, 60);
01051 st[60] = 0;
01052 printf ("%10p ", wId2);
01053 bbdPrintTaskName (wId2->taskId, 10);
01054 printf (" | \"%s\"\n => ", st);
01055
01056
01057 rId = wId2->readers;
01058 if (NULL == rId)
01059 printf ("0");
01060 else
01061 {
01062 for (; rId != NULL; rId = rId->next)
01063 {
01064 if (NULL == (name = taskName (rId->taskId)))
01065 printf ("*** ");
01066 else
01067 printf ("%s ", name);
01068 }
01069 }
01070 printf ("\n");
01071
01072 }
01073 return 0;
01074 }
01075
01076 switch (*(BBD_TYPE *) id)
01077 {
01078 case BBD_SOLE_WRITER:
01079 case BBD_MULT_WRITER:
01080 bbdShowWriter ((BBD_WRITER *) id);
01081 printf ("\n");
01082 bbdShowReaders ((BBD_WRITER *) id);
01083 break;
01084 case BBD_MULT_READER:
01085 rId = (BBD_READER *) id;
01086 wId = rId->bbd;
01087 printf ("Mult Reader: ");
01088 strncpy (st, wId->name, 60);
01089 st[60] = 0;
01090 printf ("\"%s\"\n", st);
01091 printf ("bbd semaphore (%p) is ", wId->sem);
01092 if (ERROR == semTake (wId->sem, NO_WAIT))
01093 printf ("blocked\n");
01094 else
01095 {
01096 printf ("clear\n");
01097 semGive (wId->sem);
01098 }
01099 printf ("Writer id: %p\n", wId);
01100 printf ("Write Cnt: %d\n", wId->writeCnt);
01101 printf ("Read Cnt: %d\n", rId->readCnt);
01102 if (NULL == (name = taskName (rId->taskId)))
01103 printf ("Task name: ***\nTask Id: 0x%x\n", rId->taskId);
01104 else
01105 printf ("Task name: %s\n", name);
01106
01107 break;
01108 default:
01109 if (NULL == name)
01110 bbdShow (NULL, (char *) id);
01111 else
01112 bbdShow (NULL, name);
01113 break;
01114 }
01115 return 0;
01116 }