00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <blackboard/internal/memory_manager.h>
00025 #include <blackboard/exceptions.h>
00026 #include <blackboard/shmem/header.h>
00027
00028 #include <core/exception.h>
00029 #include <core/exceptions/software.h>
00030 #include <core/exceptions/system.h>
00031 #include <core/threading/mutex.h>
00032
00033 #include <utils/ipc/shm.h>
00034 #include <utils/ipc/shm_exceptions.h>
00035
00036 #include <cstdlib>
00037 #include <cstring>
00038 #include <cstdio>
00039 #include <sys/mman.h>
00040
00041
00042
00043
00044
00045
00046
00047 #define BBMM_MIN_FREE_CHUNK_SIZE sizeof(chunk_list_t)
00048
00049
00050 #define chunk_ptr(a) (__shmem ? (chunk_list_t *)__shmem->ptr(a) : a)
00051 #define chunk_addr(a) (__shmem ? (chunk_list_t *)__shmem->addr(a) : a)
00052
00053 namespace fawkes {
00054 #if 0
00055 }
00056 #endif
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 BlackBoardMemoryManager::BlackBoardMemoryManager(size_t memsize)
00108 {
00109 __shmem = NULL;
00110 __shmem_header = NULL;
00111 __memsize = memsize;
00112 __memory = malloc(memsize);
00113 __mutex = new Mutex();
00114 __master = true;
00115
00116
00117 mlock(__memory, __memsize);
00118
00119 chunk_list_t *f = (chunk_list_t *)__memory;
00120 f->ptr = (char *)f + sizeof(chunk_list_t);
00121 f->size = __memsize - sizeof(chunk_list_t);
00122 f->overhang = 0;
00123 f->next = NULL;
00124
00125 __free_list_head = f;
00126 __alloc_list_head = NULL;
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 BlackBoardMemoryManager::BlackBoardMemoryManager(size_t memsize,
00141 unsigned int version,
00142 bool master,
00143 const char *shmem_token)
00144 {
00145 __memory = NULL;
00146 __memsize = memsize;
00147 __master = master;
00148
00149
00150
00151
00152 __shmem_header = new BlackBoardSharedMemoryHeader(__memsize, version);
00153 try {
00154 __shmem = new SharedMemory(shmem_token, __shmem_header,
00155 false,
00156 __master,
00157 __master);
00158 __shmem_header->set_shared_memory(__shmem);
00159 } catch ( ShmCouldNotAttachException &e ) {
00160 delete __shmem_header;
00161 throw BBMemMgrCannotOpenException();
00162 }
00163
00164 if ( ! __shmem->is_valid() ) {
00165 __shmem->set_destroy_on_delete(false);
00166 delete __shmem;
00167 delete __shmem_header;
00168 throw BBMemMgrCannotOpenException();
00169 }
00170
00171 if ( master && ! __shmem->is_creator() ) {
00172
00173
00174 __shmem->set_destroy_on_delete(false);
00175 delete __shmem;
00176 delete __shmem_header;
00177 throw BBNotMasterException("Not owner of shared memory segment");
00178 }
00179
00180
00181
00182 if (master) {
00183
00184
00185 __shmem->add_semaphore();
00186
00187
00188
00189 __shmem->set_swapable(false);
00190
00191 chunk_list_t *f = (chunk_list_t *)__shmem->memptr();
00192 f->ptr = __shmem->addr((char *)f + sizeof(chunk_list_t));
00193 f->size = __memsize - sizeof(chunk_list_t);
00194 f->overhang = 0;
00195 f->next = NULL;
00196
00197 __shmem_header->set_free_list_head(f);
00198 __shmem_header->set_alloc_list_head(NULL);
00199 }
00200
00201 __mutex = new Mutex();
00202 }
00203
00204
00205
00206 BlackBoardMemoryManager::~BlackBoardMemoryManager()
00207 {
00208
00209 delete __shmem;
00210 delete __shmem_header;
00211 if (__memory) {
00212 ::free(__memory);
00213 }
00214 delete __mutex;
00215 }
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 void *
00228 BlackBoardMemoryManager::alloc_nolock(unsigned int num_bytes)
00229 {
00230
00231 chunk_list_t *l = __shmem ? __shmem_header->free_list_head() : __free_list_head;
00232
00233
00234 chunk_list_t *f = NULL;
00235 while ( l ) {
00236 if ( (l->size >= num_bytes) &&
00237 ( (f == NULL) || (l->size < f->size) ) ) {
00238 f = l;
00239 }
00240 l = chunk_ptr(l->next);
00241 }
00242
00243 if ( f == NULL ) {
00244
00245 throw OutOfMemoryException("BlackBoard ran out of memory");
00246 }
00247
00248
00249 if ( __shmem ) {
00250 __shmem_header->set_free_list_head( list_remove(__shmem_header->free_list_head(), f) );
00251 } else {
00252 __free_list_head = list_remove(__free_list_head, f);
00253 }
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 if ( f->size >= (num_bytes + BBMM_MIN_FREE_CHUNK_SIZE + sizeof(chunk_list_t)) ) {
00269
00270 chunk_list_t *nfc = (chunk_list_t *)((char *)f + sizeof(chunk_list_t) + num_bytes);
00271 nfc->ptr = __shmem ? __shmem->addr((char *)nfc + sizeof(chunk_list_t)) : (char *)nfc + sizeof(chunk_list_t);
00272 nfc->size = f->size - num_bytes - sizeof(chunk_list_t);
00273 nfc->overhang = 0;
00274
00275 if ( __shmem ) {
00276 __shmem_header->set_free_list_head( list_add(__shmem_header->free_list_head(), nfc) );
00277 } else {
00278 __free_list_head = list_add(__free_list_head, nfc);
00279 }
00280
00281 f->size = num_bytes;
00282 } else {
00283
00284
00285
00286 f->overhang = f->size - num_bytes;
00287 }
00288
00289
00290 if ( __shmem ) {
00291 __shmem_header->set_alloc_list_head( list_add(__shmem_header->alloc_list_head(), f) );
00292 return __shmem->ptr(f->ptr);
00293 } else {
00294 __alloc_list_head = list_add(__alloc_list_head, f);
00295 return f->ptr;
00296 }
00297
00298 }
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309 void *
00310 BlackBoardMemoryManager::alloc(unsigned int num_bytes)
00311 {
00312 void * ptr;
00313 __mutex->lock();
00314 if (__shmem) __shmem->lock_for_write();
00315 try {
00316 ptr = alloc_nolock(num_bytes);
00317 } catch (Exception &e) {
00318 if (__shmem) __shmem->unlock();
00319 __mutex->unlock();
00320 throw;
00321 }
00322 if (__shmem) __shmem->unlock();
00323 __mutex->unlock();
00324 return ptr;
00325 }
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338 void
00339 BlackBoardMemoryManager::free(void *ptr)
00340 {
00341 __mutex->lock();
00342 if (__shmem) {
00343 __shmem->lock_for_write();
00344
00345
00346 chunk_list_t *ac = list_find_ptr(__shmem_header->alloc_list_head(), chunk_addr(ptr));
00347 if ( ac == NULL ) {
00348 throw BlackBoardMemMgrInvalidPointerException();
00349 }
00350
00351
00352 __shmem_header->set_alloc_list_head( list_remove(__shmem_header->alloc_list_head(), ac) );
00353
00354
00355 ac->overhang = 0;
00356 __shmem_header->set_free_list_head( list_add(__shmem_header->free_list_head(), ac) );
00357
00358
00359 cleanup_free_chunks();
00360
00361 __shmem->unlock();
00362 } else {
00363
00364 chunk_list_t *ac = list_find_ptr(__alloc_list_head, ptr);
00365 if ( ac == NULL ) {
00366 throw BlackBoardMemMgrInvalidPointerException();
00367 }
00368
00369
00370 __alloc_list_head = list_remove(__alloc_list_head, ac);
00371
00372
00373 ac->overhang = 0;
00374 __free_list_head = list_add(__free_list_head, ac);
00375
00376
00377 cleanup_free_chunks();
00378 }
00379
00380 __mutex->unlock();
00381 }
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391 void
00392 BlackBoardMemoryManager::check()
00393 {
00394 chunk_list_t *f = __shmem ? __shmem_header->free_list_head() : __free_list_head;
00395 chunk_list_t *a = __shmem ? __shmem_header->alloc_list_head() : __alloc_list_head;
00396 chunk_list_t *t = NULL;
00397
00398 unsigned int mem = 0;
00399
00400
00401
00402 while ( f || a ) {
00403 if ( f == NULL ) {
00404 mem += a->size + sizeof(chunk_list_t);
00405 t = chunk_ptr(a->next);
00406 if ( t ) {
00407
00408 void *next = (char *)a->ptr + a->size + sizeof(chunk_list_t);
00409 if ( next != t->ptr ) {
00410 throw BBInconsistentMemoryException("non-contiguos allocated memory");
00411 }
00412 }
00413 a = t;
00414 } else if ( a == NULL ) {
00415 mem += f->size + sizeof(chunk_list_t);
00416 t = chunk_ptr(f->next);
00417 if ( t ) {
00418
00419 void *next = (char *)f->ptr + f->size + sizeof(chunk_list_t);
00420 if ( next != t->ptr ) {
00421 throw BBInconsistentMemoryException("non-contiguos allocated memory");
00422 }
00423 }
00424 f = t;
00425 } else if ( f->ptr == a->ptr ) {
00426 throw BBInconsistentMemoryException("ptr cannot be free and allocated at the same time");
00427 } else if ( f->ptr < a->ptr ) {
00428 mem += f->size + sizeof(chunk_list_t);
00429 void *next = (char *)f->ptr + f->size;
00430 t = chunk_ptr(f->next);
00431 if ( (next != t) && (next != a) ) {
00432 throw BBInconsistentMemoryException("there are unallocated bytes between chunks (f)");
00433 }
00434 f = t;
00435 } else {
00436 mem += a->size + sizeof(chunk_list_t);
00437 void *next = (char *)a->ptr + a->size;
00438 t = chunk_ptr(a->next);
00439 if ( (next != t) && (next != f) ) {
00440 throw BBInconsistentMemoryException("there are unallocated bytes between chunks (a)");
00441 }
00442 a = t;
00443 }
00444 }
00445
00446 if ( mem != __memsize ) {
00447 throw BBInconsistentMemoryException("unmanaged memory found, managed memory size != total memory size");
00448 }
00449 }
00450
00451
00452
00453
00454
00455
00456 bool
00457 BlackBoardMemoryManager::is_master() const
00458 {
00459 return __master;
00460 }
00461
00462
00463
00464
00465
00466 void
00467 BlackBoardMemoryManager::print_free_chunks_info() const
00468 {
00469 list_print_info( __shmem ? __shmem_header->free_list_head() : __free_list_head );
00470 }
00471
00472
00473
00474
00475
00476 void
00477 BlackBoardMemoryManager::print_allocated_chunks_info() const
00478 {
00479 list_print_info( __shmem ? __shmem_header->alloc_list_head() : __alloc_list_head );
00480 }
00481
00482
00483
00484
00485
00486
00487
00488 void
00489 BlackBoardMemoryManager::print_performance_info() const
00490 {
00491 printf("free chunks: %6u, alloc chunks: %6u, max free: %10u, max alloc: %10u, overhang: %10u\n",
00492 list_length( __shmem ? __shmem_header->free_list_head() : __free_list_head),
00493 list_length( __shmem ? __shmem_header->alloc_list_head() : __alloc_list_head),
00494 max_free_size(), max_allocated_size(), overhang_size());
00495 }
00496
00497
00498
00499
00500
00501
00502
00503 unsigned int
00504 BlackBoardMemoryManager::max_free_size() const
00505 {
00506 chunk_list_t *m = list_get_biggest( __shmem ? __shmem_header->free_list_head() : __free_list_head );
00507 if ( m == NULL ) {
00508 return 0;
00509 } else {
00510 return m->size;
00511 }
00512 }
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522 unsigned int
00523 BlackBoardMemoryManager::free_size() const
00524 {
00525 unsigned int free_size = 0;
00526 chunk_list_t *l = __shmem ? __shmem_header->free_list_head() : __free_list_head;
00527 while ( l ) {
00528 free_size += l->size;
00529 l = chunk_ptr(l->next);
00530 }
00531 return free_size;
00532 }
00533
00534
00535
00536
00537
00538
00539 unsigned int
00540 BlackBoardMemoryManager::allocated_size() const
00541 {
00542 unsigned int alloc_size = 0;
00543 chunk_list_t *l = __shmem ? __shmem_header->alloc_list_head() : __alloc_list_head;
00544 while ( l ) {
00545 alloc_size += l->size;
00546 l = chunk_ptr(l->next);
00547 }
00548 return alloc_size;
00549 }
00550
00551
00552
00553
00554
00555 unsigned int
00556 BlackBoardMemoryManager::num_allocated_chunks() const
00557 {
00558 return list_length( __shmem ? __shmem_header->alloc_list_head() : __alloc_list_head );
00559 }
00560
00561
00562
00563
00564
00565 unsigned int
00566 BlackBoardMemoryManager::num_free_chunks() const
00567 {
00568 return list_length( __shmem ? __shmem_header->free_list_head() : __free_list_head );
00569 }
00570
00571
00572
00573
00574
00575
00576 unsigned int
00577 BlackBoardMemoryManager::memory_size() const
00578 {
00579 return __memsize;
00580 }
00581
00582
00583
00584
00585
00586 unsigned int
00587 BlackBoardMemoryManager::version() const
00588 {
00589 return __shmem ? __shmem_header->version() : 0;
00590 }
00591
00592
00593
00594
00595
00596
00597 void
00598 BlackBoardMemoryManager::lock()
00599 {
00600 __mutex->lock();
00601 if (__shmem) __shmem->lock_for_write();
00602 }
00603
00604
00605
00606
00607
00608
00609
00610
00611 bool
00612 BlackBoardMemoryManager::try_lock()
00613 {
00614 if ( __mutex->try_lock() ) {
00615 if (__shmem) {
00616 if ( __shmem->try_lock_for_write() ) {
00617 return true;
00618 } else {
00619 __mutex->unlock();
00620 }
00621 } else {
00622 return true;
00623 }
00624 }
00625
00626 return false;
00627 }
00628
00629
00630
00631
00632
00633 void
00634 BlackBoardMemoryManager::unlock()
00635 {
00636 if (__shmem) __shmem->unlock();
00637 __mutex->unlock();
00638 }
00639
00640
00641
00642
00643
00644
00645
00646 unsigned int
00647 BlackBoardMemoryManager::max_allocated_size() const
00648 {
00649 chunk_list_t *m = list_get_biggest( __shmem ? __shmem_header->alloc_list_head() : __alloc_list_head);
00650 if ( m == NULL ) {
00651 return 0;
00652 } else {
00653 return m->size;
00654 }
00655 }
00656
00657
00658
00659
00660
00661
00662
00663 unsigned int
00664 BlackBoardMemoryManager::overhang_size() const
00665 {
00666 unsigned int overhang = 0;
00667 chunk_list_t *a = __shmem ? __shmem_header->alloc_list_head() : __alloc_list_head;
00668 while ( a ) {
00669 overhang += a->overhang;
00670 a = chunk_ptr(a->next);
00671 }
00672 return overhang;
00673 }
00674
00675
00676
00677
00678
00679
00680 void
00681 BlackBoardMemoryManager::cleanup_free_chunks()
00682 {
00683 bool modified = true;
00684 chunk_list_t *l;
00685 chunk_list_t *n;
00686
00687 while (modified) {
00688 modified = false;
00689 l = __shmem ? __shmem_header->free_list_head() : __free_list_head;
00690 n = chunk_ptr(l->next);
00691 while ( l && n) {
00692 if ( ((char *)l->ptr + l->size + sizeof(chunk_list_t)) == n->ptr ) {
00693
00694 l->size += n->size + sizeof(chunk_list_t);
00695 l->next = n->next;
00696 modified = true;
00697 }
00698 l = n;
00699 n = chunk_ptr(l->next);
00700 }
00701 }
00702 }
00703
00704
00705
00706
00707
00708
00709
00710
00711 chunk_list_t *
00712 BlackBoardMemoryManager::list_remove(chunk_list_t *list, chunk_list_t *rmel)
00713 {
00714 if ( list == NULL )
00715 throw NullPointerException("BlackBoardMemoryManager::list_remove: list == NULL");
00716 if ( rmel == NULL )
00717 throw NullPointerException("BlackBoardMemoryManager::list_remove: rmel == NULL");
00718
00719
00720 chunk_list_t *new_head = list;
00721 chunk_list_t *l = list;
00722 chunk_list_t *p = NULL;
00723
00724 while ( l ) {
00725 if ( l == rmel ) {
00726
00727 if ( p ) {
00728
00729 p->next = l->next;
00730 } else {
00731
00732 new_head = chunk_ptr(l->next);
00733 }
00734 break;
00735 }
00736 p = l;
00737 l = chunk_ptr(l->next);
00738 }
00739
00740 return new_head;
00741 }
00742
00743
00744
00745
00746
00747
00748
00749
00750 chunk_list_t *
00751 BlackBoardMemoryManager::list_add(chunk_list_t *list, chunk_list_t *addel)
00752 {
00753 if ( addel == NULL )
00754 throw NullPointerException("BlackBoardMemoryManager::list_add: addel == NULL");
00755
00756 chunk_list_t *new_head = list;
00757 chunk_list_t *l = list;
00758 chunk_list_t *p = NULL;
00759
00760 while ( l ) {
00761 if ( addel->ptr < l->ptr ) {
00762
00763 addel->next = chunk_addr(l);
00764 if ( p != NULL ) {
00765
00766
00767 p->next = chunk_addr(addel);
00768 } else {
00769 new_head = addel;
00770 }
00771
00772 l = addel;
00773 break;
00774 } else {
00775 p = l;
00776 l = chunk_ptr(l->next);
00777 }
00778 }
00779
00780
00781 if ( l != addel ) {
00782
00783 addel->next = NULL;
00784 if ( p ) {
00785 p->next = chunk_addr(addel);
00786 } else {
00787 new_head = addel;
00788 }
00789 }
00790
00791 return new_head;
00792 }
00793
00794
00795
00796
00797
00798
00799
00800 chunk_list_t *
00801 BlackBoardMemoryManager::list_find_ptr(chunk_list_t *list, void *ptr)
00802 {
00803 chunk_list_t *l = list;
00804 while ( l ) {
00805 if ( l->ptr == ptr ) {
00806
00807 return l;
00808 } else {
00809 l = chunk_ptr(l->next);
00810 }
00811 }
00812 return NULL;
00813 }
00814
00815
00816
00817
00818
00819
00820
00821 void
00822 BlackBoardMemoryManager::list_print_info(const chunk_list_t *list) const
00823 {
00824 chunk_list_t *l = (chunk_list_t *)list;
00825 unsigned int i = 0;
00826
00827 while ( l ) {
00828 printf("Chunk %3u: 0x%x size=%10u bytes overhang=%10u bytes\n",
00829 ++i, (unsigned int)(size_t)l->ptr, l->size, l->overhang);
00830 l = chunk_ptr(l->next);
00831 }
00832
00833 }
00834
00835
00836
00837
00838
00839
00840 unsigned int
00841 BlackBoardMemoryManager::list_length(const chunk_list_t *list) const
00842 {
00843 unsigned int l = 0;
00844 while ( list ) {
00845 ++l;
00846 list = chunk_ptr(list->next);
00847 }
00848 return l;
00849 }
00850
00851
00852
00853
00854
00855
00856 chunk_list_t *
00857 BlackBoardMemoryManager::list_get_biggest(const chunk_list_t *list) const
00858 {
00859 chunk_list_t *b = (chunk_list_t *)list;
00860 chunk_list_t *l = (chunk_list_t *)list;
00861 while ( l ) {
00862 if ( l->size > b->size ) {
00863 b = l;
00864 }
00865 l = chunk_ptr(l->next);
00866 }
00867
00868 return b;
00869 }
00870
00871
00872
00873
00874 BlackBoardMemoryManager::ChunkIterator
00875 BlackBoardMemoryManager::begin()
00876 {
00877 if (__shmem) {
00878 return BlackBoardMemoryManager::ChunkIterator(__shmem, __shmem_header->alloc_list_head() );
00879 } else {
00880 return BlackBoardMemoryManager::ChunkIterator(__alloc_list_head);
00881 }
00882 }
00883
00884
00885
00886
00887
00888
00889 BlackBoardMemoryManager::ChunkIterator
00890 BlackBoardMemoryManager::end()
00891 {
00892 return BlackBoardMemoryManager::ChunkIterator();
00893 }
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905 BlackBoardMemoryManager::ChunkIterator::ChunkIterator()
00906 {
00907 __shmem = NULL;
00908 __cur = NULL;
00909 }
00910
00911
00912
00913
00914
00915 BlackBoardMemoryManager::ChunkIterator::ChunkIterator(SharedMemory *shmem,
00916 chunk_list_t *cur)
00917 {
00918 __shmem = shmem;
00919 __cur = cur;
00920 }
00921
00922
00923
00924
00925
00926 BlackBoardMemoryManager::ChunkIterator::ChunkIterator(chunk_list_t *cur)
00927 {
00928 __shmem = NULL;
00929 __cur = cur;
00930 }
00931
00932
00933
00934
00935
00936 BlackBoardMemoryManager::ChunkIterator::ChunkIterator(const ChunkIterator &it)
00937 {
00938 __shmem = it.__shmem;
00939 __cur = it.__cur;
00940 }
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953 BlackBoardMemoryManager::ChunkIterator &
00954 BlackBoardMemoryManager::ChunkIterator::operator++()
00955 {
00956 if ( __cur != NULL ) __cur = chunk_ptr(__cur->next);
00957
00958 return *this;
00959 }
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977 BlackBoardMemoryManager::ChunkIterator
00978 BlackBoardMemoryManager::ChunkIterator::operator++(int inc)
00979 {
00980 ChunkIterator rv(*this);
00981 if ( __cur != NULL ) __cur = chunk_ptr(__cur->next);
00982
00983 return rv;
00984 }
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995 BlackBoardMemoryManager::ChunkIterator &
00996 BlackBoardMemoryManager::ChunkIterator::operator+(unsigned int i)
00997 {
00998 for (unsigned int j = 0; (__cur != NULL) && (j < i); ++j) {
00999 if ( __cur != NULL ) __cur = chunk_ptr(__cur->next);
01000 }
01001 return *this;
01002 }
01003
01004
01005
01006
01007
01008
01009
01010
01011 BlackBoardMemoryManager::ChunkIterator &
01012 BlackBoardMemoryManager::ChunkIterator::operator+=(unsigned int i)
01013 {
01014 for (unsigned int j = 0; (__cur != NULL) && (j < i); ++j) {
01015 if ( __cur != NULL ) __cur = chunk_ptr(__cur->next);
01016 }
01017 return *this;
01018 }
01019
01020
01021
01022
01023
01024
01025
01026 bool
01027 BlackBoardMemoryManager::ChunkIterator::operator==(const ChunkIterator & c) const
01028 {
01029 return (__cur == c.__cur);
01030 }
01031
01032
01033
01034
01035
01036
01037
01038 bool
01039 BlackBoardMemoryManager::ChunkIterator::operator!=(const ChunkIterator & c) const
01040 {
01041 return (__cur != c.__cur);
01042 }
01043
01044
01045
01046
01047
01048
01049
01050 void *
01051 BlackBoardMemoryManager::ChunkIterator::operator*() const
01052 {
01053 if ( __cur == NULL ) return NULL;
01054
01055 if (__shmem) return __shmem->ptr(__cur->ptr);
01056 else return __cur->ptr;
01057 }
01058
01059
01060
01061
01062
01063
01064
01065 BlackBoardMemoryManager::ChunkIterator &
01066 BlackBoardMemoryManager::ChunkIterator::operator=(const ChunkIterator & c)
01067 {
01068 __shmem = c.__shmem;
01069 __cur = c.__cur;
01070 return *this;
01071 }
01072
01073
01074
01075
01076
01077
01078 unsigned int
01079 BlackBoardMemoryManager::ChunkIterator::size() const
01080 {
01081 return ( __cur != NULL ) ? __cur->size : 0;
01082 }
01083
01084
01085
01086
01087
01088
01089
01090 unsigned int
01091 BlackBoardMemoryManager::ChunkIterator::overhang() const
01092 {
01093 return ( __cur != NULL ) ? __cur->overhang : 0;
01094 }
01095
01096 }