00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CUFLOW_WHEEL_H
00019 #define CUFLOW_WHEEL_H
00020
00021 #include <cuflow/fwd.h>
00022 #include <cuflow/cdisj.h>
00023 #include <cu/clos.h>
00024 #include <atomic_ops.h>
00025
00026 CU_BEGIN_DECLARATIONS
00027
00028
00029
00030 #define CUFLOW_PROF_WHEEL 0
00031
00032 extern AO_t cuflowP_wheel_nfree;
00033 #if CUFLOW_PROF_WHEEL
00034 extern AO_t cuflowP_wheel_immcall_count;
00035 #endif
00036
00037 #if 0
00038 extern AO_t cuflowP_wheel_ratecounter;
00039 #define CUFLOW_WHEEL_RATELIM_STEP ((AO_t)1 << (sizeof(AO_t)*8 - 8))
00040 #define CUFLOWP_WHEEL_RATELIM_PASS \
00041 (!(AO_fetch_and_add(&cuflowP_wheel_ratecounter, CUFLOW_WHEEL_RATELIM_STEP)))
00042 #else
00043 #define CUFLOWP_WHEEL_RATELIM_PASS cu_true
00044 #endif
00045
00046 void cuflowP_wheel_call(cu_clop0(fn, void), AO_t *cdisj);
00047 void cuflowP_wheel_call_sub1(cu_clop0(fn, void), AO_t *cdisj);
00048
00049 CU_SINLINE void
00050 cuflow_wheel_call(cu_clop0(fn, void), AO_t *cdisj)
00051 {
00052 if (cu_expect_false(CUFLOWP_WHEEL_RATELIM_PASS &&
00053 (int)AO_load_acquire_read(&cuflowP_wheel_nfree) > 0))
00054 cuflowP_wheel_call(fn, cdisj);
00055 else {
00056 cu_call0(fn);
00057 #if CUFLOW_PROF_WHEEL
00058 AO_fetch_and_add1(&cuflowP_wheel_immcall_count);
00059 #endif
00060 }
00061 }
00062
00063 CU_SINLINE void
00064 cuflow_wheel_call_sub1(cu_clop0(fn, void), AO_t *cdisj)
00065 {
00066 if (cu_expect_false((int)AO_load_acquire_read(&cuflowP_wheel_nfree) > 0))
00067 cuflowP_wheel_call_sub1(fn, cdisj);
00068 else {
00069 cu_call0(fn);
00070 cuflow_cdisj_sub1_release_write(cdisj);
00071 #if CUFLOW_PROF_WHEEL
00072 AO_fetch_and_add1(&cuflowP_wheel_immcall_count);
00073 #endif
00074 }
00075 }
00076
00077
00078 CU_END_DECLARATIONS
00079
00080 #endif