Mercurial > flash_v2
comparison packages/kernel/current/src/common/kapi.cxx @ 115:6ed91473a1cd ecos-sw-2000-08-21
Merge from eCos master repository on 2000-08-21-22:40:54-BST
| author | jlarmour |
|---|---|
| date | Fri, 25 Aug 2000 17:32:38 +0000 |
| parents | 5a0cc6c243a9 |
| children | d397fc472bcf |
comparison
equal
deleted
inserted
replaced
| 114:5ad2b71d525e | 115:6ed91473a1cd |
|---|---|
| 56 #include <cyg/kernel/thread.inl> // thread inlines | 56 #include <cyg/kernel/thread.inl> // thread inlines |
| 57 #include <cyg/kernel/sched.hxx> | 57 #include <cyg/kernel/sched.hxx> |
| 58 #include <cyg/kernel/intr.hxx> | 58 #include <cyg/kernel/intr.hxx> |
| 59 #include <cyg/kernel/clock.hxx> | 59 #include <cyg/kernel/clock.hxx> |
| 60 | 60 |
| 61 #include <cyg/kernel/memfixed.hxx> | |
| 62 #include <cyg/kernel/memvar.hxx> | |
| 63 | |
| 64 #include <cyg/kernel/sema.hxx> | 61 #include <cyg/kernel/sema.hxx> |
| 65 #include <cyg/kernel/flag.hxx> | 62 #include <cyg/kernel/flag.hxx> |
| 66 #include <cyg/kernel/mutex.hxx> | 63 #include <cyg/kernel/mutex.hxx> |
| 67 #include <cyg/kernel/mbox.hxx> | 64 #include <cyg/kernel/mbox.hxx> |
| 68 | 65 |
| 704 { | 701 { |
| 705 return ((Cyg_Mbox *)mbox)->waiting_to_put(); | 702 return ((Cyg_Mbox *)mbox)->waiting_to_put(); |
| 706 } | 703 } |
| 707 | 704 |
| 708 | 705 |
| 709 /*-----------------------------------------------------------------------*/ | |
| 710 /* Memory pools */ | |
| 711 | |
| 712 /* Create a variable size memory pool */ | |
| 713 externC void cyg_mempool_var_create( | |
| 714 void *base, /* base of memory to use for pool */ | |
| 715 cyg_int32 size, /* size of memory in bytes */ | |
| 716 cyg_handle_t *handle, /* returned handle of memory pool */ | |
| 717 cyg_mempool_var *var /* space to put pool structure in */ | |
| 718 ) | |
| 719 { | |
| 720 CYG_ASSERT_SIZES( cyg_mempool_var, Cyg_Mempool_Variable ); | |
| 721 | |
| 722 Cyg_Mempool_Variable *t = new((void *)var) Cyg_Mempool_Variable ( | |
| 723 (cyg_uint8 *)base, | |
| 724 size | |
| 725 ); | |
| 726 t=t; | |
| 727 | |
| 728 CYG_CHECK_DATA_PTR( handle, "Bad handle pointer" ); | |
| 729 *handle = (cyg_handle_t)var; | |
| 730 } | |
| 731 | |
| 732 /* Delete variable size memory pool */ | |
| 733 externC void cyg_mempool_var_delete(cyg_handle_t varpool) | |
| 734 { | |
| 735 ((Cyg_Mempool_Variable *)varpool)->~Cyg_Mempool_Variable(); | |
| 736 } | |
| 737 | |
| 738 /* Allocates a block of length size. This waits if the memory is not | |
| 739 currently available. */ | |
| 740 externC void *cyg_mempool_var_alloc(cyg_handle_t varpool, cyg_int32 size) | |
| 741 { | |
| 742 return ((Cyg_Mempool_Variable *)varpool)->alloc(size); | |
| 743 } | |
| 744 | |
| 745 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 746 | |
| 747 /* Allocates a block of length size. This waits for up to delay | |
| 748 ticks, if the memory is not already available. NULL is returned if | |
| 749 no memory is available. */ | |
| 750 externC void *cyg_mempool_var_timed_alloc( | |
| 751 cyg_handle_t varpool, | |
| 752 cyg_int32 size, | |
| 753 cyg_tick_count_t abstime) | |
| 754 { | |
| 755 return ((Cyg_Mempool_Variable *)varpool)->alloc(size, abstime); | |
| 756 } | |
| 757 | |
| 758 #endif | |
| 759 | |
| 760 /* Allocates a block of length size. NULL is returned if no memory is | |
| 761 available. */ | |
| 762 externC void *cyg_mempool_var_try_alloc( | |
| 763 cyg_handle_t varpool, | |
| 764 cyg_int32 size) | |
| 765 { | |
| 766 return ((Cyg_Mempool_Variable *)varpool)->try_alloc(size); | |
| 767 } | |
| 768 | |
| 769 /* Frees memory back into variable size pool. */ | |
| 770 externC void cyg_mempool_var_free(cyg_handle_t varpool, void *p) | |
| 771 { | |
| 772 cyg_bool b; | |
| 773 b = ((Cyg_Mempool_Variable *)varpool)->free((cyg_uint8 *)p, 0); | |
| 774 CYG_ASSERT( b, "Bad free"); | |
| 775 } | |
| 776 | |
| 777 | |
| 778 /* Returns true if there are any threads waiting for memory in the | |
| 779 given memory pool. */ | |
| 780 externC cyg_bool_t cyg_mempool_var_waiting(cyg_handle_t varpool) | |
| 781 { | |
| 782 return ((Cyg_Mempool_Variable *)varpool)->waiting(); | |
| 783 } | |
| 784 | |
| 785 /* Puts information about a variable memory pool into the structure | |
| 786 provided. */ | |
| 787 externC void cyg_mempool_var_get_info( | |
| 788 cyg_handle_t varpool, | |
| 789 cyg_mempool_info *info) | |
| 790 { | |
| 791 Cyg_Mempool_Variable *v = (Cyg_Mempool_Variable *)varpool; | |
| 792 cyg_uint8 *base; | |
| 793 CYG_ADDRWORD maxfree; | |
| 794 | |
| 795 info->totalmem = v->get_totalmem(); | |
| 796 info->freemem = v->get_freemem(); | |
| 797 v->get_arena(base, info->size, maxfree); | |
| 798 info->base = (void *)base; | |
| 799 info->blocksize = -1; | |
| 800 info->maxfree = maxfree; | |
| 801 } | |
| 802 | |
| 803 | |
| 804 /* Create a fixed size memory pool */ | |
| 805 externC void cyg_mempool_fix_create( | |
| 806 void *base, // base of memory to use for pool | |
| 807 cyg_int32 size, // size of memory in byte | |
| 808 cyg_int32 blocksize, // size of allocation in bytes | |
| 809 cyg_handle_t *handle, // handle of memory pool | |
| 810 cyg_mempool_fix *fix // space to put pool structure in | |
| 811 ) | |
| 812 { | |
| 813 CYG_ASSERT_SIZES( cyg_mempool_fix, Cyg_Mempool_Fixed ); | |
| 814 | |
| 815 Cyg_Mempool_Fixed *t = new((void *)fix) Cyg_Mempool_Fixed ( | |
| 816 (cyg_uint8 *)base, | |
| 817 size, | |
| 818 blocksize | |
| 819 ); | |
| 820 t=t; | |
| 821 | |
| 822 CYG_CHECK_DATA_PTR( handle, "Bad handle pointer" ); | |
| 823 *handle = (cyg_handle_t)fix; | |
| 824 } | |
| 825 | |
| 826 /* Delete fixed size memory pool */ | |
| 827 externC void cyg_mempool_fix_delete(cyg_handle_t fixpool) | |
| 828 { | |
| 829 ((Cyg_Mempool_Fixed *)fixpool)->~Cyg_Mempool_Fixed(); | |
| 830 } | |
| 831 | |
| 832 /* Allocates a block. This waits if the memory is not | |
| 833 currently available. */ | |
| 834 externC void *cyg_mempool_fix_alloc(cyg_handle_t fixpool) | |
| 835 { | |
| 836 return ((Cyg_Mempool_Fixed *)fixpool)->alloc(); | |
| 837 } | |
| 838 | |
| 839 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 840 | |
| 841 /* Allocates a block. This waits for up to delay ticks, if the memory | |
| 842 is not already available. NULL is returned if no memory is | |
| 843 available. */ | |
| 844 externC void *cyg_mempool_fix_timed_alloc( | |
| 845 cyg_handle_t fixpool, | |
| 846 cyg_tick_count_t abstime) | |
| 847 { | |
| 848 return ((Cyg_Mempool_Fixed *)fixpool)->alloc(abstime); | |
| 849 } | |
| 850 | |
| 851 #endif | |
| 852 | |
| 853 /* Allocates a block. NULL is returned if no memory is available. */ | |
| 854 externC void *cyg_mempool_fix_try_alloc(cyg_handle_t fixpool) | |
| 855 { | |
| 856 return ((Cyg_Mempool_Fixed *)fixpool)->try_alloc(); | |
| 857 } | |
| 858 | |
| 859 /* Frees memory back into fixed size pool. */ | |
| 860 externC void cyg_mempool_fix_free(cyg_handle_t fixpool, void *p) | |
| 861 { | |
| 862 cyg_bool b; | |
| 863 b = ((Cyg_Mempool_Fixed *)fixpool)->free((cyg_uint8 *)p); | |
| 864 CYG_ASSERT( b, "Bad free"); | |
| 865 } | |
| 866 | |
| 867 /* Returns true if there are any threads waiting for memory in the | |
| 868 given memory pool. */ | |
| 869 externC cyg_bool_t cyg_mempool_fix_waiting(cyg_handle_t fixpool) | |
| 870 { | |
| 871 return ((Cyg_Mempool_Fixed *)fixpool)->waiting(); | |
| 872 } | |
| 873 | |
| 874 /* Puts information about a variable memory pool into the structure | |
| 875 provided. */ | |
| 876 externC void cyg_mempool_fix_get_info( | |
| 877 cyg_handle_t fixpool, | |
| 878 cyg_mempool_info *info) | |
| 879 { | |
| 880 Cyg_Mempool_Fixed *f = (Cyg_Mempool_Fixed *)fixpool; | |
| 881 cyg_uint8 *base; | |
| 882 cyg_addrword_t blocksize; | |
| 883 | |
| 884 info->totalmem = f->get_totalmem(); | |
| 885 info->freemem = f->get_freemem(); | |
| 886 f->get_arena(base, info->size, blocksize); | |
| 887 info->base = (void *)base; | |
| 888 info->maxfree = info->blocksize = (cyg_int32)blocksize; | |
| 889 } | |
| 890 | |
| 891 /*---------------------------------------------------------------------------*/ | 706 /*---------------------------------------------------------------------------*/ |
| 892 /* Semaphores */ | 707 /* Semaphores */ |
| 893 | 708 |
| 894 externC void cyg_semaphore_init( | 709 externC void cyg_semaphore_init( |
| 895 cyg_sem_t *sem, /* Semaphore to init */ | 710 cyg_sem_t *sem, /* Semaphore to init */ |
| 905 externC void cyg_semaphore_destroy( cyg_sem_t *sem ) | 720 externC void cyg_semaphore_destroy( cyg_sem_t *sem ) |
| 906 { | 721 { |
| 907 ((Cyg_Counting_Semaphore *)sem)->~Cyg_Counting_Semaphore(); | 722 ((Cyg_Counting_Semaphore *)sem)->~Cyg_Counting_Semaphore(); |
| 908 } | 723 } |
| 909 | 724 |
| 910 externC void cyg_semaphore_wait( cyg_sem_t *sem ) | 725 externC cyg_bool_t cyg_semaphore_wait( cyg_sem_t *sem ) |
| 911 { | 726 { |
| 912 ((Cyg_Counting_Semaphore *)sem)->wait(); | 727 return ((Cyg_Counting_Semaphore *)sem)->wait(); |
| 913 } | 728 } |
| 914 | 729 |
| 915 #ifdef CYGFUN_KERNEL_THREADS_TIMER | 730 #ifdef CYGFUN_KERNEL_THREADS_TIMER |
| 916 externC cyg_bool_t cyg_semaphore_timed_wait( | 731 externC cyg_bool_t cyg_semaphore_timed_wait( |
| 917 cyg_sem_t *sem, | 732 cyg_sem_t *sem, |
| 1074 externC void cyg_cond_destroy( cyg_cond_t *cond ) | 889 externC void cyg_cond_destroy( cyg_cond_t *cond ) |
| 1075 { | 890 { |
| 1076 ((Cyg_Condition_Variable *)cond)->~Cyg_Condition_Variable(); | 891 ((Cyg_Condition_Variable *)cond)->~Cyg_Condition_Variable(); |
| 1077 } | 892 } |
| 1078 | 893 |
| 1079 externC void cyg_cond_wait( cyg_cond_t *cond ) | 894 externC cyg_bool_t cyg_cond_wait( cyg_cond_t *cond ) |
| 1080 { | 895 { |
| 1081 ((Cyg_Condition_Variable *)cond)->wait(); | 896 return ((Cyg_Condition_Variable *)cond)->wait(); |
| 1082 } | 897 } |
| 1083 | 898 |
| 1084 externC void cyg_cond_signal( cyg_cond_t *cond ) | 899 externC void cyg_cond_signal( cyg_cond_t *cond ) |
| 1085 { | 900 { |
| 1086 ((Cyg_Condition_Variable *)cond)->signal(); | 901 ((Cyg_Condition_Variable *)cond)->signal(); |
| 1138 CYG_CHECK_SIZES( cyg_interrupt, Cyg_Interrupt ); | 953 CYG_CHECK_SIZES( cyg_interrupt, Cyg_Interrupt ); |
| 1139 CYG_CHECK_SIZES( cyg_counter, Cyg_Counter ); | 954 CYG_CHECK_SIZES( cyg_counter, Cyg_Counter ); |
| 1140 CYG_CHECK_SIZES( cyg_clock, Cyg_Clock ); | 955 CYG_CHECK_SIZES( cyg_clock, Cyg_Clock ); |
| 1141 CYG_CHECK_SIZES( cyg_alarm, Cyg_Alarm ); | 956 CYG_CHECK_SIZES( cyg_alarm, Cyg_Alarm ); |
| 1142 CYG_CHECK_SIZES( cyg_mbox, Cyg_Mbox ); | 957 CYG_CHECK_SIZES( cyg_mbox, Cyg_Mbox ); |
| 1143 CYG_CHECK_SIZES( cyg_mempool_var, Cyg_Mempool_Variable ); | |
| 1144 CYG_CHECK_SIZES( cyg_mempool_fix, Cyg_Mempool_Fixed ); | |
| 1145 CYG_CHECK_SIZES( cyg_sem_t, Cyg_Counting_Semaphore ); | 958 CYG_CHECK_SIZES( cyg_sem_t, Cyg_Counting_Semaphore ); |
| 1146 CYG_CHECK_SIZES( cyg_flag_t, Cyg_Flag ); | 959 CYG_CHECK_SIZES( cyg_flag_t, Cyg_Flag ); |
| 1147 CYG_CHECK_SIZES( cyg_mutex_t, Cyg_Mutex ); | 960 CYG_CHECK_SIZES( cyg_mutex_t, Cyg_Mutex ); |
| 1148 CYG_CHECK_SIZES( cyg_cond_t, Cyg_Condition_Variable ); | 961 CYG_CHECK_SIZES( cyg_cond_t, Cyg_Condition_Variable ); |
| 1149 | 962 |
| 1150 CYG_ASSERT( !fail, "Size checks failed"); | 963 CYG_ASSERT( !fail, "Size checks failed"); |
| 1151 } | 964 } |
| 1152 | 965 |
| 1153 Cyg_Check_Structure_Sizes check_structure_sizes(1); | 966 static Cyg_Check_Structure_Sizes cyg_kapi_check_structure_sizes(1); |
| 1154 | 967 |
| 1155 #endif | 968 #endif |
| 1156 | 969 |
| 1157 | 970 |
| 1158 // ------------------------------------------------------------------------- | 971 // ------------------------------------------------------------------------- |
