├── .gitignore ├── docs ├── references.bib └── reference_manual.tex ├── src ├── Hazard_Pointers │ ├── README │ ├── gnat.adc │ └── example_stack.ads ├── util │ └── gnat.adc ├── Primitives │ ├── gnat.adc │ ├── nbada-process_identification.ads │ ├── README │ └── nbada-process_identification.adb ├── Lock-Free_Deque │ ├── gnat.adc │ ├── my_deque.ads │ ├── LFRC │ │ └── nbada-lock_free_deques_memory_reclamation_adapter.ads │ └── LFMR │ │ └── nbada-lock_free_deques_memory_reclamation_adapter.ads ├── Lock-Free_Priority_Queue_2 │ ├── nbada-lock_free_priority_queues.adb │ ├── nbada-lock_free_priority_queues.ads │ ├── LFMR │ │ └── nbada-lock_free_priority_queues_memory_reclamation_adapter.ads │ ├── LFRC │ │ └── nbada-lock_free_priority_queues_memory_reclamation_adapter.ads │ ├── gnat.adc │ ├── my_priority_queue.ads │ └── my_priority_queue.adb ├── Lock-Free_Sets │ ├── gnat.adc │ ├── HPMR │ │ └── nbada-lock_free_sets_memory_reclamation_adapter.ads │ └── EBMR │ │ └── nbada-lock_free_sets_memory_reclamation_adapter.ads ├── Lock-Free_Bounded_Queue │ ├── gnat.adc │ └── README ├── Lock-Free_Priority_Queue │ ├── gnat.adc │ ├── my_priority_queue.ads │ ├── my_priority_queue.adb │ ├── EBMR │ │ └── nbada-lock_free_priority_queues_memory_reclamation_adapter.ads │ └── HPMR │ │ └── nbada-lock_free_priority_queues_memory_reclamation_adapter.ads ├── Lock-Free_Red_Black_Tree │ ├── gnat.adc │ ├── my_dictionary.ads │ └── LFRC │ │ ├── nbada-lock_free_red_black_trees_memory_reclamation_adapter.ads │ │ └── nbada-lock_free_simple_trees_memory_reclamation_adapter.ads ├── Lock-Free_Storage_Pools │ └── gnat.adc ├── Epoch-Based_Memory_Reclamation │ ├── gnat.adc │ └── example_stack.ads ├── Lock-Free_Bounded_Priority_Queue │ └── gnat.adc ├── Lock-Free_Memory_Reclamation │ ├── nbada-memory_reclamation-beware_and_cleanup.adb │ ├── nbada-memory_reclamation-beware_and_cleanup.ads │ ├── controlled │ │ ├── nbada-lock_free_memory_reclamation.adb │ │ └── nbada-lock_free_memory_reclamation.ads │ ├── uncontrolled │ │ ├── nbada-lock_free_memory_reclamation.adb │ │ └── nbada-lock_free_memory_reclamation.ads │ ├── gnat.adc │ └── my_queue.ads ├── Pass_The_Buck │ ├── gnat.adc │ ├── nbada-pass_the_buck.ads │ └── lock_free_stack.ads ├── Lock-Free_Flat_Set │ └── gnat.adc ├── Lock-Free_LL_SC │ └── gnat.adc ├── Lock-Free_Queue │ ├── gnat.adc │ ├── HPMR │ │ └── nbada-lock_free_queues_memory_reclamation_adapter.ads │ ├── EBMR │ │ └── nbada-lock_free_queues_memory_reclamation_adapter.ads │ └── nbada-lock_free_queues.ads ├── Lock-Free_Queue_2 │ ├── gnat.adc │ ├── LFRC │ │ └── nbada-lock_free_queues_memory_reclamation_adapter.ads │ └── LFMR │ │ └── nbada-lock_free_queues_memory_reclamation_adapter.ads ├── Lock-Free_Queue_3 │ ├── gnat.adc │ ├── LFRC │ │ └── nbada-lock_free_queues_memory_reclamation_adapter.ads │ └── LFMR │ │ └── nbada-lock_free_queues_memory_reclamation_adapter.ads ├── Lock-Free_Stack │ ├── gnat.adc │ ├── HPMR │ │ └── nbada-lock_free_stacks_memory_reclamation_adapter.ads │ ├── EBMR │ │ └── nbada-lock_free_stacks_memory_reclamation_adapter.ads │ └── nbada-lock_free_stack.ads ├── benchmarks │ ├── Queues │ │ ├── gnat.adc │ │ ├── benchmark.sh │ │ ├── plot.gnuplot │ │ ├── extract_result.sh │ │ ├── README │ │ ├── Lock-Free_Queue │ │ │ └── test_queues.ads │ │ ├── Lock-Free_Deque_Left │ │ │ └── test_queues.ads │ │ ├── Lock-Free_Deque_Right │ │ │ └── test_queues.ads │ │ ├── Lock-Free_Queue_3 │ │ │ ├── test_queues.ads │ │ │ └── test_queues.adb │ │ └── Lock-Free_Bounded_Queue │ │ │ ├── test_queues.ads │ │ │ └── test_queues.adb │ ├── Stacks │ │ ├── gnat.adc │ │ ├── benchmark.sh │ │ ├── mutex-based │ │ │ ├── test_stack.ads │ │ │ └── mutex_based_stack.ads │ │ ├── spin-lock-based │ │ │ ├── test_stack.ads │ │ │ └── lock_based_stack.ads │ │ └── lock-free │ │ │ └── test_stack.ads │ ├── Dictionaries │ │ ├── gnat.adc │ │ ├── Lock-Free_Sets │ │ │ └── test_dictionaries.ads │ │ ├── Lock-Free_Dictionary │ │ │ └── test_dictionaries.ads │ │ ├── Lock-Free_Simple_Tree │ │ │ └── test_dictionaries.ads │ │ └── Red_Black_Trees │ │ │ ├── red_black_trees.ads │ │ │ └── mutex-based │ │ │ └── test_dictionaries.ads │ └── Priority_Queues │ │ └── Lock-Free_Priority_Queue │ │ └── test_priority_queues.ads ├── Lock-Free_Dictionary │ ├── gnat.adc │ └── nbada-lock_free_dictionaries.ads ├── Atomic_Multi-Writer_Snapshot │ ├── gnat.adc │ └── nbada-atomic_multiwriter_snapshots.ads ├── Lock-Free_Reference_Counting │ ├── gnat.adc │ ├── my_queue.ads │ └── example_queue.ads ├── Atomic_1-Writer_N-Reader_Register │ ├── gnat.adc │ └── atomic_test.adb ├── common │ ├── nbada-internals-cleanup_tools.adb │ ├── nbada-interfaces-exceptions.ads │ ├── nbada-internals-cleanup_tools.ads │ ├── nbada-interfaces.ads │ ├── nbada.ads │ ├── nbada-per_task_storage.ads │ ├── nbada-internals.ads │ ├── nbada-configuration.ads │ ├── nbada-per_task_storage-local.adb │ ├── nbada-per_task_storage-shared.adb │ ├── nbada-per_task_storage-local.ads │ ├── nbada-per_task_storage-shared.ads │ ├── nbada-memory_reclamation.ads │ └── nbada-internals-hash_tables.ads ├── STATUS ├── Lock-Free_Bag │ ├── HPMR │ │ └── nbada-lock_free_bags_memory_reclamation_adapter.ads │ └── EBMR │ │ └── nbada-lock_free_bags_memory_reclamation_adapter.ads └── debug │ └── memory_reclamation_debug.ads ├── README └── Makefile /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | *.ali 3 | *.o 4 | *~ 5 | -------------------------------------------------------------------------------- /docs/references.bib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andgi/NBAda/HEAD/docs/references.bib -------------------------------------------------------------------------------- /docs/reference_manual.tex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andgi/NBAda/HEAD/docs/reference_manual.tex -------------------------------------------------------------------------------- /src/Hazard_Pointers/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andgi/NBAda/HEAD/src/Hazard_Pointers/README -------------------------------------------------------------------------------- /src/util/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Ada_95; 6 | -------------------------------------------------------------------------------- /src/Primitives/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Ada_95; 6 | -------------------------------------------------------------------------------- /src/Lock-Free_Deque/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Ada_95; 6 | -------------------------------------------------------------------------------- /src/Lock-Free_Priority_Queue_2/nbada-lock_free_priority_queues.adb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andgi/NBAda/HEAD/src/Lock-Free_Priority_Queue_2/nbada-lock_free_priority_queues.adb -------------------------------------------------------------------------------- /src/Lock-Free_Priority_Queue_2/nbada-lock_free_priority_queues.ads: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andgi/NBAda/HEAD/src/Lock-Free_Priority_Queue_2/nbada-lock_free_priority_queues.ads -------------------------------------------------------------------------------- /src/Lock-Free_Sets/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Ada_95; 6 | -------------------------------------------------------------------------------- /src/Lock-Free_Bounded_Queue/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Ada_95; 6 | -------------------------------------------------------------------------------- /src/Lock-Free_Priority_Queue/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Ada_95; 6 | -------------------------------------------------------------------------------- /src/Lock-Free_Red_Black_Tree/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Ada_95; 6 | -------------------------------------------------------------------------------- /src/Lock-Free_Storage_Pools/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Ada_95; 6 | -------------------------------------------------------------------------------- /src/Epoch-Based_Memory_Reclamation/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Ada_95; 6 | -------------------------------------------------------------------------------- /src/Lock-Free_Bounded_Priority_Queue/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Ada_95; 6 | -------------------------------------------------------------------------------- /src/Lock-Free_Memory_Reclamation/nbada-memory_reclamation-beware_and_cleanup.adb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andgi/NBAda/HEAD/src/Lock-Free_Memory_Reclamation/nbada-memory_reclamation-beware_and_cleanup.adb -------------------------------------------------------------------------------- /src/Lock-Free_Memory_Reclamation/nbada-memory_reclamation-beware_and_cleanup.ads: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andgi/NBAda/HEAD/src/Lock-Free_Memory_Reclamation/nbada-memory_reclamation-beware_and_cleanup.ads -------------------------------------------------------------------------------- /src/Lock-Free_Memory_Reclamation/controlled/nbada-lock_free_memory_reclamation.adb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andgi/NBAda/HEAD/src/Lock-Free_Memory_Reclamation/controlled/nbada-lock_free_memory_reclamation.adb -------------------------------------------------------------------------------- /src/Lock-Free_Memory_Reclamation/controlled/nbada-lock_free_memory_reclamation.ads: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andgi/NBAda/HEAD/src/Lock-Free_Memory_Reclamation/controlled/nbada-lock_free_memory_reclamation.ads -------------------------------------------------------------------------------- /src/Lock-Free_Memory_Reclamation/uncontrolled/nbada-lock_free_memory_reclamation.adb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andgi/NBAda/HEAD/src/Lock-Free_Memory_Reclamation/uncontrolled/nbada-lock_free_memory_reclamation.adb -------------------------------------------------------------------------------- /src/Lock-Free_Memory_Reclamation/uncontrolled/nbada-lock_free_memory_reclamation.ads: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andgi/NBAda/HEAD/src/Lock-Free_Memory_Reclamation/uncontrolled/nbada-lock_free_memory_reclamation.ads -------------------------------------------------------------------------------- /src/Lock-Free_Priority_Queue_2/LFMR/nbada-lock_free_priority_queues_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andgi/NBAda/HEAD/src/Lock-Free_Priority_Queue_2/LFMR/nbada-lock_free_priority_queues_memory_reclamation_adapter.ads -------------------------------------------------------------------------------- /src/Lock-Free_Priority_Queue_2/LFRC/nbada-lock_free_priority_queues_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andgi/NBAda/HEAD/src/Lock-Free_Priority_Queue_2/LFRC/nbada-lock_free_priority_queues_memory_reclamation_adapter.ads -------------------------------------------------------------------------------- /src/Pass_The_Buck/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Restrictions (No_Abort_Statements); 6 | pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); 7 | pragma Ada_95; 8 | -------------------------------------------------------------------------------- /src/Hazard_Pointers/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Restrictions (No_Abort_Statements); 6 | pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); 7 | pragma Ada_95; 8 | -------------------------------------------------------------------------------- /src/Lock-Free_Flat_Set/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Restrictions (No_Abort_Statements); 6 | pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); 7 | pragma Ada_95; 8 | -------------------------------------------------------------------------------- /src/Lock-Free_LL_SC/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Restrictions (No_Abort_Statements); 6 | pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); 7 | pragma Ada_95; 8 | -------------------------------------------------------------------------------- /src/Lock-Free_Queue/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Restrictions (No_Abort_Statements); 6 | pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); 7 | pragma Ada_95; 8 | -------------------------------------------------------------------------------- /src/Lock-Free_Queue_2/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Restrictions (No_Abort_Statements); 6 | pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); 7 | pragma Ada_95; 8 | -------------------------------------------------------------------------------- /src/Lock-Free_Queue_3/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Restrictions (No_Abort_Statements); 6 | pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); 7 | pragma Ada_95; 8 | -------------------------------------------------------------------------------- /src/Lock-Free_Stack/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Restrictions (No_Abort_Statements); 6 | pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); 7 | pragma Ada_95; 8 | -------------------------------------------------------------------------------- /src/benchmarks/Queues/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Restrictions (No_Abort_Statements); 6 | pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); 7 | pragma Ada_95; 8 | -------------------------------------------------------------------------------- /src/benchmarks/Stacks/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Restrictions (No_Abort_Statements); 6 | pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); 7 | pragma Ada_95; 8 | -------------------------------------------------------------------------------- /src/Lock-Free_Dictionary/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Restrictions (No_Abort_Statements); 6 | pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); 7 | pragma Ada_95; 8 | -------------------------------------------------------------------------------- /src/benchmarks/Dictionaries/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Restrictions (No_Abort_Statements); 6 | pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); 7 | pragma Ada_95; 8 | -------------------------------------------------------------------------------- /src/Atomic_Multi-Writer_Snapshot/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Restrictions (No_Abort_Statements); 6 | pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); 7 | pragma Ada_95; 8 | -------------------------------------------------------------------------------- /src/Lock-Free_Memory_Reclamation/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Restrictions (No_Abort_Statements); 6 | pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); 7 | pragma Ada_95; 8 | -------------------------------------------------------------------------------- /src/Lock-Free_Priority_Queue_2/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Restrictions (No_Abort_Statements); 6 | pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); 7 | pragma Ada_95; 8 | -------------------------------------------------------------------------------- /src/Lock-Free_Reference_Counting/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Restrictions (No_Abort_Statements); 6 | pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); 7 | pragma Ada_95; 8 | -------------------------------------------------------------------------------- /src/Atomic_1-Writer_N-Reader_Register/gnat.adc: -------------------------------------------------------------------------------- 1 | pragma Warnings (On); 2 | pragma Initialize_Scalars; 3 | pragma Validity_Checks (ALL_CHECKS); 4 | pragma Style_Checks (ALL_CHECKS); 5 | pragma Restrictions (No_Abort_Statements); 6 | pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); 7 | pragma Ada_95; 8 | -------------------------------------------------------------------------------- /src/benchmarks/Stacks/benchmark.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # $Id: benchmark.sh,v 1.1 2007/10/04 11:54:35 andersg Exp $ 3 | # Benchmark batch job 4 | # Copyright (C) 2007 Anders Gidenstam 5 | # 6 | 7 | # job directory 8 | DIR=./ 9 | BIN=./ 10 | 11 | # The job 12 | cd $DIR 13 | 14 | # Lists of programs and worker threads 15 | PROGS="stack_test.ebmr stack_test.hpmr stack_test.mutex stack_test.splk" 16 | THREADS="1 2 4 8 16" 17 | 18 | # The number of repetitions of each experiment. 19 | SAMPLES="1 2 3 4 5 6 7 8 9 10" 20 | 21 | LOGBASE=result_`uname -n`_`uname`_`date +%Y-%m-%d_%H:%M`.log 22 | 23 | for T in $THREADS; do 24 | for S in $SAMPLES; do 25 | for PRG in $PROGS; do 26 | LOG=${PRG}_${LOGBASE} 27 | echo $PRG $T threads sample $S 28 | echo "% Sample: "$S >> $LOG 29 | $BIN/$PRG -u $T -o $T -s >> $LOG 30 | done 31 | done 32 | done -------------------------------------------------------------------------------- /src/benchmarks/Queues/benchmark.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # $Id: benchmark.sh,v 1.4 2008/01/11 18:48:56 andersg Exp $ 3 | # Benchmark batch job 4 | # Copyright (C) 2007 - 2008 Anders Gidenstam 5 | # 6 | 7 | # job directory 8 | DIR=./ 9 | BIN=./ 10 | 11 | # The job 12 | cd $DIR 13 | 14 | # Lists of programs and worker threads 15 | PROGS="queue_test.ebmr queue_test.hpmr queue_test.lfrc queue_test.lfmr queue_test.lfmr2 queue_test.bounded" 16 | THREADS="1 2 4 8 16" 17 | 18 | # The number of repetitions of each experiment. 19 | SAMPLES="1 2 3 4 5 6 7 8 9 10" 20 | 21 | LOGBASE=result_`uname -n`_`uname`_`date +%Y-%m-%d_%H:%M`.log 22 | 23 | for T in $THREADS; do 24 | for S in $SAMPLES; do 25 | for PRG in $PROGS; do 26 | LOG=${PRG}_${LOGBASE} 27 | echo $PRG $T threads sample $S 28 | echo "% Sample: "$S >> $LOG 29 | $BIN/$PRG -p $T -c $T -s >> $LOG 30 | done 31 | done 32 | done 33 | -------------------------------------------------------------------------------- /src/benchmarks/Queues/plot.gnuplot: -------------------------------------------------------------------------------- 1 | reset 2 | set terminal x11 3 | set output 4 | #set terminal png 5 | #set output "queues.png" 6 | set datafile separator " " 7 | set title "NBAda queue benchmark" 8 | set ylabel "Time (seconds)" 9 | set xlabel "#threads" 10 | 11 | #set yrange [0:100] 12 | 13 | plot \ 14 | "queue_test.ebmr_result_dork_Linux_2007-09-12_17:36.log.res"\ 15 | using "%lf %*lf %*lf %*lf %lf"\ 16 | title "M&S Queue/EBMR" with linespoints\ 17 | ,"queue_test.hpmr_result_dork_Linux_2007-09-12_17:36.log.res"\ 18 | using "%lf %*lf %*lf %*lf %lf"\ 19 | title "M&S Queue/HPMR" with linespoints\ 20 | ,"queue_test.lfmr_result_dork_Linux_2007-09-12_17:36.log.res"\ 21 | using "%lf %*lf %*lf %*lf %lf"\ 22 | title "M&S Queue/LFMR" with linespoints\ 23 | ,"queue_test.lfrc_result_dork_Linux_2007-09-12_17:36.log.res"\ 24 | using "%lf %*lf %*lf %*lf %lf"\ 25 | title "M&S Queue/LFRC" with linespoints\ 26 | 27 | exit -------------------------------------------------------------------------------- /src/benchmarks/Queues/extract_result.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # $Id: extract_result.sh,v 1.1 2008/01/11 18:48:56 andersg Exp $ 3 | # Extract the result in gnuplot form from an experiment log file. 4 | # Anders Gidenstam 2008 5 | # 6 | # Usage: extract_result.sh 7 | # 8 | 9 | exp=$1 10 | 11 | gawk \ 12 | ' 13 | BEGIN { 14 | last = 0; 15 | sumSamples = 0; 16 | numEnq = 0; 17 | numDeq = 0; 18 | sumTime = 0; 19 | faulty = 0; 20 | } 21 | /^ [[:digit:]]+ [[:digit:]]+ [[:digit:]]+/ { 22 | if ($1 != last) { 23 | if (last > 0) { 24 | print last, " ", last, " ", numEnq, " ", numDeq, " ", sumTime/sumSamples, " ", sumSamples, " ", faulty; 25 | } 26 | last = $1; 27 | numEnq = $3; 28 | numDeq = $4; 29 | sumSamples = 0; 30 | sumTime = 0; 31 | faulty = 0; 32 | } 33 | sumSamples += 1; 34 | sumTime += $5; 35 | if ((numDeq != $4) || (numEnq != $3)) { faulty=1; } 36 | #print $0; 37 | } 38 | END { 39 | print last, " ", last, " ", numEnq, " ", numDeq, " ", sumTime/sumSamples, " ", sumSamples, " ", faulty; 40 | }' \ 41 | $exp 42 | -------------------------------------------------------------------------------- /src/benchmarks/Stacks/mutex-based/test_stack.ads: -------------------------------------------------------------------------------- 1 | with Mutex_Based_Stack; 2 | with NBAda.Process_Identification; 3 | 4 | generic 5 | type Element_Type is private; 6 | -- Element type. 7 | with package Process_Ids is 8 | new NBAda.Process_Identification (<>); 9 | -- Process identification. 10 | package Test_Stack is 11 | 12 | package Stack is new 13 | Mutex_Based_Stack (Element_Type, Process_Ids); 14 | 15 | ---------------------------------------------------------------------------- 16 | -- Stack. 17 | ---------------------------------------------------------------------------- 18 | subtype Stack_Type is Stack.Stack_Type; 19 | 20 | Stack_Empty : exception renames Stack.Stack_Empty; 21 | 22 | procedure Push (On : in out Stack_Type; 23 | Element : in Element_Type) 24 | renames Stack.Push; 25 | procedure Pop (From : in out Stack_Type; 26 | Element : out Element_Type) 27 | renames Stack.Pop; 28 | function Pop (From : access Stack_Type) 29 | return Element_Type 30 | renames Stack.Pop; 31 | function Top (From : access Stack_Type) 32 | return Element_Type 33 | renames Stack.Top; 34 | 35 | 36 | end Test_Stack; 37 | -------------------------------------------------------------------------------- /src/benchmarks/Stacks/spin-lock-based/test_stack.ads: -------------------------------------------------------------------------------- 1 | with Lock_Based_Stack; 2 | with NBAda.Process_Identification; 3 | 4 | generic 5 | type Element_Type is private; 6 | -- Element type. 7 | with package Process_Ids is 8 | new NBAda.Process_Identification (<>); 9 | -- Process identification. 10 | package Test_Stack is 11 | 12 | package Stack is new 13 | Lock_Based_Stack (Element_Type, Process_Ids); 14 | 15 | ---------------------------------------------------------------------------- 16 | -- Stack. 17 | ---------------------------------------------------------------------------- 18 | subtype Stack_Type is Stack.Stack_Type; 19 | 20 | Stack_Empty : exception renames Stack.Stack_Empty; 21 | 22 | procedure Push (On : in out Stack_Type; 23 | Element : in Element_Type) 24 | renames Stack.Push; 25 | procedure Pop (From : in out Stack_Type; 26 | Element : out Element_Type) 27 | renames Stack.Pop; 28 | function Pop (From : access Stack_Type) 29 | return Element_Type 30 | renames Stack.Pop; 31 | function Top (From : access Stack_Type) 32 | return Element_Type 33 | renames Stack.Top; 34 | 35 | 36 | end Test_Stack; 37 | -------------------------------------------------------------------------------- /src/benchmarks/Stacks/lock-free/test_stack.ads: -------------------------------------------------------------------------------- 1 | with NBAda.Lock_Free_Stack; 2 | with NBAda.Process_Identification; 3 | 4 | generic 5 | type Element_Type is private; 6 | -- Element type. 7 | with package Process_Ids is 8 | new NBAda.Process_Identification (<>); 9 | -- Process identification. 10 | package Test_Stack is 11 | 12 | package Stack is new 13 | NBAda.Lock_Free_Stack (Element_Type, Process_Ids); 14 | 15 | ---------------------------------------------------------------------------- 16 | -- Stack. 17 | ---------------------------------------------------------------------------- 18 | subtype Stack_Type is Stack.Stack_Type; 19 | 20 | Stack_Empty : exception renames Stack.Stack_Empty; 21 | 22 | procedure Push (On : in out Stack_Type; 23 | Element : in Element_Type) 24 | renames Stack.Push; 25 | procedure Pop (From : in out Stack_Type; 26 | Element : out Element_Type) 27 | renames Stack.Pop; 28 | function Pop (From : access Stack_Type) 29 | return Element_Type 30 | renames Stack.Pop; 31 | function Top (From : access Stack_Type) 32 | return Element_Type 33 | renames Stack.Top; 34 | 35 | 36 | end Test_Stack; 37 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | NBAda - Non-blocking Algorithms and Data Structures 3 | =================================================== 4 | 5 | Copyright (C) 2002 - 2015 Anders Gidenstam anders(at)gidenstam.org 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | 21 | 22 | Install 23 | ------- 24 | 25 | Installing NBAda is simple: just extract the distribution archive 26 | anywhere you want. To make it convenient to compile programs that use 27 | componets from NBAda there is a utility, nbada_config, that outputs 28 | suitable commandline options for use with gnatmake. See Chapter 2 of 29 | the reference manual for full install instructions 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/common/nbada-internals-cleanup_tools.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- NBAda - A library of non-blocking algorithms and data structures. 3 | -- 4 | -- Copyright (C) 2008 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | 22 | pragma License (GPL); 23 | 24 | package body NBAda.Internals.Cleanup_Tools is 25 | 26 | procedure Finalize (Object : in out On_Exit) is 27 | begin 28 | if Object.Final_Action /= null then 29 | Object.Final_Action.all; 30 | end if; 31 | end Finalize; 32 | 33 | end NBAda.Internals.Cleanup_Tools; 34 | -------------------------------------------------------------------------------- /src/common/nbada-interfaces-exceptions.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- NBAda - A library of non-blocking algorithms and data structures. 3 | -- 4 | -- Copyright (C) 2008 - 2011 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | 22 | pragma License (GPL); 23 | 24 | package NBAda.Interfaces.Exceptions is 25 | 26 | pragma Pure (NBAda.Interfaces.Exceptions); 27 | 28 | Not_Found : exception; 29 | Already_Present : exception; 30 | Empty : exception; 31 | 32 | Not_Implemented : exception; 33 | 34 | end NBAda.Interfaces.Exceptions; 35 | -------------------------------------------------------------------------------- /src/Lock-Free_Bounded_Queue/README: -------------------------------------------------------------------------------- 1 | Ada implementation of P. Tsigas and Y. Zhang's lock-free FIFO queue 2 | ------------------------------------------------------------------- 3 | 4 | Copyright (C) 2005 Anders Gidenstam. All rights reserved. 5 | 6 | e-mail: anders-www@gidenstam.org 7 | www: http://www.gidenstam.org 8 | 9 | Introduction 10 | 11 | This is an Ada implementation of the lock-free bounded size FIFO queue 12 | algorithm presented by Philippas Tsigas and Yi Zhang in 13 | [P. Tsigas and Y. Zhang, "A Simple, Fast and Scalable Non-Blocking 14 | Concurrent FIFO Queue for Shared Memory Multiprocessor Systems", 15 | Proceedings of the 13th annual ACM symposium on Parallel algorithms and 16 | architectures (SPAA), 134--143, ACM, July 2001]. 17 | The FIFO queue can be used for any data type that can be represented in 18 | 32 bits with two unique values reserved for internal use (i.e. those 19 | two values must not occur as data). 20 | 21 | For more details of the algorithm see the paper, which can be found on 22 | Philippas Tsigas' publication page: 23 | http://www.cs.chalmers.se/~tsigas/pubs.html 24 | 25 | Test program 26 | 27 | The very minimal test program can be compiled with the following commands: 28 | 29 | On IA32: (i.e. Intel x86 architecture) 30 | > gnatmake -I../Primitives -I../Primitives/IA32 queue_test 31 | 32 | On SPARC: 33 | > gnatmake -I../Primitives -I../Primitives/SPARCv9 queue_test -cargs -Wa,-xarch=v8plus 34 | 35 | On MIPS Irix: 36 | > gnatmake -I../Primitives -I../Primitives/MIPSN32 queue_test 37 | 38 | -------------------------------------------------------------------------------- /src/common/nbada-internals-cleanup_tools.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- NBAda - A library of non-blocking algorithms and data structures. 3 | -- 4 | -- Copyright (C) 2008 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | 22 | pragma License (GPL); 23 | 24 | with Ada.Finalization; 25 | 26 | package NBAda.Internals.Cleanup_Tools is 27 | 28 | type Action is access procedure; 29 | 30 | type On_Exit (Final_Action : Action) is limited private; 31 | 32 | private 33 | 34 | type On_Exit (Final_Action : Action) is 35 | new Ada.Finalization.Limited_Controlled 36 | with null record; 37 | 38 | procedure Finalize (Object : in out On_Exit); 39 | 40 | end NBAda.Internals.Cleanup_Tools; 41 | -------------------------------------------------------------------------------- /src/common/nbada-interfaces.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- NBAda - A library of non-blocking algorithms and data structures. 3 | -- 4 | -- Copyright (C) 2008 - 2011 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : nbada-interfaces.ads 23 | -- Description : NBAda - A library of non-blocking algorithms and 24 | -- data structures. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Wed Jun 11 12:22:08 2007 27 | ------------------------------------------------------------------------------- 28 | 29 | pragma License (GPL); 30 | 31 | package NBAda.Interfaces is 32 | 33 | pragma Pure (NBAda.Interfaces); 34 | 35 | end NBAda.Interfaces; 36 | -------------------------------------------------------------------------------- /src/common/nbada.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- NBAda - A library of non-blocking algorithms and data structures. 3 | -- 4 | -- Copyright (C) 2007 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : nbada.ads 23 | -- Description : NBAda - A library of non-blocking algorithms and 24 | -- data structures. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Thu Aug 30 15:22:08 2007 27 | -- $Id: nbada.ads,v 1.2 2007/08/30 16:16:15 andersg Exp $ 28 | ------------------------------------------------------------------------------- 29 | 30 | pragma License (GPL); 31 | 32 | package NBAda is 33 | 34 | pragma Pure (NBAda); 35 | 36 | end NBAda; 37 | -------------------------------------------------------------------------------- /src/common/nbada-per_task_storage.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- NBAda - A library of non-blocking algorithms and data structures. 3 | -- 4 | -- Copyright (C) 2011 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : nbada-per_task_storage.ads 23 | -- Description : NBAda - A library of non-blocking algorithms and 24 | -- data structures. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Thu Aug 01 19:01:08 2011 27 | ------------------------------------------------------------------------------- 28 | 29 | pragma License (GPL); 30 | 31 | package NBAda.Per_Task_Storage is 32 | 33 | pragma Pure (NBAda.Per_Task_Storage); 34 | 35 | end NBAda.Per_Task_Storage; 36 | -------------------------------------------------------------------------------- /src/common/nbada-internals.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- NBAda - A library of non-blocking algorithms and data structures. 3 | -- 4 | -- Copyright (C) 2007 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : nbada-internals.ads 23 | -- Description : NBAda - A library of non-blocking algorithms and 24 | -- data structures. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Thu Aug 30 18:08:01 2007 27 | -- $Id: nbada-internals.ads,v 1.1 2007/08/30 16:16:15 andersg Exp $ 28 | ------------------------------------------------------------------------------- 29 | 30 | pragma License (GPL); 31 | 32 | package NBAda.Internals is 33 | 34 | pragma Pure (NBAda.Internals); 35 | 36 | end NBAda.Internals; 37 | -------------------------------------------------------------------------------- /src/common/nbada-configuration.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- NBAda - A library of non-blocking algorithms and data structures. 3 | -- 4 | -- Copyright (C) 2012 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : nbada-configuration.ads 23 | -- Description : NBAda - A library of non-blocking algorithms and 24 | -- data structures. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Thu Aug 03 12:31:08 2012 27 | ------------------------------------------------------------------------------- 28 | 29 | pragma License (GPL); 30 | 31 | 32 | package NBAda.Configuration is 33 | 34 | pragma Pure (NBAda.Configuration); 35 | 36 | Integrity_Checking : constant Boolean := False; 37 | -- Enables integrity checking in modules that support it. 38 | 39 | Collect_Statistics : constant Boolean := True; 40 | -- Enables collection of runtime statistics in modules 41 | -- that support it. 42 | 43 | end NBAda.Configuration; 44 | -------------------------------------------------------------------------------- /src/common/nbada-per_task_storage-local.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Per-object task local storage. 3 | -- Copyright (C) 2011 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | pragma Style_Checks (Off); 21 | ------------------------------------------------------------------------------- 22 | -- -*- Mode: Ada -*- 23 | -- Filename : nbada-per_task_storage-local.adb 24 | -- Description : A simple implementation of task local storage. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Thu Jun 07 19:55:00 2011 27 | ------------------------------------------------------------------------------- 28 | pragma Style_Checks (All_Checks); 29 | 30 | pragma License (GPL); 31 | 32 | package body NBAda.Per_Task_Storage.Local is 33 | 34 | function Get (Source : Storage) return Element_Access is 35 | ID : constant Process_Ids.Process_ID_Type := Process_Ids.Process_ID; 36 | begin 37 | if Source.Element (ID) = null then 38 | Source.Mutable.Self.Element (ID) := new Element_Type; 39 | end if; 40 | return Source.Element (ID); 41 | end Get; 42 | 43 | end NBAda.Per_Task_Storage.Local; 44 | -------------------------------------------------------------------------------- /src/Lock-Free_Reference_Counting/my_queue.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Queue - An implementation of Michael and Scott's lock-free queue. 3 | -- 4 | -- Copyright (C) 2004 - 2006 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : my_queue.ads 23 | -- Description : Example application for lock-free reference counting. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Thu Mar 2 18:49:40 2006 26 | -- $Id: my_queue.ads,v 1.3 2007/09/03 15:23:08 andersg Exp $ 27 | ------------------------------------------------------------------------------- 28 | 29 | pragma License (GPL); 30 | 31 | with NBAda.Process_Identification; 32 | with Example_Queue; 33 | 34 | package My_Queue is 35 | 36 | package PID is 37 | new NBAda.Process_Identification (Max_Number_Of_Processes => 32); 38 | 39 | type Value_Type is 40 | record 41 | Creator : PID.Process_ID_Type; 42 | Index : Integer; 43 | end record; 44 | package Queues is new Example_Queue (Value_Type => Value_Type, 45 | Process_Ids => PID); 46 | 47 | end My_Queue; 48 | -------------------------------------------------------------------------------- /src/Lock-Free_Deque/my_deque.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Deques - An Ada implementation of the lock-free deque algorithm 3 | -- by H. Sundell and P. Tsigas. 4 | -- 5 | -- Copyright (C) 2006 - 2008 Anders Gidenstam 6 | -- 7 | -- This program is free software; you can redistribute it and/or modify 8 | -- it under the terms of the GNU General Public License as published by 9 | -- the Free Software Foundation; either version 2 of the License, or 10 | -- (at your option) any later version. 11 | -- 12 | -- This program is distributed in the hope that it will be useful, 13 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | -- GNU General Public License for more details. 16 | -- 17 | -- You should have received a copy of the GNU General Public License 18 | -- along with this program; if not, write to the Free Software 19 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | -- 21 | ------------------------------------------------------------------------------- 22 | -- -*- Mode: Ada -*- 23 | -- Filename : my_deque.ads 24 | -- Description : Instantiation of the lock-free deque. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Thu Mar 2 16:41:48 2006 27 | -- $Id: my_deque.ads,v 1.4 2008/02/11 16:59:45 andersg Exp $ 28 | ------------------------------------------------------------------------------- 29 | 30 | with NBAda.Process_Identification; 31 | with NBAda.Lock_Free_Deques; 32 | 33 | package My_Deque is 34 | 35 | package PID is 36 | new NBAda.Process_Identification (Max_Number_Of_Processes => 64); 37 | 38 | type Value_Type is 39 | record 40 | Creator : PID.Process_ID_Type; 41 | Index : Integer; 42 | end record; 43 | 44 | package Deques is new NBAda.Lock_Free_Deques (Element_Type => Value_Type, 45 | Process_Ids => PID); 46 | 47 | end My_Deque; 48 | -------------------------------------------------------------------------------- /src/Primitives/nbada-process_identification.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Primitives - A binding to the synchronization primitives of the hardware. 3 | -- Copyright (C) 2004 - 2007 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | pragma Style_Checks (Off); 21 | ------------------------------------------------------------------------------- 22 | -- -*- Mode: Ada -*- 23 | -- Filename : process_identification.ads 24 | -- Description : Process IDs. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Fri Nov 19 15:56:51 2004 27 | -- $Id: nbada-process_identification.ads,v 1.6 2007/08/30 14:19:56 andersg Exp $ 28 | ------------------------------------------------------------------------------- 29 | pragma Style_Checks (All_Checks); 30 | 31 | pragma License (GPL); 32 | 33 | generic 34 | Max_Number_Of_Processes : Natural; 35 | package NBAda.Process_Identification is 36 | 37 | pragma Elaborate_Body; 38 | 39 | type Process_ID_Type is new Natural range 1 .. Max_Number_Of_Processes; 40 | 41 | -- Register a process ID for this task. 42 | procedure Register; 43 | 44 | -- Returns the process ID of the calling task. 45 | function Process_ID return Process_ID_Type; 46 | 47 | end NBAda.Process_Identification; 48 | -------------------------------------------------------------------------------- /src/Lock-Free_Memory_Reclamation/my_queue.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Reference Counting - An implementation of the lock-free 3 | -- garbage reclamation scheme by A. Gidenstam, M. Papatriantafilou, H. Sundell 4 | -- and P. Tsigas. 5 | -- 6 | -- Copyright (C) 2004 - 2006 Anders Gidenstam 7 | -- 8 | -- This program is free software; you can redistribute it and/or modify 9 | -- it under the terms of the GNU General Public License as published by 10 | -- the Free Software Foundation; either version 2 of the License, or 11 | -- (at your option) any later version. 12 | -- 13 | -- This program is distributed in the hope that it will be useful, 14 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | -- GNU General Public License for more details. 17 | -- 18 | -- You should have received a copy of the GNU General Public License 19 | -- along with this program; if not, write to the Free Software 20 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | -- 22 | ------------------------------------------------------------------------------- 23 | -- -*- Mode: Ada -*- 24 | -- Filename : my_queue.ads 25 | -- Description : Example application for lock-free reference counting. 26 | -- Author : Anders Gidenstam 27 | -- Created On : Thu Mar 2 18:49:40 2006 28 | -- $Id: my_queue.ads,v 1.2 2007/09/04 12:03:59 andersg Exp $ 29 | ------------------------------------------------------------------------------- 30 | 31 | pragma License (GPL); 32 | 33 | with NBAda.Process_Identification; 34 | with Example_Queue; 35 | 36 | package My_Queue is 37 | 38 | package PID is 39 | new NBAda.Process_Identification (Max_Number_Of_Processes => 32); 40 | 41 | type Value_Type is 42 | record 43 | Creator : PID.Process_ID_Type; 44 | Index : Integer; 45 | end record; 46 | package Queues is new Example_Queue (Value_Type => Value_Type, 47 | Process_Ids => PID); 48 | 49 | end My_Queue; 50 | -------------------------------------------------------------------------------- /src/Lock-Free_Queue/HPMR/nbada-lock_free_queues_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Queue - An implementation of Michael and Scott's lock-free queue. 3 | -- Copyright (C) 2007 - 2012 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | pragma Style_Checks (Off); 21 | ------------------------------------------------------------------------------- 22 | -- Filename : nbada-lock_free_queues_memory_reclamation_adapter.ads 23 | -- Description : An Ada implementation of Michael and Scott's 24 | -- lock-free queue algorithm. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Wed Sep 5 13:50:28 2007 27 | ------------------------------------------------------------------------------- 28 | pragma Style_Checks (All_Checks); 29 | 30 | pragma License (GPL); 31 | 32 | with NBAda.Memory_Reclamation.Hazard_Pointers; 33 | with NBAda.Process_Identification; 34 | 35 | generic 36 | 37 | with package Process_Ids is 38 | new NBAda.Process_Identification (<>); 39 | -- Process identification. 40 | 41 | package NBAda.Lock_Free_Queues_Memory_Reclamation_Adapter is 42 | 43 | package Memory_Reclamation is new NBAda.Memory_Reclamation.Hazard_Pointers 44 | (Max_Number_Of_Dereferences => 3, 45 | Process_Ids => Process_Ids); 46 | 47 | end NBAda.Lock_Free_Queues_Memory_Reclamation_Adapter; 48 | -------------------------------------------------------------------------------- /src/Lock-Free_Stack/HPMR/nbada-lock_free_stacks_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Stack - A lock-free stack using lock-free memory reclamation. 3 | -- Copyright (C) 2007 - 2012 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | pragma Style_Checks (Off); 21 | ------------------------------------------------------------------------------- 22 | -- -*- Mode: Ada -*- 23 | -- Filename : nbada-lock_free_stacks_memory_reclamation_adapter.ads 24 | -- Description : A lock-free stack using lock-free memory reclamation. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Thu Sep 6 17:50:28 2007 27 | ------------------------------------------------------------------------------- 28 | pragma Style_Checks (All_Checks); 29 | 30 | pragma License (GPL); 31 | 32 | with NBAda.Memory_Reclamation.Hazard_Pointers; 33 | with NBAda.Process_Identification; 34 | 35 | generic 36 | 37 | with package Process_Ids is 38 | new NBAda.Process_Identification (<>); 39 | -- Process identification. 40 | 41 | package NBAda.Lock_Free_Stacks_Memory_Reclamation_Adapter is 42 | 43 | package Memory_Reclamation is new NBAda.Memory_Reclamation.Hazard_Pointers 44 | (Max_Number_Of_Dereferences => 2, 45 | Process_Ids => Process_Ids); 46 | 47 | end NBAda.Lock_Free_Stacks_Memory_Reclamation_Adapter; 48 | -------------------------------------------------------------------------------- /src/Lock-Free_Priority_Queue/my_priority_queue.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Priority Queues - Based on the the lock-free set algorithm by 3 | -- M. Michael. 4 | -- 5 | -- Copyright (C) 2007 - 2008 Anders Gidenstam 6 | -- 7 | -- This program is free software; you can redistribute it and/or modify 8 | -- it under the terms of the GNU General Public License as published by 9 | -- the Free Software Foundation; either version 2 of the License, or 10 | -- (at your option) any later version. 11 | -- 12 | -- This program is distributed in the hope that it will be useful, 13 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | -- GNU General Public License for more details. 16 | -- 17 | -- You should have received a copy of the GNU General Public License 18 | -- along with this program; if not, write to the Free Software 19 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | -- 21 | ------------------------------------------------------------------------------- 22 | -- -*- Mode: Ada -*- 23 | -- Filename : my_priority_queue.ads 24 | -- Description : Test program for lock-free priority queues. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Mon Jun 11 15:15:56 2007 27 | -- $Id 28 | ------------------------------------------------------------------------------- 29 | 30 | pragma License (GPL); 31 | 32 | with NBAda.Lock_Free_Priority_Queues; 33 | with NBAda.Process_Identification; 34 | 35 | package My_Priority_Queue is 36 | 37 | package PID is 38 | new NBAda.Process_Identification (Max_Number_Of_Processes => 64); 39 | 40 | type Value_Type is 41 | record 42 | Creator : PID.Process_ID_Type; 43 | Index : Integer; 44 | end record; 45 | 46 | function "<" (Left, Right : Value_Type) return Boolean; 47 | function Image (X : Value_Type) return String; 48 | 49 | package Priority_Queues is new 50 | NBAda.Lock_Free_Priority_Queues 51 | (Element_Type => Value_Type, 52 | "<" => "<", 53 | Process_Ids => PID); 54 | 55 | end My_Priority_Queue; 56 | -------------------------------------------------------------------------------- /src/Primitives/README: -------------------------------------------------------------------------------- 1 | 2 | Ada binding to some hardware synchronization primitives 3 | ------------------------------------------------------- 4 | 5 | Copyright (C) 2004 - 2007 Anders Gidenstam. All rights reserved. 6 | 7 | anders-www (at) gidenstam.org 8 | 9 | Introduction 10 | 11 | The instruction sets of current processors often include support 12 | for hardware synchronization primitives which can be used to 13 | synchronize concurrent threads without using locks. 14 | 15 | I should write more here, but for the time being I'll refer to 16 | to the web-pages and publications by the research group I work in. 17 | 18 | http://www.cs.chalmers.se/~dcs/research.html#Synchronization 19 | http://www.cs.chalmers.se/~dcs/cgi-bin/readbib.py?1 20 | 21 | Supported platforms 22 | 23 | Presently the binding supports 32-bit versions of the 24 | 'Compare & Swap' and 'Fetch & Add' synchronization primitives on 25 | 26 | - SPARC v8+ and v9 based Sun workstations in 32 or 64-bit mode. 27 | 28 | - Intel IA32 compatible processors (486(?) or Pentium and newer). 29 | 30 | - MIPS 3 and higher based SGI workstations running Irix with the N32 ABI. 31 | 32 | Presently the binding supports 64-bit versions of the 33 | 'Compare & Swap' primitives on 34 | 35 | - Intel IA32 compatible processors (Pentium and newer). 36 | 37 | - SPARC v9 based Sun workstations in 64-bit mode. 38 | 39 | - 64-bit MIPS based SGI workstations running Irix with the N32 ABI. 40 | 41 | As the binding uses GNAT syntax for the inline assembler, other compilers 42 | than GNAT are unlikely to work without adapting the machine code insertions. 43 | 44 | Test programs 45 | 46 | The very minimal test programs can be compiled with the following commands: 47 | 48 | On IA32: 49 | > gnatmake -I./IA32 cas_test 50 | > gnatmake -I./IA32 faa_test 51 | 52 | On SPARC 32-bit: 53 | > gnatmake -I./SPARCv9 cas_test -cargs -Wa,-xarch=v8plus 54 | > gnatmake -I./SPARCv9 faa_test -cargs -Wa,-xarch=v8plus 55 | 56 | On SPARC 64-bit: 57 | > gnatmake -I./SPARCv9 -m64 --RTS=m64 cas_test -cargs -Wa,-xarch=v9 58 | > gnatmake -I./SPARCv9 -m64 --RTS=m64 faa_test -cargs -Wa,-xarch=v9 59 | 60 | On MIPS Irix: 61 | > gnatmake -I./MIPSN32 cas_test 62 | > gnatmake -I./MIPSN32 faa_test 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /src/Lock-Free_Priority_Queue_2/my_priority_queue.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Priority Queues - An implementation of the lock-free skip-list 3 | -- algorithm by H. Sundell. 4 | -- 5 | -- Copyright (C) 2007 Anders Gidenstam 6 | -- 7 | -- This program is free software; you can redistribute it and/or modify 8 | -- it under the terms of the GNU General Public License as published by 9 | -- the Free Software Foundation; either version 2 of the License, or 10 | -- (at your option) any later version. 11 | -- 12 | -- This program is distributed in the hope that it will be useful, 13 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | -- GNU General Public License for more details. 16 | -- 17 | -- You should have received a copy of the GNU General Public License 18 | -- along with this program; if not, write to the Free Software 19 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | -- 21 | ------------------------------------------------------------------------------- 22 | -- -*- Mode: Ada -*- 23 | -- Filename : my_priority_queue.ads 24 | -- Description : Test program for lock-free priority queues. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Mon Jun 11 15:15:56 2007 27 | -- $Id 28 | ------------------------------------------------------------------------------- 29 | 30 | pragma License (GPL); 31 | 32 | with NBAda.Lock_Free_Priority_Queues; 33 | with NBAda.Process_Identification; 34 | 35 | package My_Priority_Queue is 36 | 37 | package PID is 38 | new NBAda.Process_Identification (Max_Number_Of_Processes => 64); 39 | 40 | type Value_Type is 41 | record 42 | Creator : PID.Process_ID_Type; 43 | Index : Integer; 44 | end record; 45 | 46 | function "<" (Left, Right : Value_Type) return Boolean; 47 | function Image (X : Value_Type) return String; 48 | 49 | package Priority_Queues is new 50 | NBAda.Lock_Free_Priority_Queues 51 | (Element_Type => Value_Type, 52 | "<" => "<", 53 | Process_Ids => PID); 54 | 55 | end My_Priority_Queue; 56 | -------------------------------------------------------------------------------- /src/Lock-Free_Deque/LFRC/nbada-lock_free_deques_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Deques - An Ada implementation of the lock-free deque algorithm 3 | -- by H. Sundell and P. Tsigas. 4 | -- 5 | -- Copyright (C) 2007 - 2012 Anders Gidenstam 6 | -- 7 | -- This program is free software; you can redistribute it and/or modify 8 | -- it under the terms of the GNU General Public License as published by 9 | -- the Free Software Foundation; either version 2 of the License, or 10 | -- (at your option) any later version. 11 | -- 12 | -- This program is distributed in the hope that it will be useful, 13 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | -- GNU General Public License for more details. 16 | -- 17 | -- You should have received a copy of the GNU General Public License 18 | -- along with this program; if not, write to the Free Software 19 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | -- 21 | ------------------------------------------------------------------------------- 22 | pragma Style_Checks (Off); 23 | ------------------------------------------------------------------------------- 24 | -- Filename : nbada-lock_free_deques_memory_reclamation_adapter.ads 25 | -- Description : An Ada implementation of the lock-free deque algorithm 26 | -- by H. Sundell and P. Tsigas. 27 | -- Author : Anders Gidenstam 28 | -- Created On : Thu Sep 6 11:48:14 2007 29 | ------------------------------------------------------------------------------- 30 | pragma Style_Checks (All_Checks); 31 | 32 | pragma License (GPL); 33 | 34 | with NBAda.Memory_Reclamation.Lock_Free_Reference_Counting; 35 | with NBAda.Process_Identification; 36 | 37 | generic 38 | 39 | with package Process_Ids is 40 | new NBAda.Process_Identification (<>); 41 | -- Process identification. 42 | 43 | package NBAda.Lock_Free_Deques_Memory_Reclamation_Adapter is 44 | 45 | package Memory_Reclamation is 46 | new NBAda.Memory_Reclamation.Lock_Free_Reference_Counting 47 | (Process_Ids); 48 | 49 | end NBAda.Lock_Free_Deques_Memory_Reclamation_Adapter; 50 | -------------------------------------------------------------------------------- /src/benchmarks/Queues/README: -------------------------------------------------------------------------------- 1 | 2 | NBAda - Non-blocking Algorithms and Data Structures 3 | =================================================== 4 | 5 | Copyright (C) 2002 - 2008 Anders Gidenstam anders(at)gidenstam.org 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | 21 | 22 | Compilation 23 | =========== 24 | 25 | This benchmark can be built with several of the queue data structures 26 | in NBAda. 27 | 28 | Lock-Free_Bounded_Queue 29 | 30 | % gnatmake queue_test.adb -ILock-Free_Bounded_Queue `nbada_config LF_QUEUES_BOUNDED LF_POOLS` 31 | 32 | 33 | Lock-Free_Queue + EBMR / HPMR 34 | 35 | % gnatmake queue_test.adb -ILock-Free_Queue `nbada_config LF_QUEUES_EBMR` 36 | % gnatmake queue_test.adb -ILock-Free_Queue `nbada_config LF_QUEUES_HPMR` 37 | 38 | 39 | Lock-Free_Queue_2 + LFMR / LFRC 40 | 41 | % gnatmake queue_test.adb -ILock-Free_Queue `nbada_config LF_QUEUES_LFMR` 42 | % gnatmake queue_test.adb -ILock-Free_Queue `nbada_config LF_QUEUES_LFRC` 43 | 44 | 45 | LFMR example queue 46 | 47 | % gnatmake queue_test.adb -ILFMR `nbada_config LF_QUEUES_LFMR` 48 | 49 | 50 | LFRC example queue 51 | 52 | % gnatmake queue_test.adb -ILFRC `nbada_config LF_QUEUES_LFRC` 53 | 54 | 55 | Lock-Free_Deque Left + LFMR / LFRC 56 | % gnatmake queue_test.adb -ILock-Free_Deque_Left `nbada_config LF_DEQUES_LFMR` 57 | % gnatmake queue_test.adb -ILock-Free_Deque_Left `nbada_config LF_DEQUES_LFRC` 58 | 59 | 60 | Lock-Free_Deque Right + LFMR / LFRC 61 | % gnatmake queue_test.adb -ILock-Free_Deque_Right `nbada_config LF_DEQUES_LFMR` 62 | % gnatmake queue_test.adb -ILock-Free_Deque_Right `nbada_config LF_DEQUES_LFRC` 63 | -------------------------------------------------------------------------------- /src/Lock-Free_Stack/EBMR/nbada-lock_free_stacks_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Stack - A lock-free stack using lock-free memory reclamation. 3 | -- Copyright (C) 2007 - 2012 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | pragma Style_Checks (Off); 21 | ------------------------------------------------------------------------------- 22 | -- Filename : nbada-lock_free_stacks_memory_reclamation_adapter.ads 23 | -- Description : A lock-free stack using lock-free memory reclamation. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Thu Sep 6 17:50:28 2007 26 | ------------------------------------------------------------------------------- 27 | pragma Style_Checks (All_Checks); 28 | 29 | pragma License (GPL); 30 | 31 | with NBAda.Memory_Reclamation.Epoch_Based_Memory_Reclamation; 32 | with NBAda.Process_Identification; 33 | 34 | generic 35 | 36 | with package Process_Ids is 37 | new NBAda.Process_Identification (<>); 38 | -- Process identification. 39 | 40 | package NBAda.Lock_Free_Stacks_Memory_Reclamation_Adapter is 41 | 42 | package Memory_Reclamation is 43 | new NBAda.Memory_Reclamation.Epoch_Based_Memory_Reclamation 44 | (Epoch_Update_Threshold => 100, 45 | -- Suitable number for epoch-based reclamation. 46 | Process_Ids => Process_Ids); 47 | 48 | end NBAda.Lock_Free_Stacks_Memory_Reclamation_Adapter; 49 | -------------------------------------------------------------------------------- /src/Lock-Free_Red_Black_Tree/my_dictionary.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Dicitionaries - An implementation of the lock-free hash table 3 | -- algorithm by M. Michael. 4 | -- 5 | -- Copyright (C) 2007 Anders Gidenstam 6 | -- 7 | -- This program is free software; you can redistribute it and/or modify 8 | -- it under the terms of the GNU General Public License as published by 9 | -- the Free Software Foundation; either version 2 of the License, or 10 | -- (at your option) any later version. 11 | -- 12 | -- This program is distributed in the hope that it will be useful, 13 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | -- GNU General Public License for more details. 16 | -- 17 | -- You should have received a copy of the GNU General Public License 18 | -- along with this program; if not, write to the Free Software 19 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | -- 21 | ------------------------------------------------------------------------------- 22 | -- -*- Mode: Ada -*- 23 | -- Filename : my_dictionary.ads 24 | -- Description : Test of the lock-free set. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Fri May 18 14:48:33 2006 27 | -- $Id: my_dictionary.ads,v 1.1 2008/02/26 16:55:14 andersg Exp $ 28 | ------------------------------------------------------------------------------- 29 | 30 | pragma License (GPL); 31 | 32 | with NBAda.Process_Identification; 33 | with NBAda.Lock_Free_Red_Black_Trees; 34 | 35 | package My_Dictionary is 36 | 37 | package PID is 38 | new NBAda.Process_Identification (Max_Number_Of_Processes => 32); 39 | 40 | subtype Key_Type is Natural; 41 | type Value_Type is 42 | record 43 | Creator : PID.Process_ID_Type; 44 | Index : Integer; 45 | end record; 46 | 47 | package Dictionaries is new 48 | NBAda.Lock_Free_Red_Black_Trees (Key_Type => Key_Type, 49 | Value_Type => Value_Type, 50 | Image => Natural'Image, 51 | Process_Ids => PID); 52 | 53 | end My_Dictionary; 54 | -------------------------------------------------------------------------------- /src/STATUS: -------------------------------------------------------------------------------- 1 | Status of the NBAda components 2 | 3 | Component Status Release 4 | 5 | Hardware support 6 | 7 | Primitives OK. Fairly well tested. Y 8 | 9 | Atomic objects 10 | 11 | Atomic_1-Writer_N-Reader_Register OK. Not thoroughly tested. Y 12 | Atomic_Multi-Writer_Snapshot OK. Not thoroughly tested. Y 13 | 14 | Memory management and reclamation 15 | 16 | Lock-Free_Storage_Pools Ok. Fairly well tested. Some oddities. Y 17 | Epoch-Based_Memory_Reclamation OK. Fairly well tested. Y 18 | Hazard_Pointers OK. Fairly well tested. Y 19 | Pass_The_Buck OK, not well tested. Y 20 | Lock-Free_Reference_Counting Uncertain, not well tested. Some oddities. Y 21 | Lock-Free_Memory_Reclamation Uncertain, not well tested. Few oddities. Y 22 | 23 | Algorithms and Data-structures 24 | 25 | Lock-Free_LL_SC OK. Fairly well tested. Y 26 | Lock-Free_Stack Maybe OK. Y 27 | Lock-Free_Bounded_Queue Maybe OK. Some oddities. Y 28 | Lock-Free_Queue HPMR: Oddities. EBMR: OK. Y 29 | Lock-Free_Queue_2 LFMR: Looks OK. Y 30 | Lock-Free_Deque LFRC: Looks OK. LFMR: Looks OK. Y 31 | Lock-Free_Sets HPMR: A few oddities. EBMR: Looks OK. Y 32 | Lock-Free_Dictionary HPMR: Looks OK. EBMR: Looks OK. Y 33 | Lock-Free_Dictionary_2 Under construction. 34 | Lock-Free_Priority_Queue HPMR: Problems. EBMR: liveness problems. 35 | Lock-Free_Priority_Queue_2 LFMR: Okish. LFRC: Broken ? 36 | Lock-Free_Bounded_Priority_Queue Not working. 37 | 38 | 39 | Queue benchmark: 40 | bounded Oddities: FIFO + #dequeues. 41 | EBMR OK. 42 | HPMR Oddities: random STORAGE_ERROR exceptions. 43 | LFRC OK. 44 | LFMR OK. 45 | LF_QUEUE_LFMR OK. 46 | LF_QUEUE_LFRC OK? Oddities: Liveness? 47 | DEQUE_LFRC OK 48 | DEQUE_LFMR OK? Oddities: Reclamation safety? 49 | -------------------------------------------------------------------------------- /src/Lock-Free_Queue/EBMR/nbada-lock_free_queues_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Queue - An implementation of Michael and Scott's lock-free queue. 3 | -- Copyright (C) 2007 - 2012 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | pragma Style_Checks (Off); 21 | ------------------------------------------------------------------------------- 22 | -- Filename : nbada-lock_free_queues_memory_reclamation_adapter.ads 23 | -- Description : An Ada implementation of Michael and Scott's 24 | -- lock-free queue algorithm. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Wed Sep 5 13:50:28 2007 27 | ------------------------------------------------------------------------------- 28 | pragma Style_Checks (All_Checks); 29 | 30 | pragma License (GPL); 31 | 32 | with NBAda.Memory_Reclamation.Epoch_Based_Memory_Reclamation; 33 | with NBAda.Process_Identification; 34 | 35 | generic 36 | 37 | with package Process_Ids is 38 | new NBAda.Process_Identification (<>); 39 | -- Process identification. 40 | 41 | package NBAda.Lock_Free_Queues_Memory_Reclamation_Adapter is 42 | 43 | package Memory_Reclamation is 44 | new NBAda.Memory_Reclamation.Epoch_Based_Memory_Reclamation 45 | (Epoch_Update_Threshold => 100, 46 | -- Suitable number for epoch-based reclamation. 47 | Process_Ids => Process_Ids); 48 | 49 | end NBAda.Lock_Free_Queues_Memory_Reclamation_Adapter; 50 | -------------------------------------------------------------------------------- /src/Lock-Free_Priority_Queue/my_priority_queue.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Priority Queues - Based on the the lock-free set algorithm by 3 | -- M. Michael. 4 | -- 5 | -- Copyright (C) 2007 - 2008 Anders Gidenstam 6 | -- 7 | -- This program is free software; you can redistribute it and/or modify 8 | -- it under the terms of the GNU General Public License as published by 9 | -- the Free Software Foundation; either version 2 of the License, or 10 | -- (at your option) any later version. 11 | -- 12 | -- This program is distributed in the hope that it will be useful, 13 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | -- GNU General Public License for more details. 16 | -- 17 | -- You should have received a copy of the GNU General Public License 18 | -- along with this program; if not, write to the Free Software 19 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | -- 21 | ------------------------------------------------------------------------------- 22 | -- -*- Mode: Ada -*- 23 | -- Filename : my_priority_queue.adb 24 | -- Description : Test program for lock-free priority queues. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Mon Jun 11 19:23:38 2007 27 | -- $Id: my_priority_queue.adb,v 1.1 2008/02/20 20:55:38 andersg Exp $ 28 | ------------------------------------------------------------------------------- 29 | 30 | pragma License (GPL); 31 | 32 | package body My_Priority_Queue is 33 | 34 | ---------------------------------------------------------------------------- 35 | function "<" (Left, Right : Value_Type) return Boolean is 36 | use type PID.Process_ID_Type; 37 | begin 38 | return Left.Index < Right.Index or 39 | else (Left.Index = Right.Index and Left.Creator < Right.Creator); 40 | end "<"; 41 | 42 | ---------------------------------------------------------------------------- 43 | function Image (X : Value_Type) return String is 44 | begin 45 | return 46 | "(" & 47 | Integer'Image (X.Index) & ", " & 48 | PID.Process_ID_Type'Image (X.Creator) & 49 | ")"; 50 | end Image; 51 | 52 | end My_Priority_Queue; 53 | -------------------------------------------------------------------------------- /src/Lock-Free_Priority_Queue_2/my_priority_queue.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Priority Queues - An implementation of the lock-free skip-list 3 | -- algorithm by H. Sundell. 4 | -- 5 | -- Copyright (C) 2007 Anders Gidenstam 6 | -- 7 | -- This program is free software; you can redistribute it and/or modify 8 | -- it under the terms of the GNU General Public License as published by 9 | -- the Free Software Foundation; either version 2 of the License, or 10 | -- (at your option) any later version. 11 | -- 12 | -- This program is distributed in the hope that it will be useful, 13 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | -- GNU General Public License for more details. 16 | -- 17 | -- You should have received a copy of the GNU General Public License 18 | -- along with this program; if not, write to the Free Software 19 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | -- 21 | ------------------------------------------------------------------------------- 22 | -- -*- Mode: Ada -*- 23 | -- Filename : my_priority_queue.adb 24 | -- Description : Test program for lock-free priority queues. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Mon Jun 11 19:23:38 2007 27 | -- $Id: my_priority_queue.adb,v 1.1 2007/06/11 18:08:24 andersg Exp $ 28 | ------------------------------------------------------------------------------- 29 | 30 | pragma License (GPL); 31 | 32 | package body My_Priority_Queue is 33 | 34 | ---------------------------------------------------------------------------- 35 | function "<" (Left, Right : Value_Type) return Boolean is 36 | use type PID.Process_ID_Type; 37 | begin 38 | return Left.Index < Right.Index or 39 | else (Left.Index = Right.Index and Left.Creator < Right.Creator); 40 | end "<"; 41 | 42 | ---------------------------------------------------------------------------- 43 | function Image (X : Value_Type) return String is 44 | begin 45 | return 46 | "(" & 47 | Integer'Image (X.Index) & ", " & 48 | PID.Process_ID_Type'Image (X.Creator) & 49 | ")"; 50 | end Image; 51 | 52 | end My_Priority_Queue; 53 | -------------------------------------------------------------------------------- /src/common/nbada-per_task_storage-shared.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Per-object per-task shared storage. 3 | -- Copyright (C) 2011 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | pragma Style_Checks (Off); 21 | ------------------------------------------------------------------------------- 22 | -- -*- Mode: Ada -*- 23 | -- Filename : nbada-per_task_storage-shared.adb 24 | -- Description : A simple implementation of per-task shared storage. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Tue Aug 02 14:07:00 2011 27 | ------------------------------------------------------------------------------- 28 | pragma Style_Checks (All_Checks); 29 | 30 | pragma License (GPL); 31 | 32 | package body NBAda.Per_Task_Storage.Shared is 33 | 34 | ---------------------------------------------------------------------------- 35 | function Get (Source : Storage) return Element_Access is 36 | ID : constant Process_Ids.Process_ID_Type := Process_Ids.Process_ID; 37 | begin 38 | if Source.Element (ID) = null then 39 | Source.Mutable.Self.Element (ID) := new Element_Type; 40 | end if; 41 | return Source.Element (ID); 42 | end Get; 43 | 44 | ---------------------------------------------------------------------------- 45 | function Get (Source : Storage; 46 | Owner : Process_Ids.Process_ID_Type) return Element_Access is 47 | begin 48 | return Source.Element (Owner); 49 | end Get; 50 | 51 | end NBAda.Per_Task_Storage.Shared; 52 | -------------------------------------------------------------------------------- /src/Lock-Free_Red_Black_Tree/LFRC/nbada-lock_free_red_black_trees_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Red Black Trees - An implementation of the lock-free red black 3 | -- tree algorithm by A. Gidenstam. 4 | -- 5 | -- Copyright (C) 2008 Anders Gidenstam 6 | -- 7 | -- This program is free software; you can redistribute it and/or modify 8 | -- it under the terms of the GNU General Public License as published by 9 | -- the Free Software Foundation; either version 2 of the License, or 10 | -- (at your option) any later version. 11 | -- 12 | -- This program is distributed in the hope that it will be useful, 13 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | -- GNU General Public License for more details. 16 | -- 17 | -- You should have received a copy of the GNU General Public License 18 | -- along with this program; if not, write to the Free Software 19 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | -- 21 | ------------------------------------------------------------------------------- 22 | pragma Style_Checks (Off); 23 | ------------------------------------------------------------------------------- 24 | -- -*- Mode: Ada -*- 25 | -- Filename : nbada-lock_free_deques_memory_reclamation_adapter.ads 26 | -- Description : An Ada implementation of the lock-free deque algorithm 27 | -- by H. Sundell and P. Tsigas. 28 | -- Author : Anders Gidenstam 29 | -- Created On : Thu Sep 6 11:48:14 2007 30 | -- $Id: nbada-lock_free_red_black_trees_memory_reclamation_adapter.ads,v 1.1 2008/02/26 16:55:14 andersg Exp $ 31 | ------------------------------------------------------------------------------- 32 | pragma Style_Checks (All_Checks); 33 | 34 | pragma License (GPL); 35 | 36 | with NBAda.Lock_Free_Reference_Counting; 37 | with NBAda.Process_Identification; 38 | 39 | generic 40 | 41 | with package Process_Ids is 42 | new NBAda.Process_Identification (<>); 43 | -- Process identification. 44 | 45 | package NBAda.Lock_Free_Red_Black_Trees_Memory_Reclamation_Adapter is 46 | 47 | package Memory_Reclamation is new NBAda.Lock_Free_Reference_Counting 48 | (Max_Number_Of_Guards => 128); 49 | 50 | end NBAda.Lock_Free_Red_Black_Trees_Memory_Reclamation_Adapter; 51 | -------------------------------------------------------------------------------- /src/common/nbada-per_task_storage-local.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Per-object task local storage. 3 | -- Copyright (C) 2011 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | pragma Style_Checks (Off); 21 | ------------------------------------------------------------------------------- 22 | -- -*- Mode: Ada -*- 23 | -- Filename : nbada-per_task_storage-local.ads 24 | -- Description : A simple implementation of task local storage. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Thu Jun 07 19:55:00 2011 27 | ------------------------------------------------------------------------------- 28 | pragma Style_Checks (All_Checks); 29 | 30 | pragma License (GPL); 31 | 32 | with NBAda.Process_Identification; 33 | 34 | generic 35 | 36 | type Element_Type is limited private; 37 | -- Element type. 38 | 39 | with package Process_Ids is 40 | new Process_Identification (<>); 41 | -- Process identification. 42 | 43 | package NBAda.Per_Task_Storage.Local is 44 | 45 | type Element_Access is access Element_Type; 46 | 47 | type Storage is limited private; 48 | 49 | function Get (Source : in Storage) return Element_Access; 50 | 51 | private 52 | 53 | type Element_Array is array (Process_Ids.Process_ID_Type) of Element_Access; 54 | 55 | type Mutable_View (Self : access Storage) is 56 | limited null record; 57 | 58 | type Storage is 59 | limited record 60 | Element : Element_Array; 61 | Mutable : Mutable_View (Storage'Access); 62 | end record; 63 | 64 | end NBAda.Per_Task_Storage.Local; 65 | -------------------------------------------------------------------------------- /src/Lock-Free_Queue_2/LFRC/nbada-lock_free_queues_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Queue - An implementation of M. Hoffman, O. Shalev and 3 | -- N. Shavit's lock-free queue algorithm. 4 | -- Copyright (C) 2008 - 2012 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | pragma Style_Checks (Off); 22 | ------------------------------------------------------------------------------- 23 | -- Filename : nbada-lock_free_queues_memory_reclamation_adapter.ads 24 | -- Description : A lock-free queue algorithm based on 25 | -- M. Hoffman, O. Shalev and N. Shavit, 26 | -- "The Baskets Queue", The 11th International Conference 27 | -- On the Principles Of Distributed Systems (OPODIS'07), 28 | -- LNCS 4878, pp. 401-414, 2007. 29 | -- Author : Anders Gidenstam 30 | -- Created On : Thu Jan 10 19:57:44 2008 31 | ------------------------------------------------------------------------------- 32 | 33 | pragma Style_Checks (All_Checks); 34 | 35 | pragma License (GPL); 36 | 37 | with NBAda.Memory_Reclamation.Lock_Free_Reference_Counting; 38 | with NBAda.Process_Identification; 39 | 40 | generic 41 | 42 | with package Process_Ids is 43 | new NBAda.Process_Identification (<>); 44 | -- Process identification. 45 | 46 | package NBAda.Lock_Free_Queues_Memory_Reclamation_Adapter is 47 | 48 | package Memory_Reclamation is 49 | new NBAda.Memory_Reclamation.Lock_Free_Reference_Counting 50 | (Process_Ids); 51 | 52 | end NBAda.Lock_Free_Queues_Memory_Reclamation_Adapter; 53 | -------------------------------------------------------------------------------- /src/Lock-Free_Sets/HPMR/nbada-lock_free_sets_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Sets - An implementation of the lock-free set algorithm by 3 | -- M. Michael. 4 | -- 5 | -- Copyright (C) 2007 - 2012 Anders Gidenstam 6 | -- 7 | -- This program is free software; you can redistribute it and/or modify 8 | -- it under the terms of the GNU General Public License as published by 9 | -- the Free Software Foundation; either version 2 of the License, or 10 | -- (at your option) any later version. 11 | -- 12 | -- This program is distributed in the hope that it will be useful, 13 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | -- GNU General Public License for more details. 16 | -- 17 | -- You should have received a copy of the GNU General Public License 18 | -- along with this program; if not, write to the Free Software 19 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | -- 21 | ------------------------------------------------------------------------------- 22 | pragma Style_Checks (Off); 23 | ------------------------------------------------------------------------------- 24 | -- Filename : nbada-lock_free_sets_memory_reclamation_adapter.ads 25 | -- Description : Lock-free list-based sets based on Maged Michael, 26 | -- "High Performance Dynamic Lock-Free Hash Tables and 27 | -- List-Based Sets", The 14th Annual ACM Symposium on 28 | -- Parallel Algorithms and Architectures (SPAA'02), 29 | -- pages 73-82, August 2002. 30 | -- Author : Anders Gidenstam 31 | -- Created On : Wed Sep 5 17:01:01 2007 32 | ------------------------------------------------------------------------------- 33 | pragma Style_Checks (All_Checks); 34 | 35 | pragma License (GPL); 36 | 37 | with NBAda.Memory_Reclamation.Hazard_Pointers; 38 | with NBAda.Process_Identification; 39 | 40 | generic 41 | 42 | with package Process_Ids is 43 | new NBAda.Process_Identification (<>); 44 | -- Process identification. 45 | 46 | package NBAda.Lock_Free_Sets_Memory_Reclamation_Adapter is 47 | 48 | package Memory_Reclamation is 49 | new NBAda.Memory_Reclamation.Hazard_Pointers 50 | (Process_Ids => Process_Ids, 51 | Max_Number_Of_Dereferences => 4); 52 | 53 | end NBAda.Lock_Free_Sets_Memory_Reclamation_Adapter; 54 | -------------------------------------------------------------------------------- /src/Lock-Free_Queue_3/LFRC/nbada-lock_free_queues_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Queue - An implementation of the cache-aware lock-free queue 3 | -- algorithm by A. Gidenstam, H. Sundell and P. Tsigas. 4 | -- Copyright (C) 2011 - 2012 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | pragma Style_Checks (Off); 22 | ------------------------------------------------------------------------------- 23 | -- Description : A lock-free queue algorithm based on 24 | -- A. Gidenstam, H. Sundell and P. Tsigas, 25 | -- "Cache-Aware Lock-Free Queues for Multiple 26 | -- Producers/Consumers and Weak Memory Consistency", 27 | -- The 14th International Conference 28 | -- On the Principles Of Distributed Systems (OPODIS'10), 29 | -- LNCS 6490, pp. 302-317, 2011. 30 | -- Author : Anders Gidenstam 31 | -- Created On : Thu Jun 07 19:49:28 2011 32 | ------------------------------------------------------------------------------- 33 | pragma Style_Checks (All_Checks); 34 | 35 | pragma License (GPL); 36 | 37 | with NBAda.Memory_Reclamation.Lock_Free_Reference_Counting; 38 | with NBAda.Process_Identification; 39 | 40 | generic 41 | 42 | with package Process_Ids is 43 | new NBAda.Process_Identification (<>); 44 | -- Process identification. 45 | 46 | package NBAda.Lock_Free_Queues_Memory_Reclamation_Adapter is 47 | 48 | package Memory_Reclamation is 49 | new NBAda.Memory_Reclamation.Lock_Free_Reference_Counting 50 | (Process_Ids); 51 | 52 | end NBAda.Lock_Free_Queues_Memory_Reclamation_Adapter; 53 | -------------------------------------------------------------------------------- /src/Lock-Free_Bag/HPMR/nbada-lock_free_bags_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free bag - An implementation of the lock-free bag algorithm 3 | -- by H. Sundell, A. Gidenstam, M. Papatriantafilou and P. Tsigas. 4 | -- Copyright (C) 2011 - 2012 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | pragma Style_Checks (Off); 22 | ------------------------------------------------------------------------------- 23 | -- Description : A lock-free bag algorithm based on 24 | -- H. Sundell, A. Gidenstam, M. Papatriantafilou and 25 | -- P. Tsigas, 26 | -- "A Lock-Free Algorithm for Concurrent Bags", 27 | -- Proceedings of the 23rd Annual Symposium on Parallelism 28 | -- in Algorithms and Architectures (SPAA 2011), 29 | -- pages 335 - 344, ACM, 2011. 30 | -- Author : Anders Gidenstam 31 | -- Created On : Thu Aug 02 16:25:00 2011 32 | ------------------------------------------------------------------------------- 33 | pragma Style_Checks (All_Checks); 34 | 35 | pragma License (GPL); 36 | 37 | with NBAda.Memory_Reclamation.Hazard_Pointers; 38 | with NBAda.Process_Identification; 39 | 40 | generic 41 | 42 | with package Process_Ids is 43 | new NBAda.Process_Identification (<>); 44 | -- Process identification. 45 | 46 | package NBAda.Lock_Free_Bags_Memory_Reclamation_Adapter is 47 | 48 | package Memory_Reclamation is new NBAda.Memory_Reclamation.Hazard_Pointers 49 | (Max_Number_Of_Dereferences => 6, 50 | Process_Ids => Process_Ids, 51 | Verbose_Debug => False); 52 | 53 | end NBAda.Lock_Free_Bags_Memory_Reclamation_Adapter; 54 | -------------------------------------------------------------------------------- /src/Lock-Free_Sets/EBMR/nbada-lock_free_sets_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Sets - An implementation of the lock-free set algorithm by 3 | -- M. Michael. 4 | -- 5 | -- Copyright (C) 2007 - 2012 Anders Gidenstam 6 | -- 7 | -- This program is free software; you can redistribute it and/or modify 8 | -- it under the terms of the GNU General Public License as published by 9 | -- the Free Software Foundation; either version 2 of the License, or 10 | -- (at your option) any later version. 11 | -- 12 | -- This program is distributed in the hope that it will be useful, 13 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | -- GNU General Public License for more details. 16 | -- 17 | -- You should have received a copy of the GNU General Public License 18 | -- along with this program; if not, write to the Free Software 19 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | -- 21 | ------------------------------------------------------------------------------- 22 | pragma Style_Checks (Off); 23 | ------------------------------------------------------------------------------- 24 | -- Filename : nbada-lock_free_sets_memory_reclamation_adapter.ads 25 | -- Description : Lock-free list-based sets based on Maged Michael, 26 | -- "High Performance Dynamic Lock-Free Hash Tables and 27 | -- List-Based Sets", The 14th Annual ACM Symposium on 28 | -- Parallel Algorithms and Architectures (SPAA'02), 29 | -- pages 73-82, August 2002. 30 | -- Author : Anders Gidenstam 31 | -- Created On : Wed Sep 5 17:01:01 2007 32 | ------------------------------------------------------------------------------- 33 | pragma Style_Checks (All_Checks); 34 | 35 | pragma License (GPL); 36 | 37 | with NBAda.Memory_Reclamation.Epoch_Based_Memory_Reclamation; 38 | with NBAda.Process_Identification; 39 | 40 | generic 41 | 42 | with package Process_Ids is 43 | new NBAda.Process_Identification (<>); 44 | -- Process identification. 45 | 46 | package NBAda.Lock_Free_Sets_Memory_Reclamation_Adapter is 47 | 48 | package Memory_Reclamation is 49 | new NBAda.Memory_Reclamation.Epoch_Based_Memory_Reclamation 50 | (Epoch_Update_Threshold => 100, 51 | -- Suitable number for epoch-based reclamation. 52 | Process_Ids => Process_Ids); 53 | 54 | end NBAda.Lock_Free_Sets_Memory_Reclamation_Adapter; 55 | -------------------------------------------------------------------------------- /src/Lock-Free_Bag/EBMR/nbada-lock_free_bags_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free bag - An implementation of the lock-free bag algorithm 3 | -- by H. Sundell, A. Gidenstam, M. Papatriantafilou and P. Tsigas. 4 | -- Copyright (C) 2011 - 2012 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | pragma Style_Checks (Off); 22 | ------------------------------------------------------------------------------- 23 | -- Description : A lock-free bag algorithm based on 24 | -- H. Sundell, A. Gidenstam, M. Papatriantafilou and 25 | -- P. Tsigas, 26 | -- "A Lock-Free Algorithm for Concurrent Bags", 27 | -- Proceedings of the 23rd Annual Symposium on Parallelism 28 | -- in Algorithms and Architectures (SPAA 2011), 29 | -- pages 335 - 344, ACM, 2011. 30 | -- Author : Anders Gidenstam 31 | -- Created On : Thu Sep 21 11:30:00 2011 32 | ------------------------------------------------------------------------------- 33 | pragma Style_Checks (All_Checks); 34 | 35 | pragma License (GPL); 36 | 37 | with NBAda.Memory_Reclamation.Epoch_Based_Memory_Reclamation; 38 | with NBAda.Process_Identification; 39 | 40 | generic 41 | 42 | with package Process_Ids is 43 | new NBAda.Process_Identification (<>); 44 | -- Process identification. 45 | 46 | package NBAda.Lock_Free_Bags_Memory_Reclamation_Adapter is 47 | 48 | package Memory_Reclamation is 49 | new NBAda.Memory_Reclamation.Epoch_Based_Memory_Reclamation 50 | (Epoch_Update_Threshold => 100, 51 | -- Suitable number for epoch-based reclamation. 52 | Process_Ids => Process_Ids); 53 | 54 | end NBAda.Lock_Free_Bags_Memory_Reclamation_Adapter; 55 | -------------------------------------------------------------------------------- /src/benchmarks/Queues/Lock-Free_Queue/test_queues.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Queue Test - Test benchmark for lock-free queues. 3 | -- 4 | -- Copyright (C) 2006 - 2007 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : queue_test.adb 23 | -- Description : Benchmark application for lock-free queues. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Thu Nov 30 19:49:40 2006 26 | -- $Id: test_queues.ads,v 1.2 2007/09/11 14:47:37 andersg Exp $ 27 | ------------------------------------------------------------------------------- 28 | 29 | pragma License (GPL); 30 | 31 | with NBAda.Lock_Free_Queues; 32 | with NBAda.Process_Identification; 33 | 34 | generic 35 | type Element_Type is private; 36 | -- Element type. 37 | with package Process_Ids is 38 | new NBAda.Process_Identification (<>); 39 | -- Process identification. 40 | package Test_Queues is 41 | 42 | package Queues is new 43 | NBAda.Lock_Free_Queues (Element_Type, Process_Ids); 44 | 45 | ---------------------------------------------------------------------------- 46 | -- Queue. 47 | ---------------------------------------------------------------------------- 48 | subtype Queue_Type is Queues.Queue_Type; 49 | 50 | Queue_Empty : exception renames Queues.Queue_Empty; 51 | 52 | procedure Init (Queue : in out Queue_Type) 53 | renames Queues.Init; 54 | function Dequeue (From : access Queue_Type) return Element_Type 55 | renames Queues.Dequeue; 56 | procedure Enqueue (On : in out Queue_Type; 57 | Element : in Element_Type) 58 | renames Queues.Enqueue; 59 | 60 | -- procedure Print_Statistics renames Queues.MR.Print_Statistics; 61 | 62 | end Test_Queues; 63 | -------------------------------------------------------------------------------- /src/benchmarks/Queues/Lock-Free_Deque_Left/test_queues.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Queue Test - Test benchmark for lock-free queues. 3 | -- 4 | -- Copyright (C) 2006 - 2007 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : queue_test.adb 23 | -- Description : Benchmark application for lock-free queues. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Tue Oct 30 16:22:40 2007 26 | -- $Id: test_queues.ads,v 1.1 2007/10/30 15:36:20 andersg Exp $ 27 | ------------------------------------------------------------------------------- 28 | 29 | pragma License (GPL); 30 | 31 | with NBAda.Lock_Free_Deques; 32 | with NBAda.Process_Identification; 33 | 34 | generic 35 | type Element_Type is private; 36 | -- Element type. 37 | with package Process_Ids is 38 | new NBAda.Process_Identification (<>); 39 | -- Process identification. 40 | package Test_Queues is 41 | 42 | package Queues is new 43 | NBAda.Lock_Free_Deques (Element_Type, Process_Ids); 44 | 45 | ---------------------------------------------------------------------------- 46 | -- Queue. 47 | ---------------------------------------------------------------------------- 48 | subtype Queue_Type is Queues.Deque_Type; 49 | 50 | Queue_Empty : exception renames Queues.Deque_Empty; 51 | 52 | procedure Init (Queue : in out Queue_Type) 53 | renames Queues.Init; 54 | function Dequeue (From : access Queue_Type) return Element_Type 55 | renames Queues.Pop_Left; 56 | procedure Enqueue (On : in out Queue_Type; 57 | Element : in Element_Type) 58 | renames Queues.Push_Right; 59 | 60 | -- procedure Print_Statistics renames Queues.MR.Print_Statistics; 61 | 62 | end Test_Queues; 63 | -------------------------------------------------------------------------------- /src/benchmarks/Queues/Lock-Free_Deque_Right/test_queues.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Queue Test - Test benchmark for lock-free queues. 3 | -- 4 | -- Copyright (C) 2006 - 2007 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : queue_test.adb 23 | -- Description : Benchmark application for lock-free queues. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Tue Oct 30 16:22:40 2007 26 | -- $Id: test_queues.ads,v 1.1 2007/10/30 15:36:20 andersg Exp $ 27 | ------------------------------------------------------------------------------- 28 | 29 | pragma License (GPL); 30 | 31 | with NBAda.Lock_Free_Deques; 32 | with NBAda.Process_Identification; 33 | 34 | generic 35 | type Element_Type is private; 36 | -- Element type. 37 | with package Process_Ids is 38 | new NBAda.Process_Identification (<>); 39 | -- Process identification. 40 | package Test_Queues is 41 | 42 | package Queues is new 43 | NBAda.Lock_Free_Deques (Element_Type, Process_Ids); 44 | 45 | ---------------------------------------------------------------------------- 46 | -- Queue. 47 | ---------------------------------------------------------------------------- 48 | subtype Queue_Type is Queues.Deque_Type; 49 | 50 | Queue_Empty : exception renames Queues.Deque_Empty; 51 | 52 | procedure Init (Queue : in out Queue_Type) 53 | renames Queues.Init; 54 | function Dequeue (From : access Queue_Type) return Element_Type 55 | renames Queues.Pop_Right; 56 | procedure Enqueue (On : in out Queue_Type; 57 | Element : in Element_Type) 58 | renames Queues.Push_Left; 59 | 60 | -- procedure Print_Statistics renames Queues.MR.Print_Statistics; 61 | 62 | end Test_Queues; 63 | -------------------------------------------------------------------------------- /src/common/nbada-per_task_storage-shared.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Per-object per-task shared storage. 3 | -- Copyright (C) 2011 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | pragma Style_Checks (Off); 21 | ------------------------------------------------------------------------------- 22 | -- -*- Mode: Ada -*- 23 | -- Filename : nbada-task_storage-shared.ads 24 | -- Description : A simple implementation of per-task shared storage. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Tue Aug 02 14:05:00 2011 27 | ------------------------------------------------------------------------------- 28 | pragma Style_Checks (All_Checks); 29 | 30 | pragma License (GPL); 31 | 32 | with NBAda.Process_Identification; 33 | 34 | generic 35 | 36 | type Element_Type is limited private; 37 | -- Element type. 38 | 39 | with package Process_Ids is 40 | new Process_Identification (<>); 41 | -- Process identification. 42 | 43 | package NBAda.Per_Task_Storage.Shared is 44 | 45 | type Element_Access is access Element_Type; 46 | 47 | type Storage is limited private; 48 | 49 | function Get (Source : in Storage) return Element_Access; 50 | -- Get the task's own element. 51 | 52 | function Get (Source : in Storage; 53 | Owner : in Process_Ids.Process_ID_Type) 54 | return Element_Access; 55 | -- Returns null if there is no element associated with the owner. 56 | 57 | private 58 | 59 | type Element_Array is array (Process_Ids.Process_ID_Type) of Element_Access; 60 | 61 | type Mutable_View (Self : access Storage) is 62 | limited null record; 63 | 64 | type Storage is 65 | limited record 66 | Element : Element_Array; 67 | Mutable : Mutable_View (Storage'Access); 68 | end record; 69 | 70 | end NBAda.Per_Task_Storage.Shared; 71 | -------------------------------------------------------------------------------- /src/Lock-Free_Priority_Queue/EBMR/nbada-lock_free_priority_queues_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Priority Queues - Based on the the lock-free set algorithm by 3 | -- M. Michael. 4 | -- 5 | -- Copyright (C) 2007 - 2008 Anders Gidenstam 6 | -- 7 | -- This program is free software; you can redistribute it and/or modify 8 | -- it under the terms of the GNU General Public License as published by 9 | -- the Free Software Foundation; either version 2 of the License, or 10 | -- (at your option) any later version. 11 | -- 12 | -- This program is distributed in the hope that it will be useful, 13 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | -- GNU General Public License for more details. 16 | -- 17 | -- You should have received a copy of the GNU General Public License 18 | -- along with this program; if not, write to the Free Software 19 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | -- 21 | ------------------------------------------------------------------------------- 22 | pragma Style_Checks (Off); 23 | ------------------------------------------------------------------------------- 24 | -- -*- Mode: Ada -*- 25 | -- Filename : nbada-lock_free_priority_queues_memory_reclamation_adapter.ads 26 | -- Description : Lock-free list-based sets based on Maged Michael, 27 | -- "High Performance Dynamic Lock-Free Hash Tables and 28 | -- List-Based Sets", The 14th Annual ACM Symposium on 29 | -- Parallel Algorithms and Architectures (SPAA'02), 30 | -- pages 73-82, August 2002. 31 | -- Author : Anders Gidenstam 32 | -- Created On : Wed Sep 5 17:01:01 2007 33 | -- $Id: nbada-lock_free_priority_queues_memory_reclamation_adapter.ads,v 1.1 2008/02/20 20:55:38 andersg Exp $ 34 | ------------------------------------------------------------------------------- 35 | pragma Style_Checks (All_Checks); 36 | 37 | pragma License (GPL); 38 | 39 | with NBAda.Epoch_Based_Memory_Reclamation; 40 | with NBAda.Process_Identification; 41 | 42 | generic 43 | 44 | with package Process_Ids is 45 | new NBAda.Process_Identification (<>); 46 | -- Process identification. 47 | 48 | package NBAda.Lock_Free_Priority_Queues_Memory_Reclamation_Adapter is 49 | 50 | package Memory_Reclamation is new NBAda.Epoch_Based_Memory_Reclamation 51 | (Epoch_Update_Threshold => 100, 52 | -- Suitable number for epoch-based reclamation. 53 | Process_Ids => Process_Ids); 54 | 55 | end NBAda.Lock_Free_Priority_Queues_Memory_Reclamation_Adapter; 56 | -------------------------------------------------------------------------------- /src/Lock-Free_Red_Black_Tree/LFRC/nbada-lock_free_simple_trees_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Simple Trees - An implementation of a simple lock-free binary 3 | -- tree algorithm by A. Gidenstam. 4 | -- 5 | -- Copyright (C) 2008 Anders Gidenstam 6 | -- 7 | -- This program is free software; you can redistribute it and/or modify 8 | -- it under the terms of the GNU General Public License as published by 9 | -- the Free Software Foundation; either version 2 of the License, or 10 | -- (at your option) any later version. 11 | -- 12 | -- This program is distributed in the hope that it will be useful, 13 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | -- GNU General Public License for more details. 16 | -- 17 | -- You should have received a copy of the GNU General Public License 18 | -- along with this program; if not, write to the Free Software 19 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | -- 21 | ------------------------------------------------------------------------------- 22 | pragma Style_Checks (Off); 23 | ------------------------------------------------------------------------------- 24 | -- -*- Mode: Ada -*- 25 | -- Filename : nbada-lock_free_simple_trees_memory_reclamation_adapter.ads 26 | -- Description : An implementation of a simple lock-free binary 27 | -- tree algorithm by A. Gidenstam. 28 | -- Author : Anders Gidenstam 29 | -- Created On : Thu Sep 6 11:48:14 2007 30 | -- $Id: nbada-lock_free_simple_trees_memory_reclamation_adapter.ads,v 1.2 2008/05/08 08:48:44 andersg Exp $ 31 | ------------------------------------------------------------------------------- 32 | pragma Style_Checks (All_Checks); 33 | 34 | pragma License (GPL); 35 | 36 | with NBAda.Lock_Free_Reference_Counting; 37 | -- with NBAda.Epoch_Based_Memory_Reclamation; 38 | with NBAda.Hazard_Pointers; 39 | with NBAda.Process_Identification; 40 | 41 | generic 42 | 43 | with package Process_Ids is 44 | new NBAda.Process_Identification (<>); 45 | -- Process identification. 46 | 47 | package NBAda.Lock_Free_Simple_Trees_Memory_Reclamation_Adapter is 48 | 49 | package Node_Memory_Reclamation is new NBAda.Lock_Free_Reference_Counting 50 | (Max_Number_Of_Guards => 128); 51 | 52 | package State_Memory_Reclamation is 53 | -- new NBAda.Epoch_Based_Memory_Reclamation (Process_Ids); 54 | new NBAda.Hazard_Pointers (Max_Number_Of_Dereferences => 5, 55 | Process_Ids => Process_Ids); 56 | 57 | end NBAda.Lock_Free_Simple_Trees_Memory_Reclamation_Adapter; 58 | -------------------------------------------------------------------------------- /src/Lock-Free_Priority_Queue/HPMR/nbada-lock_free_priority_queues_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Priority Queues - Based on the the lock-free set algorithm by 3 | -- M. Michael. 4 | -- 5 | -- Copyright (C) 2007 - 2008 Anders Gidenstam 6 | -- 7 | -- This program is free software; you can redistribute it and/or modify 8 | -- it under the terms of the GNU General Public License as published by 9 | -- the Free Software Foundation; either version 2 of the License, or 10 | -- (at your option) any later version. 11 | -- 12 | -- This program is distributed in the hope that it will be useful, 13 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | -- GNU General Public License for more details. 16 | -- 17 | -- You should have received a copy of the GNU General Public License 18 | -- along with this program; if not, write to the Free Software 19 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | -- 21 | ------------------------------------------------------------------------------- 22 | pragma Style_Checks (Off); 23 | ------------------------------------------------------------------------------- 24 | -- -*- Mode: Ada -*- 25 | -- Filename : nbada-lock_free_sets_memory_reclamation_adapter.ads 26 | -- Description : Lock-free list-based sets based on Maged Michael, 27 | -- "High Performance Dynamic Lock-Free Hash Tables and 28 | -- List-Based Sets", The 14th Annual ACM Symposium on 29 | -- Parallel Algorithms and Architectures (SPAA'02), 30 | -- pages 73-82, August 2002. 31 | -- Author : Anders Gidenstam 32 | -- Created On : Wed Sep 5 17:01:01 2007 33 | -- $Id: nbada-lock_free_priority_queues_memory_reclamation_adapter.ads,v 1.2 2008/05/14 11:44:34 andersg Exp $ 34 | ------------------------------------------------------------------------------- 35 | pragma Style_Checks (All_Checks); 36 | 37 | pragma License (GPL); 38 | 39 | with NBAda.Hazard_Pointers; 40 | with NBAda.Process_Identification; 41 | 42 | generic 43 | 44 | with package Process_Ids is 45 | new NBAda.Process_Identification (<>); 46 | -- Process identification. 47 | 48 | package NBAda.Lock_Free_Priority_Queues_Memory_Reclamation_Adapter is 49 | 50 | package Memory_Reclamation is 51 | new NBAda.Hazard_Pointers (Process_Ids => Process_Ids, 52 | Max_Number_Of_Dereferences => 4 53 | -- Integrity_Checking => True 54 | ); 55 | 56 | end NBAda.Lock_Free_Priority_Queues_Memory_Reclamation_Adapter; 57 | -------------------------------------------------------------------------------- /src/benchmarks/Stacks/spin-lock-based/lock_based_stack.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-based Stack - A lock-based concurrent stack. 3 | -- Copyright (C) 2005 - 2007 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | -- -*- Mode: Ada -*- 21 | -- Filename : lock_based_stack.ads 22 | -- Description : A lock-based concurrent stack. 23 | -- Author : Anders Gidenstam 24 | -- Created On : Fri Sep 23 17:55:38 2005 25 | -- $Id: lock_based_stack.ads,v 1.2 2007/09/11 12:27:50 andersg Exp $ 26 | ------------------------------------------------------------------------------- 27 | 28 | pragma License (GPL); 29 | 30 | with NBAda.Process_Identification; 31 | 32 | generic 33 | type Element_Type is private; 34 | -- Element type. 35 | with package Process_Ids is 36 | new NBAda.Process_Identification (<>); 37 | -- Process identification. 38 | package Lock_Based_Stack is 39 | 40 | ---------------------------------------------------------------------------- 41 | -- Lock-based Stack. 42 | ---------------------------------------------------------------------------- 43 | type Stack_Type is limited private; 44 | 45 | Stack_Empty : exception; 46 | 47 | procedure Push (On : in out Stack_Type; 48 | Element : in Element_Type); 49 | procedure Pop (From : in out Stack_Type; 50 | Element : out Element_Type); 51 | function Pop (From : access Stack_Type) 52 | return Element_Type; 53 | 54 | function Top (From : access Stack_Type) 55 | return Element_Type; 56 | 57 | private 58 | 59 | type Stack_Node; 60 | type Stack_Node_Access is access all Stack_Node; 61 | 62 | type Stack_Node is 63 | record 64 | Element : Element_Type; 65 | Next : Stack_Node_Access; 66 | end record; 67 | 68 | type Stack_Type is 69 | limited record 70 | Head : Stack_Node_Access; 71 | Lock : aliased Integer := 1; 72 | pragma Atomic (Lock); 73 | end record; 74 | 75 | end Lock_Based_Stack; 76 | -------------------------------------------------------------------------------- /src/common/nbada-memory_reclamation.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- NBAda - A library of non-blocking algorithms and data structures. 3 | -- 4 | -- Copyright (C) 2011 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | 22 | pragma License (GPL); 23 | pragma Style_Checks (ALL_CHECKS); 24 | 25 | with NBAda.Primitives; 26 | 27 | package NBAda.Memory_Reclamation is 28 | 29 | ---------------------------------------------------------------------------- 30 | type Shared_Reference_Base is limited private; 31 | -- For type separation between shared references to different 32 | -- managed types derive your own shared reference types from 33 | -- Shared_Reference_Base and instantiate the memory management 34 | -- operation package below for each of them. 35 | 36 | type Reference_Mark is (A, B, AB); 37 | -- Private and shared references can be tagged with marks. 38 | 39 | private 40 | 41 | type Reference_Impl is new Primitives.Standard_Unsigned; 42 | 43 | type Shared_Reference_Base is 44 | record 45 | Ref : aliased Reference_Impl := 0; 46 | pragma Atomic (Ref); 47 | end record; 48 | for Shared_Reference_Base'Size use Primitives.Standard_Unsigned'Size; 49 | pragma Atomic (Shared_Reference_Base); 50 | 51 | function Boolean_Compare_And_Swap_Impl is 52 | new Primitives.Standard_Boolean_Compare_And_Swap (Reference_Impl); 53 | procedure Void_Compare_And_Swap_Impl is 54 | new Primitives.Standard_Void_Compare_And_Swap (Reference_Impl); 55 | 56 | Mark_Bits : constant := 2; 57 | -- Note: Reference_Counted_Node_Base'Alignment >= 2 ** Mark_Bits MUST hold. 58 | Mark_Mask : constant array (Reference_Mark) of Reference_Impl 59 | := (A => 1, 60 | B => 2, 61 | AB => 3); 62 | Ref_Mask : constant Reference_Impl := -(2 ** Mark_Bits); 63 | 64 | type MM_Magic_Type is new Primitives.Unsigned_32; 65 | MM_Live : constant := 12121212; 66 | MM_Deleted : constant := 21212121; 67 | MM_Reclaimable : constant := 44444444; 68 | MM_Reclaimed : constant := 88888888; 69 | 70 | end NBAda.Memory_Reclamation; 71 | -------------------------------------------------------------------------------- /src/Lock-Free_Deque/LFMR/nbada-lock_free_deques_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Deques - An Ada implementation of the lock-free deque algorithm 3 | -- by H. Sundell and P. Tsigas. 4 | -- 5 | -- Copyright (C) 2007 - 2012 Anders Gidenstam 6 | -- 7 | -- This program is free software; you can redistribute it and/or modify 8 | -- it under the terms of the GNU General Public License as published by 9 | -- the Free Software Foundation; either version 2 of the License, or 10 | -- (at your option) any later version. 11 | -- 12 | -- This program is distributed in the hope that it will be useful, 13 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | -- GNU General Public License for more details. 16 | -- 17 | -- You should have received a copy of the GNU General Public License 18 | -- along with this program; if not, write to the Free Software 19 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | -- 21 | ------------------------------------------------------------------------------- 22 | pragma Style_Checks (Off); 23 | ------------------------------------------------------------------------------- 24 | -- Filename : nbada-lock_free_deques_memory_reclamation_adapter.ads 25 | -- Description : An Ada implementation of the lock-free deque algorithm 26 | -- by H. Sundell and P. Tsigas. 27 | -- Author : Anders Gidenstam 28 | -- Created On : Thu Sep 6 12:05:42 2007 29 | ------------------------------------------------------------------------------- 30 | pragma Style_Checks (All_Checks); 31 | 32 | pragma License (GPL); 33 | 34 | with NBAda.Memory_Reclamation.Beware_And_Cleanup; 35 | with NBAda.Process_Identification; 36 | 37 | generic 38 | 39 | with package Process_Ids is 40 | new NBAda.Process_Identification (<>); 41 | -- Process identification. 42 | 43 | package NBAda.Lock_Free_Deques_Memory_Reclamation_Adapter is 44 | 45 | package Memory_Reclamation is 46 | new NBAda.Memory_Reclamation.Beware_And_Cleanup 47 | (Max_Number_Of_Dereferences => 10, 48 | -- Remember to account for the dereferences in the 49 | -- callbacks Clean_Up and Dispose (which are invoked by Delete). 50 | -- Here: PushRight <= ? 51 | -- PopRight <= ? 52 | -- PushLeft <= ? 53 | -- PopLeft <= ? 54 | -- Dispose <= ? 55 | -- Clean_up <= ? 56 | -- Delete is called from Pop* on a dereferenced node so the 57 | -- maximum number of simultaneous dereferences is ?. 58 | Max_Number_Of_Links_Per_Node => 2, 59 | Clean_Up_Threshold => 60 | 2 * Natural (Process_Ids.Max_Number_Of_Processes), 61 | -- Clean up and scan often. 62 | Process_Ids => Process_Ids); 63 | 64 | end NBAda.Lock_Free_Deques_Memory_Reclamation_Adapter; 65 | 66 | -------------------------------------------------------------------------------- /src/Pass_The_Buck/nbada-pass_the_buck.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Pass-the-buck - An implementation of Herlihy et. al.'s algorithm. 3 | -- Copyright (C) 2006 - 2007 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | -- -*- Mode: Ada -*- 21 | -- Filename : pass_the_buck.ads 22 | -- Description : Lock-Free Ada implementation of Herlihy et. al.'s 23 | -- Pass-The-Buck Algorithm. 24 | -- Based on M. Herlihy, V. Luchangco, P. Martin and M. Moir, 25 | -- "Nonblocking Memory Management Support for 26 | -- Dynamic-Sized Data Structures", ACM Transcations on 27 | -- Computer Systems, 23(2), 147--196, May 2005. 28 | -- Author : Anders Gidenstam 29 | -- Created On : Thu Nov 23 17:13:55 2006 30 | -- $Id: nbada-pass_the_buck.ads,v 1.5 2007/08/30 16:59:30 andersg Exp $ 31 | ------------------------------------------------------------------------------- 32 | 33 | pragma License (GPL); 34 | 35 | generic 36 | 37 | Max_Number_Of_Guards : Natural; 38 | -- The maximum number of simultaneously active guards. 39 | -- (Rouhly: The maximum number of simultaneously dereferenced nodes.) 40 | 41 | type Value_Type is private; 42 | -- Value_Type must be atomic. 43 | -- Value_Type'Object_Size MUST equal System.Word_Size. 44 | 45 | Null_Value : Value_Type; 46 | 47 | package NBAda.Pass_The_Buck is 48 | 49 | pragma Elaborate_Body; 50 | 51 | type Guard_Type is private; 52 | type Value_Set is array (Natural range <>) of Value_Type; 53 | 54 | function Hire_Guard return Guard_Type; 55 | 56 | procedure Fire_Guard (Guard : in Guard_Type); 57 | 58 | procedure Post_Guard (Guard : in Guard_Type; 59 | Value : in Value_Type); 60 | 61 | function Liberate (Values : in Value_Set) return Value_Set; 62 | 63 | private 64 | 65 | type Guard_Type is new Natural range 0 .. Max_Number_Of_Guards; 66 | for Guard_Type'Size use 32; 67 | 68 | 69 | type Atomic_Guard_Type is new Guard_Type; 70 | pragma Atomic (Atomic_Guard_Type); 71 | 72 | end NBAda.Pass_The_Buck; 73 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------ 2 | #- NBAda - A library of non-blocking algorithms and data structures. 3 | #- 4 | #- Copyright (C) 2007 - 2008 Anders Gidenstam 5 | #- 6 | #- This program is free software; you can redistribute it and/or modify 7 | #- it under the terms of the GNU General Public License as published by 8 | #- the Free Software Foundation; either version 2 of the License, or 9 | #- (at your option) any later version. 10 | #- 11 | #- This program is distributed in the hope that it will be useful, 12 | #- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | #- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | #- GNU General Public License for more details. 15 | #- 16 | #- You should have received a copy of the GNU General Public License 17 | #- along with this program; if not, write to the Free Software 18 | #- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | #- 20 | #------------------------------------------------------------------------------ 21 | # $Id: Makefile,v 1.2 2008/02/13 10:23:57 andersg Exp $ 22 | #------------------------------------------------------------------------------ 23 | 24 | DIST_TAG=RELEASE_0_1_0 25 | DIST_VERSION=0.1.0 26 | 27 | DIST_ADTs = src/Atomic_1-Writer_N-Reader_Register \ 28 | src/Atomic_Multi-Writer_Snapshot \ 29 | src/Lock-Free_LL_SC \ 30 | src/Lock-Free_Stack \ 31 | src/Lock-Free_Bounded_Queue \ 32 | src/Lock-Free_Queue \ 33 | src/Lock-Free_Queue_2 \ 34 | src/Lock-Free_Deque \ 35 | src/Lock-Free_Priority_Queue 36 | 37 | DIST_MRs = src/Lock-Free_Storage_Pools \ 38 | src/Epoch-Based_Memory_Reclamation \ 39 | src/Hazard_Pointers \ 40 | src/Pass_The_Buck \ 41 | src/Lock-Free_Reference_Counting \ 42 | src/Lock-Free_Memory_Reclamation \ 43 | src/debug 44 | 45 | DIST_BASE = src/common \ 46 | src/Primitives \ 47 | src/benchmarks 48 | 49 | DIST_UTIL = src/util 50 | 51 | DIST_benchmarks = src/benchmarks 52 | 53 | DIST_DOCs = docs/reference_manual.pdf 54 | 55 | DIST_COMMON = COPYING README \ 56 | $(DIST_BASE) $(DIST_UTIL) $(DIST_MRs) $(DIST_ADTs) \ 57 | $(DIST_benchmarks) $(DIST_DOCs) 58 | 59 | # This target makes an archive containing everything tagged for the specified 60 | # release. 61 | dist_archive: docs 62 | (cd /tmp/; \ 63 | rm -rf /tmp/NBAda; \ 64 | cvs -d /home/andersg/cvsroot export -d NBAda -r $(DIST_TAG) Ada/Non-Blocking/NBAda;\ 65 | ) 66 | cp $(DIST_DOCs) /tmp/NBAda/ 67 | (cd /tmp/; \ 68 | tar zcf NBAda-$(DIST_VERSION).tar.gz \ 69 | --exclude=CVS --exclude='*~' --exclude='*.o' --exclude='*.ali'\ 70 | NBAda;\ 71 | ) 72 | 73 | dist: docs 74 | tar zcf NBAda-$(DIST_VERSION).tar.gz \ 75 | --exclude=CVS --exclude='*~' --exclude='*.o' --exclude='*.ali'\ 76 | $(DIST_COMMON) 77 | 78 | docs: docs/reference_manual.tex docs/references.bib 79 | cd docs; latex reference_manual; bibtex reference_manual; \ 80 | latex reference_manual; latex reference_manual; dvipdf reference_manual 81 | -------------------------------------------------------------------------------- /src/benchmarks/Stacks/mutex-based/mutex_based_stack.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Mutex-based Stack - A mutex-based concurrent stack. 3 | -- Copyright (C) 2005 - 2007 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | -- -*- Mode: Ada -*- 21 | -- Filename : mutex_based_stack.ads 22 | -- Description : A mutex-based concurrent stack. 23 | -- Author : Anders Gidenstam 24 | -- Created On : Fri Sep 23 17:55:38 2005 25 | -- $Id: mutex_based_stack.ads,v 1.2 2007/09/11 12:27:50 andersg Exp $ 26 | ------------------------------------------------------------------------------- 27 | 28 | pragma License (GPL); 29 | 30 | with NBAda.Process_Identification; 31 | 32 | generic 33 | type Element_Type is private; 34 | -- Element type. 35 | with package Process_Ids is 36 | new NBAda.Process_Identification (<>); 37 | -- Process identification. 38 | package Mutex_Based_Stack is 39 | 40 | ---------------------------------------------------------------------------- 41 | -- Mutex-based Stack. 42 | ---------------------------------------------------------------------------- 43 | type Stack_Type is limited private; 44 | 45 | Stack_Empty : exception; 46 | 47 | procedure Push (On : in out Stack_Type; 48 | Element : in Element_Type); 49 | procedure Pop (From : in out Stack_Type; 50 | Element : out Element_Type); 51 | function Pop (From : access Stack_Type) 52 | return Element_Type; 53 | 54 | function Top (From : access Stack_Type) 55 | return Element_Type; 56 | 57 | private 58 | 59 | type Stack_Node; 60 | type Stack_Node_Access is access all Stack_Node; 61 | 62 | type Stack_Node is 63 | record 64 | Element : Element_Type; 65 | Next : Stack_Node_Access; 66 | end record; 67 | 68 | protected type Mutex_Type is 69 | entry Acquire; 70 | procedure Release; 71 | private 72 | Locked : Boolean := False; 73 | end Mutex_Type; 74 | 75 | type Stack_Type is 76 | limited record 77 | Head : Stack_Node_Access; 78 | Mutex : Mutex_Type; 79 | end record; 80 | 81 | end Mutex_Based_Stack; 82 | -------------------------------------------------------------------------------- /src/Atomic_1-Writer_N-Reader_Register/atomic_test.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Ada implementation of atomic multi-word register based on the algorithm 3 | -- by G. Peterson. 4 | -- Copyright (C) 2001 - 2007 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : atomic_test.adb 23 | -- Description : Test of wait-free register constructions. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Sat Oct 20 00:43:30 2001 26 | -- $Id: atomic_test.adb,v 1.7 2007/10/24 14:22:44 andersg Exp $ 27 | ------------------------------------------------------------------------------- 28 | 29 | pragma License (GPL); 30 | 31 | with Ada.Text_IO; use Ada.Text_IO; 32 | 33 | with NBAda.Atomic_Single_Writer_Registers; 34 | 35 | procedure Atomic_Test is 36 | 37 | type My_String is new String (1 .. 255); 38 | 39 | package Wait_Free_Strings is 40 | new NBAda.Atomic_Single_Writer_Registers (My_String); 41 | use Wait_Free_Strings; 42 | 43 | task Writer; 44 | task type Reader; 45 | 46 | Reg : Atomic_1_M_Register (No_Of_Readers => 15); 47 | 48 | R1 : Reader; 49 | R2 : Reader; 50 | R3 : Reader; 51 | R4 : Reader; 52 | R5 : Reader; 53 | R6 : Reader; 54 | R7 : Reader; 55 | R8 : Reader; 56 | R9 : Reader; 57 | R10 : Reader; 58 | R11 : Reader; 59 | R12 : Reader; 60 | R13 : Reader; 61 | R14 : Reader; 62 | R15 : Reader; 63 | 64 | Str1 : constant My_String := (others => 'A'); 65 | Str2 : constant My_String := (others => 'B'); 66 | 67 | task body Writer is 68 | begin 69 | Write (Reg, Str1); 70 | delay 1.0; 71 | loop 72 | Write (Reg, Str1); 73 | Write (Reg, Str2); 74 | end loop; 75 | end Writer; 76 | 77 | task body Reader is 78 | Id : constant Reader_Id := Register_Reader (Reg); 79 | Str : My_String; 80 | begin 81 | delay 1.0; 82 | loop 83 | Read (Reg, Id, Str); 84 | if Str /= Str1 and Str /= Str2 then 85 | Put_Line ("Bad value: " & String (Str)); 86 | end if; 87 | end loop; 88 | end Reader; 89 | 90 | begin 91 | Ada.Text_IO.Put_Line ("NOTE: Unless there are severe errors " & 92 | "this program runs forever."); 93 | end Atomic_Test; 94 | -------------------------------------------------------------------------------- /src/benchmarks/Queues/Lock-Free_Queue_3/test_queues.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Queue Test - Test benchmark for lock-free queues. 3 | -- 4 | -- Copyright (C) 2011 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : test_queues.ads 23 | -- Description : Benchmark application for lock-free queues. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Fri Jun 10 11:35:49 2011 26 | ------------------------------------------------------------------------------- 27 | 28 | pragma License (GPL); 29 | 30 | with NBAda.Process_Identification; 31 | with NBAda.Lock_Free_Queues; 32 | with NBAda.Primitives; 33 | with Ada.Unchecked_Conversion; 34 | 35 | generic 36 | type Element_Type is private; 37 | -- Element type. 38 | with package Process_Ids is 39 | new NBAda.Process_Identification (<>); 40 | -- Process identification. 41 | package Test_Queues is 42 | 43 | ---------------------------------------------------------------------------- 44 | -- Queue. 45 | ---------------------------------------------------------------------------- 46 | type Queue_Type is limited private; 47 | 48 | Queue_Empty : exception; 49 | 50 | procedure Init (Queue : in out Queue_Type); 51 | function Dequeue (From : access Queue_Type) return Element_Type; 52 | procedure Enqueue (On : in out Queue_Type; 53 | Element : in Element_Type); 54 | 55 | -- procedure Print_Statistics renames Queues.MR.Print_Statistics; 56 | 57 | private 58 | 59 | type Element_Access is access all Element_Type; 60 | 61 | function To_Element_Access is new 62 | Ada.Unchecked_Conversion (NBAda.Primitives.Standard_Unsigned, 63 | Element_Access); 64 | use type NBAda.Primitives.Standard_Unsigned; 65 | Null_0 : constant Element_Access := null; 66 | Null_1 : constant Element_Access := To_Element_Access (0-1); 67 | 68 | package Queues is new 69 | NBAda.Lock_Free_Queues (Element_Type => Element_Access, 70 | Null_0 => Null_0, 71 | Null_1 => Null_1, 72 | Process_Ids => Process_Ids); 73 | 74 | type Queue_Type is new Queues.Queue_Type; 75 | 76 | end Test_Queues; 77 | -------------------------------------------------------------------------------- /src/Lock-Free_Queue_2/LFMR/nbada-lock_free_queues_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Queue - An implementation of M. Hoffman, O. Shalev and 3 | -- N. Shavit's lock-free queue algorithm. 4 | -- Copyright (C) 2008 - 2012 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | pragma Style_Checks (Off); 22 | ------------------------------------------------------------------------------- 23 | -- Filename : nbada-lock_free_queues_memory_reclamation_adapter.ads 24 | -- Description : A lock-free queue algorithm based on 25 | -- M. Hoffman, O. Shalev and N. Shavit, 26 | -- "The Baskets Queue", The 11th International Conference 27 | -- On the Principles Of Distributed Systems (OPODIS'07), 28 | -- LNCS 4878, pp. 401-414, 2007. 29 | -- Author : Anders Gidenstam 30 | -- Created On : Thu Jan 10 19:57:44 2008 31 | ------------------------------------------------------------------------------- 32 | 33 | pragma Style_Checks (All_Checks); 34 | 35 | pragma License (GPL); 36 | 37 | with NBAda.Memory_Reclamation.Beware_And_Cleanup; 38 | with NBAda.Process_Identification; 39 | 40 | generic 41 | 42 | with package Process_Ids is 43 | new NBAda.Process_Identification (<>); 44 | -- Process identification. 45 | 46 | package NBAda.Lock_Free_Queues_Memory_Reclamation_Adapter is 47 | 48 | package Memory_Reclamation is 49 | new NBAda.Memory_Reclamation.Beware_And_Cleanup 50 | (Max_Number_Of_Dereferences => 10, 51 | -- Remember to account for the dereferences in the 52 | -- callbacks Clean_Up and Dispose (which are invoked by Delete). 53 | -- Here: Enqueue <= ? 54 | -- Dequeue <= ? 55 | -- Dispose <= ? 56 | -- Clean_up <= ? 57 | -- Delete is called from Dequeue on a dereferenced node so the 58 | -- maximum number of simultaneous dereferences is ?. 59 | Max_Number_Of_Links_Per_Node => 1, 60 | Clean_Up_Threshold => 61 | 2 * Natural (Process_Ids.Max_Number_Of_Processes), 62 | -- Scan_Threshold => 63 | -- 2 * Natural (Process_Ids.Max_Number_Of_Processes * 10) + 1, 64 | -- Clean up and scan often. 65 | Process_Ids => Process_Ids); 66 | 67 | end NBAda.Lock_Free_Queues_Memory_Reclamation_Adapter; 68 | -------------------------------------------------------------------------------- /src/debug/memory_reclamation_debug.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- NBAda - A library of non-blocking algorithms and data structures. 3 | -- 4 | -- Copyright (C) 2007 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : memory_reclamation_debug.ads 23 | -- Description : Track local references. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Tue Oct 30 10:37:19 2007 26 | -- $Id: memory_reclamation_debug.ads,v 1.2 2008/05/13 12:59:27 andersg Exp $ 27 | ------------------------------------------------------------------------------- 28 | 29 | with NBAda.Process_Identification; 30 | 31 | generic 32 | 33 | type Private_Reference is private; 34 | -- The private reference type to be tracked. 35 | Max_Number_Of_Dereferences : Natural; 36 | -- Maximum number of simultaneously dereferenced links per thread. 37 | 38 | with package Process_Ids is 39 | new NBAda.Process_Identification (<>); 40 | -- Process identification. 41 | 42 | -- Needed reference operations. 43 | with function Same_Node (Left, Right : Private_Reference) 44 | return Boolean; 45 | with function Image (Reference : Private_Reference) 46 | return String; 47 | 48 | package Memory_Reclamation_Debug is 49 | 50 | Reference_Error : exception; 51 | 52 | procedure Add_Reference (Node : Private_Reference; 53 | Where : String := ""); 54 | procedure Remove_Reference (Node : Private_Reference; 55 | Where : String := ""); 56 | procedure Dump_Local_References (Where : String := ""); 57 | 58 | procedure Verify_Quiescent (Where : String := ""); 59 | -- Verifies that there are no unreleased private references. 60 | 61 | procedure Enter; 62 | procedure Exit_Quiescent (Where : String := ""); 63 | type Reference_Array is array (Positive range <>) of Private_Reference; 64 | procedure Exit_Quiescent (Where : String := ""; 65 | Except : Reference_Array); 66 | -- Verifies that there are no unreleased private references 67 | -- except the exceptions. 68 | 69 | ---------------------------------------------------------------------------- 70 | package Debug_IO is 71 | 72 | procedure Put_Line (Text : in String); 73 | 74 | end Debug_IO; 75 | 76 | end Memory_Reclamation_Debug; 77 | -------------------------------------------------------------------------------- /src/Lock-Free_Queue_3/LFMR/nbada-lock_free_queues_memory_reclamation_adapter.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Queue - An implementation of the cache-aware lock-free queue 3 | -- algorithm by A. Gidenstam, H. Sundell and P. Tsigas. 4 | -- Copyright (C) 2011 - 2012 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | pragma Style_Checks (Off); 22 | ------------------------------------------------------------------------------- 23 | -- Description : A lock-free queue algorithm based on 24 | -- A. Gidenstam, H. Sundell and P. Tsigas, 25 | -- "Cache-Aware Lock-Free Queues for Multiple 26 | -- Producers/Consumers and Weak Memory Consistency", 27 | -- The 14th International Conference 28 | -- On the Principles Of Distributed Systems (OPODIS'10), 29 | -- LNCS 6490, pp. 302-317, 2011. 30 | -- Author : Anders Gidenstam 31 | -- Created On : Thu Jun 07 19:49:28 2011 32 | ------------------------------------------------------------------------------- 33 | pragma Style_Checks (All_Checks); 34 | 35 | pragma License (GPL); 36 | 37 | with NBAda.Memory_Reclamation.Beware_And_Cleanup; 38 | with NBAda.Process_Identification; 39 | 40 | generic 41 | 42 | with package Process_Ids is 43 | new NBAda.Process_Identification (<>); 44 | -- Process identification. 45 | 46 | package NBAda.Lock_Free_Queues_Memory_Reclamation_Adapter is 47 | 48 | package Memory_Reclamation is 49 | new NBAda.Memory_Reclamation.Beware_And_Cleanup 50 | (Max_Number_Of_Dereferences => 10, 51 | -- Remember to account for the dereferences in the 52 | -- callbacks Clean_Up and Dispose (which are invoked by Delete). 53 | -- Here: Enqueue <= ? 54 | -- Dequeue <= ? 55 | -- Dispose <= ? 56 | -- Clean_up <= ? 57 | -- Delete is called from Dequeue on a dereferenced node so the 58 | -- maximum number of simultaneous dereferences is ?. 59 | Max_Number_Of_Links_Per_Node => 1, 60 | Clean_Up_Threshold => 61 | 2 * Natural (Process_Ids.Max_Number_Of_Processes), 62 | -- Scan_Threshold => 63 | -- 2 * Natural (Process_Ids.Max_Number_Of_Processes * 10) + 1, 64 | -- Clean up and scan often. 65 | Process_Ids => Process_Ids); 66 | 67 | end NBAda.Lock_Free_Queues_Memory_Reclamation_Adapter; 68 | -------------------------------------------------------------------------------- /src/benchmarks/Queues/Lock-Free_Bounded_Queue/test_queues.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Queue Test - Test benchmark for lock-free queues. 3 | -- 4 | -- Copyright (C) 2007 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : test_queues.ads 23 | -- Description : Benchmark application for lock-free queues. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Wed Sep 12 16:25:49 2007 26 | -- $Id: test_queues.ads,v 1.1 2007/09/12 15:35:18 andersg Exp $ 27 | ------------------------------------------------------------------------------- 28 | 29 | pragma License (GPL); 30 | 31 | with NBAda.Process_Identification; 32 | with NBAda.Lock_Free_Bounded_Queues; 33 | with NBAda.Primitives; 34 | with Ada.Unchecked_Conversion; 35 | 36 | generic 37 | type Element_Type is private; 38 | -- Element type. 39 | with package Process_Ids is 40 | new NBAda.Process_Identification (<>); 41 | -- Process identification. 42 | package Test_Queues is 43 | 44 | ---------------------------------------------------------------------------- 45 | -- Queue. 46 | ---------------------------------------------------------------------------- 47 | type Queue_Type is limited private; 48 | 49 | Queue_Empty : exception; 50 | Queue_Full : exception; 51 | 52 | procedure Init (Queue : in out Queue_Type); 53 | function Dequeue (From : access Queue_Type) return Element_Type; 54 | procedure Enqueue (On : in out Queue_Type; 55 | Element : in Element_Type); 56 | 57 | -- procedure Print_Statistics renames Queues.MR.Print_Statistics; 58 | 59 | private 60 | 61 | type Element_Access is access all Element_Type; 62 | 63 | function To_Element_Access is new 64 | Ada.Unchecked_Conversion (NBAda.Primitives.Standard_Unsigned, 65 | Element_Access); 66 | use type NBAda.Primitives.Standard_Unsigned; 67 | Null_0 : constant Element_Access := null; 68 | Null_1 : constant Element_Access := To_Element_Access (0-1); 69 | 70 | package Queues is new 71 | NBAda.Lock_Free_Bounded_Queues (Element_Type => Element_Access, 72 | Null_0 => Null_0, 73 | Null_1 => Null_1); 74 | 75 | type Queue_Access is access Queues.Lock_Free_Queue; 76 | 77 | type Queue_Type is limited 78 | record 79 | Impl : Queue_Access; 80 | end record; 81 | 82 | end Test_Queues; 83 | -------------------------------------------------------------------------------- /src/benchmarks/Dictionaries/Lock-Free_Sets/test_dictionaries.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Dicitionary Test - Test benchmark for lock-free dictionaries. 3 | -- 4 | -- Copyright (C) 2008 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : test_dictionaries.ads 23 | -- Description : Test application for the lock-free dictionaries. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Tue Feb 26 14:31:56 2008 26 | -- $Id: test_dictionaries.ads,v 1.1 2008/02/26 14:25:20 andersg Exp $ 27 | ------------------------------------------------------------------------------- 28 | 29 | pragma License (GPL); 30 | 31 | with NBAda.Lock_Free_Sets; 32 | with NBAda.Process_Identification; 33 | 34 | generic 35 | 36 | type Value_Type is private; 37 | type Key_Type is private; 38 | 39 | with function Hash (Key : Key_Type; 40 | Table_Size : Positive) return Natural; 41 | -- Note: Not used. 42 | with function "<" (Left, Right : Key_Type) return Boolean is <>; 43 | -- Note: Key_Type must be totally ordered. 44 | 45 | with package Process_Ids is 46 | new NBAda.Process_Identification (<>); 47 | 48 | package Test_Dictionaries is 49 | 50 | package Sets is new 51 | NBAda.Lock_Free_Sets (Value_Type => Value_Type, 52 | Key_Type => Key_Type, 53 | "<" => "<", 54 | Process_Ids => Process_Ids); 55 | 56 | ---------------------------------------------------------------------------- 57 | -- Dictionary. 58 | ---------------------------------------------------------------------------- 59 | subtype Dictionary_Type is Sets.Set_Type; 60 | 61 | Not_Found : exception 62 | renames Sets.Not_Found; 63 | Already_Present : exception 64 | renames Sets.Already_Present; 65 | 66 | procedure Init (Dictionary : in out Dictionary_Type) 67 | renames Sets.Init; 68 | 69 | procedure Insert (Into : in out Dictionary_Type; 70 | Key : in Key_Type; 71 | Value : in Value_Type) 72 | renames Sets.Insert; 73 | 74 | procedure Delete (From : in out Dictionary_Type; 75 | Key : in Key_Type) 76 | renames Sets.Delete; 77 | 78 | function Lookup (From : in Dictionary_Type; 79 | Key : in Key_Type) 80 | return Value_Type 81 | renames Sets.Find; 82 | 83 | end Test_Dictionaries; 84 | -------------------------------------------------------------------------------- /src/Pass_The_Buck/lock_free_stack.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Stack - A lock-free stack using lock-free memory reclamation. 3 | -- Copyright (C) 2005 - 2007 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | -- -*- Mode: Ada -*- 21 | -- Filename : lock_free_stack.ads 22 | -- Description : A lock-free stack using lock-free memory reclamation. 23 | -- Author : Anders Gidenstam 24 | -- Created On : Fri Sep 23 17:55:38 2005 25 | -- $Id: lock_free_stack.ads,v 1.4 2007/08/30 16:59:30 andersg Exp $ 26 | ------------------------------------------------------------------------------- 27 | 28 | pragma License (GPL); 29 | 30 | with NBAda.Pass_The_Buck; 31 | with NBAda.Primitives; 32 | 33 | generic 34 | 35 | type Element_Type is private; 36 | -- Element type. 37 | 38 | package Lock_Free_Stack is 39 | 40 | ---------------------------------------------------------------------------- 41 | -- Lock-free Stack. 42 | ---------------------------------------------------------------------------- 43 | type Stack_Type is limited private; 44 | 45 | Stack_Empty : exception; 46 | 47 | procedure Push (On : in out Stack_Type; 48 | Element : in Element_Type); 49 | procedure Pop (From : in out Stack_Type; 50 | Element : out Element_Type); 51 | function Pop (From : access Stack_Type) 52 | return Element_Type; 53 | 54 | function Top (From : access Stack_Type) 55 | return Element_Type; 56 | 57 | private 58 | 59 | type Stack_Node; 60 | type Stack_Node_Access is access all Stack_Node; 61 | for Stack_Node_Access'Size use NBAda.Primitives.Standard_Unsigned'Size; 62 | pragma Atomic (Stack_Node_Access); 63 | 64 | type Stack_Node is 65 | record 66 | Element : Element_Type; 67 | Next : aliased Stack_Node_Access; 68 | pragma Atomic (Next); 69 | -- NOTE: Next MUST NEVER be DEREFERENCED! 70 | end record; 71 | 72 | procedure Free (Node : access Stack_Node); 73 | 74 | package MR is new NBAda.Pass_The_Buck 75 | (Max_Number_Of_Guards => 128, 76 | Value_Type => Stack_Node_Access, 77 | Null_Value => null); 78 | 79 | subtype Stack_Node_Reference is Stack_Node_Access; 80 | subtype Node_Access is Stack_Node_Access; 81 | 82 | type Stack_Type is 83 | limited record 84 | Head : aliased Stack_Node_Reference; 85 | pragma Atomic (Head); 86 | end record; 87 | 88 | end Lock_Free_Stack; 89 | -------------------------------------------------------------------------------- /src/Epoch-Based_Memory_Reclamation/example_stack.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Example Stack - A lock-free stack using epoch-based memory reclamation. 3 | -- Copyright (C) 2005 - 2007 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | -- -*- Mode: Ada -*- 21 | -- Filename : example_stack.ads 22 | -- Description : A lock-free stack using hazard pointers for 23 | -- memory management and ABA prevention. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Fri Sep 23 17:55:38 2005 26 | -- $Id: example_stack.ads,v 1.5 2007/08/30 15:51:09 andersg Exp $ 27 | ------------------------------------------------------------------------------- 28 | 29 | pragma License (GPL); 30 | 31 | with NBAda.Process_Identification; 32 | with NBAda.Epoch_Based_Memory_Reclamation; 33 | 34 | generic 35 | type Element_Type is private; 36 | -- Element type. 37 | with package Process_Ids is 38 | new NBAda.Process_Identification (<>); 39 | -- Process identification. 40 | package Example_Stack is 41 | 42 | ---------------------------------------------------------------------------- 43 | -- Lock-free Stack. 44 | ---------------------------------------------------------------------------- 45 | type Stack_Type is limited private; 46 | 47 | Stack_Empty : exception; 48 | 49 | procedure Push (On : in out Stack_Type; 50 | Element : in Element_Type); 51 | procedure Pop (From : in out Stack_Type; 52 | Element : out Element_Type); 53 | function Pop (From : access Stack_Type) 54 | return Element_Type; 55 | 56 | function Top (From : access Stack_Type) 57 | return Element_Type; 58 | 59 | -- private 60 | 61 | package MRS is new NBAda.Epoch_Based_Memory_Reclamation 62 | (Process_Ids => Process_Ids); 63 | 64 | private 65 | 66 | type Stack_Node; 67 | type Stack_Node_No_Access is access all Stack_Node; 68 | 69 | type Stack_Node is 70 | new MRS.Managed_Node_Base with 71 | record 72 | Element : Element_Type; 73 | Next : aliased Stack_Node_No_Access; 74 | pragma Atomic (Next); 75 | -- NOTE: Next MUST NEVER be DEREFERENCED! 76 | end record; 77 | 78 | procedure Free (Node : access Stack_Node); 79 | 80 | package MRS_Ops is new MRS.Operations (Managed_Node => Stack_Node); 81 | 82 | subtype Stack_Node_Reference is MRS_Ops.Shared_Reference; 83 | 84 | type Stack_Type is 85 | limited record 86 | Head : aliased Stack_Node_Reference; 87 | pragma Atomic (Head); 88 | end record; 89 | 90 | end Example_Stack; 91 | -------------------------------------------------------------------------------- /src/Lock-Free_Stack/nbada-lock_free_stack.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Stack - A lock-free stack using lock-free memory reclamation. 3 | -- Copyright (C) 2005 - 2011 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | -- Filename : lock_free_stack.ads 21 | -- Description : A lock-free stack using lock-free memory reclamation. 22 | -- Author : Anders Gidenstam 23 | -- Created On : Fri Sep 23 17:55:38 2005 24 | ------------------------------------------------------------------------------- 25 | 26 | pragma License (GPL); 27 | 28 | with NBAda.Process_Identification; 29 | with NBAda.Interfaces.Exceptions; 30 | with NBAda.Lock_Free_Stacks_Memory_Reclamation_Adapter; 31 | 32 | generic 33 | 34 | type Element_Type is private; 35 | -- Element type. 36 | 37 | with package Process_Ids is 38 | new NBAda.Process_Identification (<>); 39 | -- Process identification. 40 | 41 | package NBAda.Lock_Free_Stack is 42 | 43 | ---------------------------------------------------------------------------- 44 | -- Lock-free Stack. 45 | ---------------------------------------------------------------------------- 46 | type Stack_Type is limited private; 47 | 48 | Stack_Empty : exception 49 | renames NBAda.Interfaces.Exceptions.Empty; 50 | 51 | procedure Push (On : in out Stack_Type; 52 | Element : in Element_Type); 53 | procedure Pop (From : in out Stack_Type; 54 | Element : out Element_Type); 55 | function Pop (From : access Stack_Type) 56 | return Element_Type; 57 | 58 | function Top (From : access Stack_Type) 59 | return Element_Type; 60 | 61 | private 62 | 63 | package MR_Adapter is 64 | new Lock_Free_Stacks_Memory_Reclamation_Adapter (Process_Ids); 65 | package MR renames MR_Adapter.Memory_Reclamation; 66 | 67 | type Stack_Node_Reference is new Memory_Reclamation.Shared_Reference_Base; 68 | 69 | type Stack_Node is 70 | new MR.Managed_Node_Base with 71 | record 72 | Element : Element_Type; 73 | Next : aliased Stack_Node_Reference; 74 | pragma Atomic (Next); 75 | -- NOTE: Next MUST NEVER be DEREFERENCED! 76 | end record; 77 | 78 | procedure Free (Node : access Stack_Node); 79 | 80 | package MR_Ops is new MR.Reference_Operations 81 | (Managed_Node => Stack_Node, 82 | Shared_Reference => Stack_Node_Reference); 83 | 84 | type Stack_Type is 85 | limited record 86 | MM : MR_Ops.Memory_Manager; 87 | Head : aliased Stack_Node_Reference; 88 | pragma Atomic (Head); 89 | end record; 90 | 91 | end NBAda.Lock_Free_Stack; 92 | -------------------------------------------------------------------------------- /src/common/nbada-internals-hash_tables.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- NBAda - A library of non-blocking algorithms and data structures. 3 | -- 4 | -- Copyright (C) 2004 - 2007 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | pragma Style_Checks (Off); 22 | ------------------------------------------------------------------------------- 23 | -- -*- Mode: Ada -*- 24 | -- Filename : hash_tables.ads 25 | -- Description : A simple closed hash table. 26 | -- Author : Anders Gidenstam 27 | -- Created On : Thu Nov 25 21:51:42 2004 28 | -- $Id: nbada-internals-hash_tables.ads,v 1.8 2007/08/30 16:15:38 andersg Exp $ 29 | ------------------------------------------------------------------------------- 30 | pragma Style_Checks (All_Checks); 31 | 32 | pragma License (GPL); 33 | 34 | generic 35 | type Element_Type is private; 36 | with function "=" (Left, Right : Element_Type) return Boolean is <>; 37 | with function Hash (Key : Element_Type; 38 | Table_Size : Positive) return Natural; 39 | 40 | package NBAda.Internals.Hash_Tables is 41 | 42 | pragma Elaborate_Body; 43 | 44 | type Hash_Table (Size : Positive) is private; 45 | 46 | procedure Clear (Table : out Hash_Table); 47 | -- Clear a hash table. 48 | 49 | procedure Insert (Key : in Element_Type; 50 | Table : in out Hash_Table); 51 | -- Insert an element. 52 | 53 | procedure Delete (Key : in Element_Type; 54 | Table : in out Hash_Table); 55 | -- Delete an element. 56 | 57 | function Member (Key : in Element_Type; 58 | Table : in Hash_Table) return Boolean; 59 | -- Find an element. 60 | 61 | procedure Find (Key : in out Element_Type; 62 | Table : in Hash_Table); 63 | -- Find an element. 64 | 65 | function Find (Key : in Element_Type; 66 | Table : in Hash_Table) return Element_Type; 67 | -- Find an element. 68 | 69 | Item_Not_Found : exception; 70 | 71 | type Element_Array is array (Natural range <>) of Element_Type; 72 | function To_Array (Table : in Hash_Table) return Element_Array; 73 | 74 | private 75 | 76 | type Entry_Status is (Valid, Empty, Deleted); 77 | 78 | type Hash_Entry is 79 | record 80 | Element : Element_Type; 81 | Status : Entry_Status := Empty; 82 | end record; 83 | 84 | subtype Hash_Index is Natural; 85 | type Hash_Array is array (Hash_Index range <>) of Hash_Entry; 86 | 87 | type Hash_Table (Size : Positive) is 88 | record 89 | Table : Hash_Array (0 .. Size); 90 | end record; 91 | 92 | end NBAda.Internals.Hash_Tables; 93 | -------------------------------------------------------------------------------- /src/benchmarks/Dictionaries/Lock-Free_Dictionary/test_dictionaries.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Dicitionary Test - Test benchmark for lock-free dictionaries. 3 | -- 4 | -- Copyright (C) 2008 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : test_dictionaries.ads 23 | -- Description : Test application for the lock-free dictionaries. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Tue Feb 26 14:31:56 2008 26 | -- $Id: test_dictionaries.ads,v 1.1 2008/02/26 14:25:20 andersg Exp $ 27 | ------------------------------------------------------------------------------- 28 | 29 | pragma License (GPL); 30 | 31 | with NBAda.Lock_Free_Dictionaries; 32 | with NBAda.Process_Identification; 33 | 34 | generic 35 | 36 | type Value_Type is private; 37 | type Key_Type is private; 38 | 39 | with function Hash (Key : Key_Type; 40 | Table_Size : Positive) return Natural; 41 | with function "<" (Left, Right : Key_Type) return Boolean is <>; 42 | -- Note: Key_Type must be totally ordered. 43 | 44 | with package Process_Ids is 45 | new NBAda.Process_Identification (<>); 46 | 47 | package Test_Dictionaries is 48 | 49 | package Dictionaries is new 50 | NBAda.Lock_Free_Dictionaries (Value_Type => Value_Type, 51 | Key_Type => Key_Type, 52 | Hash => Hash, 53 | "<" => "<", 54 | Process_Ids => Process_Ids); 55 | 56 | ---------------------------------------------------------------------------- 57 | -- Dictionary. 58 | ---------------------------------------------------------------------------- 59 | subtype Dictionary_Type is Dictionaries.Dictionary_Type (No_Buckets => 100); 60 | 61 | Not_Found : exception 62 | renames Dictionaries.Not_Found; 63 | Already_Present : exception 64 | renames Dictionaries.Already_Present; 65 | 66 | procedure Init (Dictionary : in out Dictionary_Type) 67 | renames Dictionaries.Init; 68 | 69 | procedure Insert (Into : in out Dictionary_Type; 70 | Key : in Key_Type; 71 | Value : in Value_Type) 72 | renames Dictionaries.Insert; 73 | 74 | procedure Delete (From : in out Dictionary_Type; 75 | Key : in Key_Type) 76 | renames Dictionaries.Delete; 77 | 78 | function Lookup (From : in Dictionary_Type; 79 | Key : in Key_Type) 80 | return Value_Type 81 | renames Dictionaries.Lookup; 82 | 83 | end Test_Dictionaries; 84 | -------------------------------------------------------------------------------- /src/Primitives/nbada-process_identification.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Primitives - A binding to the synchronization primitives of the hardware. 3 | -- Copyright (C) 2004 - 2007 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | pragma Style_Checks (Off); 21 | ------------------------------------------------------------------------------- 22 | -- -*- Mode: Ada -*- 23 | -- Filename : process_identification.adb 24 | -- Description : Process IDs. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Fri Nov 19 16:06:16 2004 27 | -- $Id: nbada-process_identification.adb,v 1.7 2007/09/12 10:08:15 andersg Exp $ 28 | ------------------------------------------------------------------------------- 29 | pragma Style_Checks (All_Checks); 30 | 31 | pragma License (GPL); 32 | 33 | with Ada.Task_Attributes; 34 | with Ada.Exceptions; 35 | with NBAda.Primitives; 36 | 37 | package body NBAda.Process_Identification is 38 | 39 | subtype Process_ID_Base is Primitives.Standard_Unsigned; 40 | 41 | package Process_IDs is 42 | new Ada.Task_Attributes (Attribute => Process_ID_Base, 43 | Initial_Value => 0); 44 | -- In GNAT some of the operations in Ada.Task_Attributes are 45 | -- blocking, in particular, Set_Value. Value is non-blocking for 46 | -- small values, though. 47 | 48 | Process_Count : aliased Process_ID_Base := 0; 49 | pragma Atomic (Process_Count); 50 | -- Shared process id counter. 51 | 52 | ---------------------------------------------------------------------------- 53 | procedure Register is 54 | use type Process_ID_Base; 55 | begin 56 | if Process_IDs.Value = 0 then 57 | declare 58 | ID : constant Process_ID_Base := 59 | Primitives.Fetch_And_Add (Target => Process_Count'Access, 60 | Increment => 1) + 1; 61 | begin 62 | if ID in Process_ID_Base (Process_ID_Type'First) .. 63 | Process_ID_Base (Process_ID_Type'Last) 64 | then 65 | Process_IDs.Set_Value (ID); 66 | else 67 | Ada.Exceptions.Raise_Exception 68 | (Constraint_Error'Identity, 69 | "nbada-process_identification.adb: " & 70 | "Maximum number of registered threads exceeded!"); 71 | end if; 72 | end; 73 | end if; 74 | end Register; 75 | 76 | ---------------------------------------------------------------------------- 77 | function Process_ID return Process_ID_Type is 78 | begin 79 | return Process_ID_Type (Process_IDs.Value); 80 | end Process_ID; 81 | 82 | end NBAda.Process_Identification; 83 | -------------------------------------------------------------------------------- /src/benchmarks/Priority_Queues/Lock-Free_Priority_Queue/test_priority_queues.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Priority Queue Test - Test benchmark for lock-free priority queues. 3 | -- 4 | -- Copyright (C) 2008 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : test_priority_queues.ads 23 | -- Description : Harness for the lock-free priority queue. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Tue Mar 11 15:57:43 2008 26 | -- $Id: test_priority_queues.ads,v 1.1 2008/03/11 16:00:06 andersg Exp $ 27 | ------------------------------------------------------------------------------- 28 | 29 | pragma License (GPL); 30 | 31 | with NBAda.Lock_Free_Priority_Queues; 32 | with NBAda.Process_Identification; 33 | 34 | generic 35 | 36 | type Element_Type is private; 37 | 38 | with function "<" (Left, Right : Element_Type) return Boolean is <>; 39 | -- Note: Element_Type must be totally ordered. 40 | 41 | with function Image (Element : Element_Type) return String is <>; 42 | 43 | with package Process_Ids is 44 | new NBAda.Process_Identification (<>); 45 | -- Process identification. 46 | 47 | package Test_Priority_Queues is 48 | 49 | package Priority_Queues is new 50 | NBAda.Lock_Free_Priority_Queues (Element_Type => Element_Type, 51 | "<" => "<", 52 | Process_Ids => Process_Ids); 53 | 54 | ---------------------------------------------------------------------------- 55 | -- Priority Queue. 56 | ---------------------------------------------------------------------------- 57 | subtype Priority_Queue_Type is Priority_Queues.Priority_Queue_Type; 58 | 59 | Queue_Empty : exception 60 | renames Priority_Queues.Queue_Empty; 61 | Already_Present : exception 62 | renames Priority_Queues.Already_Present; 63 | 64 | procedure Initialize (Queue : in out Priority_Queue_Type) 65 | renames Priority_Queues.Initialize; 66 | 67 | procedure Insert (Into : in out Priority_Queue_Type; 68 | Element : in Element_Type) 69 | renames Priority_Queues.Insert; 70 | 71 | procedure Delete_Min (From : in out Priority_Queue_Type; 72 | Element : out Element_Type) 73 | renames Priority_Queues.Delete_Min; 74 | 75 | function Delete_Min (From : in Priority_Queue_Type) 76 | return Element_Type 77 | renames Priority_Queues.Delete_Min; 78 | 79 | function Delete_Min (From : access Priority_Queue_Type) 80 | return Element_Type 81 | renames Priority_Queues.Delete_Min; 82 | 83 | end Test_Priority_Queues; 84 | -------------------------------------------------------------------------------- /src/Hazard_Pointers/example_stack.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Example Stack - A lock-free stack using hazard pointers. 3 | -- Copyright (C) 2005 - 2007 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | -- -*- Mode: Ada -*- 21 | -- Filename : example_stack.ads 22 | -- Description : A lock-free stack using hazard pointers for 23 | -- memory management and ABA prevention. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Fri Sep 23 17:55:38 2005 26 | -- $Id: example_stack.ads,v 1.3 2007/08/30 16:14:05 andersg Exp $ 27 | ------------------------------------------------------------------------------- 28 | 29 | pragma License (GPL); 30 | 31 | with NBAda.Process_Identification; 32 | with NBAda.Hazard_Pointers; 33 | 34 | generic 35 | type Element_Type is private; 36 | -- Element type. 37 | with package Process_Ids is 38 | new NBAda.Process_Identification (<>); 39 | -- Process identification. 40 | package Example_Stack is 41 | 42 | ---------------------------------------------------------------------------- 43 | -- Lock-free Stack. 44 | ---------------------------------------------------------------------------- 45 | type Stack_Type is limited private; 46 | 47 | Stack_Empty : exception; 48 | 49 | procedure Push (On : in out Stack_Type; 50 | Element : in Element_Type); 51 | procedure Pop (From : in out Stack_Type; 52 | Element : out Element_Type); 53 | function Pop (From : access Stack_Type) 54 | return Element_Type; 55 | 56 | function Top (From : access Stack_Type) 57 | return Element_Type; 58 | 59 | -- private 60 | 61 | package HP is new NBAda.Hazard_Pointers 62 | (Max_Number_Of_Dereferences => 1, 63 | -- Each operation on the stack only accesses one element on the stack. 64 | Process_Ids => Process_Ids); 65 | 66 | private 67 | 68 | type Stack_Node; 69 | type Stack_Node_No_Access is access all Stack_Node; 70 | 71 | type Stack_Node is 72 | new HP.Managed_Node_Base with 73 | record 74 | Element : Element_Type; 75 | Next : aliased Stack_Node_No_Access; 76 | pragma Atomic (Next); 77 | -- NOTE: Next MUST NEVER be DEREFERENCED! 78 | end record; 79 | 80 | procedure Free (Node : access Stack_Node); 81 | 82 | package HP_Ops is new HP.Operations (Managed_Node => Stack_Node); 83 | 84 | subtype Stack_Node_Reference is HP_Ops.Shared_Reference; 85 | 86 | type Stack_Type is 87 | limited record 88 | Head : aliased Stack_Node_Reference; 89 | pragma Atomic (Head); 90 | end record; 91 | 92 | end Example_Stack; 93 | -------------------------------------------------------------------------------- /src/Lock-Free_Reference_Counting/example_queue.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Queue - An implementation of Michael and Scott's lock-free queue. 3 | -- Copyright (C) 2004 - 2006 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | -- -*- Mode: Ada -*- 21 | -- Filename : example_queue.ads 22 | -- Description : Simple example ADT for lock-free garbage reclamation 23 | -- schemes. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Sat May 7 20:54:49 2005 26 | -- $Id: example_queue.ads,v 1.5 2007/09/03 15:23:08 andersg Exp $ 27 | ------------------------------------------------------------------------------- 28 | 29 | pragma License (GPL); 30 | 31 | with NBAda.Lock_Free_Reference_Counting; 32 | with NBAda.Process_Identification; 33 | 34 | generic 35 | type Value_Type is private; 36 | -- Value type. 37 | with package Process_Ids is 38 | new NBAda.Process_Identification (<>); 39 | -- Process identification. 40 | package Example_Queue is 41 | 42 | ---------------------------------------------------------------------------- 43 | -- Lock-free Queue. 44 | ---------------------------------------------------------------------------- 45 | type Queue_Type is limited private; 46 | 47 | Queue_Empty : exception; 48 | 49 | procedure Init (Queue : in out Queue_Type); 50 | function Dequeue (Queue : access Queue_Type) return Value_Type; 51 | procedure Enqueue (Queue : in out Queue_Type; 52 | Value : in Value_Type); 53 | 54 | 55 | package LFMR is new NBAda.Lock_Free_Reference_Counting 56 | (Max_Number_Of_Guards => 128, 57 | Integrity_Checking => True, 58 | Collect_Statistics => True); 59 | 60 | private 61 | 62 | type Queue_Node_Reference is new LFMR.Shared_Reference_Base; 63 | 64 | type Queue_Node is new LFMR.Managed_Node_Base with 65 | record 66 | Next : aliased Queue_Node_Reference; 67 | pragma Atomic (Next); 68 | Value : Value_Type; 69 | end record; 70 | 71 | procedure Dispose (Node : access Queue_Node); 72 | procedure Free (Node : access Queue_Node); 73 | function All_References (Node : access Queue_Node) 74 | return LFMR.Reference_Set; 75 | 76 | package LFMR_Ops is new LFMR.Operations (Queue_Node, 77 | Queue_Node_Reference); 78 | 79 | subtype Queue_Node_Access is LFMR_Ops.Private_Reference; 80 | 81 | type Queue_Type is limited 82 | record 83 | Head : aliased Queue_Node_Reference; 84 | pragma Atomic (Head); 85 | Tail : aliased Queue_Node_Reference; 86 | pragma Atomic (Tail); 87 | end record; 88 | 89 | end Example_Queue; 90 | -------------------------------------------------------------------------------- /src/Atomic_Multi-Writer_Snapshot/nbada-atomic_multiwriter_snapshots.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Atomic M-component N-process snapshot implementation based on P. Jayanti, 3 | -- "An Optimal Multi-Writer Snapshot Algorithm", Proceedings of STOC'05, 4 | -- ACM, 2005. 5 | -- 6 | -- Copyright (C) 2007 Anders Gidenstam 7 | -- 8 | -- This program is free software; you can redistribute it and/or modify 9 | -- it under the terms of the GNU General Public License as published by 10 | -- the Free Software Foundation; either version 2 of the License, or 11 | -- (at your option) any later version. 12 | -- 13 | -- This program is distributed in the hope that it will be useful, 14 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | -- GNU General Public License for more details. 17 | -- 18 | -- You should have received a copy of the GNU General Public License 19 | -- along with this program; if not, write to the Free Software 20 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | -- 22 | ------------------------------------------------------------------------------- 23 | pragma Style_Checks (Off); 24 | ------------------------------------------------------------------------------- 25 | -- -*- Mode: Ada -*- 26 | -- Filename : atomic_multiwriter_snapshots.ads 27 | -- Description : M-component N-process snapshot implementation based on 28 | -- P. Jayanti, "An Optimal Multi-Writer Snapshot Algorithm", 29 | -- Proceedings of STOC'05, ACM, 2005. 30 | -- Author : Anders Gidenstam 31 | -- Created On : Fri May 11 15:58:30 2007 32 | -- $Id: nbada-atomic_multiwriter_snapshots.ads,v 1.2 2007/08/31 15:03:14 andersg Exp $ 33 | ------------------------------------------------------------------------------- 34 | pragma Style_Checks (All_Checks); 35 | 36 | pragma License (GPL); 37 | 38 | with NBAda.Process_Identification; 39 | with NBAda.Primitives; 40 | 41 | generic 42 | 43 | Max_Number_Of_Components : Natural; 44 | -- Maximum number of components in the snapshot. 45 | 46 | with package Process_Ids is 47 | new Process_Identification (<>); 48 | -- Process identification. 49 | 50 | package NBAda.Atomic_Multiwriter_Snapshots is 51 | 52 | pragma Elaborate_Body; 53 | 54 | type Snapshot (<>) is private; 55 | 56 | function Scan return Snapshot; 57 | 58 | Maximum_Number_Of_Components_Exceeded : exception; 59 | 60 | generic 61 | -- Use pragma Atomic and pragma Volatile for Target. 62 | -- Element'Object_Size MUST be System.Word_Size. 63 | type Element is private; 64 | package Element_Components is 65 | 66 | type Element_Component is private; 67 | 68 | function Create (Default_Value : in Element) return Element_Component; 69 | 70 | procedure Write (To : in Element_Component; 71 | Value : in Element); 72 | 73 | function Read (Component : in Element_Component; 74 | From : in Snapshot) return Element; 75 | 76 | private 77 | 78 | type Element_Component is 79 | record 80 | Index : Natural := 0; 81 | end record; 82 | 83 | end Element_Components; 84 | 85 | private 86 | 87 | type Component_Index is new Natural range 0 .. Max_Number_Of_Components; 88 | 89 | type Component_Impl is new Primitives.Standard_Unsigned; 90 | type Component_Array is array (Component_Index) of Component_Impl; 91 | 92 | type Snapshot is new Component_Array; 93 | 94 | end NBAda.Atomic_Multiwriter_Snapshots; 95 | -------------------------------------------------------------------------------- /src/benchmarks/Dictionaries/Lock-Free_Simple_Tree/test_dictionaries.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Dicitionary Test - Test benchmark for lock-free dictionaries. 3 | -- 4 | -- Copyright (C) 2008 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : test_dictionaries.ads 23 | -- Description : Test application for the lock-free dictionaries. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Tue Feb 26 14:31:56 2008 26 | -- $Id: test_dictionaries.ads,v 1.1 2008/03/05 11:11:40 andersg Exp $ 27 | ------------------------------------------------------------------------------- 28 | 29 | pragma License (GPL); 30 | 31 | with NBAda.Lock_Free_Simple_Trees; 32 | with NBAda.Process_Identification; 33 | 34 | generic 35 | 36 | type Value_Type is private; 37 | type Key_Type is private; 38 | 39 | with function Hash (Key : Key_Type; 40 | Table_Size : Positive) return Natural; 41 | -- Note: Not used. 42 | with function "<" (Left, Right : Key_Type) return Boolean is <>; 43 | -- Note: Key_Type must be totally ordered. 44 | with function Image (Key : Key_Type) return String is <>; 45 | 46 | with package Process_Ids is 47 | new NBAda.Process_Identification (<>); 48 | 49 | package Test_Dictionaries is 50 | 51 | package Trees is new 52 | NBAda.Lock_Free_Simple_Trees (Value_Type => Value_Type, 53 | Key_Type => Key_Type, 54 | "<" => "<", 55 | Process_Ids => Process_Ids); 56 | 57 | ---------------------------------------------------------------------------- 58 | -- Dictionary. 59 | ---------------------------------------------------------------------------- 60 | subtype Dictionary_Type is Trees.Dictionary_Type; 61 | 62 | Not_Found : exception 63 | renames Trees.Not_Found; 64 | Already_Present : exception 65 | renames Trees.Already_Present; 66 | 67 | procedure Init (Dictionary : in out Dictionary_Type) 68 | renames Trees.Init; 69 | 70 | procedure Insert (Into : in out Dictionary_Type; 71 | Key : in Key_Type; 72 | Value : in Value_Type) 73 | renames Trees.Insert; 74 | 75 | procedure Delete (From : in out Dictionary_Type; 76 | Key : in Key_Type) 77 | renames Trees.Delete; 78 | 79 | function Lookup (From : in Dictionary_Type; 80 | Key : in Key_Type) 81 | return Value_Type 82 | renames Trees.Lookup; 83 | 84 | procedure Verify (Dictionary : in out Dictionary_Type; 85 | Print : in Boolean := False) 86 | renames Trees.Verify; 87 | 88 | end Test_Dictionaries; 89 | -------------------------------------------------------------------------------- /src/benchmarks/Dictionaries/Red_Black_Trees/red_black_trees.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Dicitionary Test - Test benchmark for lock-free dictionaries. 3 | -- 4 | -- Copyright (C) 2008 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : red_black_trees.ads 23 | -- Description : Left-leaning red-black trees based on Robert Sedgewick's 24 | -- presentation at Dagstuhl, 2008-02-18. 25 | -- Author : Anders Gidenstam 26 | -- Created On : Tue Feb 26 18:25:37 2008 27 | -- $Id: red_black_trees.ads,v 1.1 2008/02/27 17:27:27 andersg Exp $ 28 | ------------------------------------------------------------------------------- 29 | 30 | pragma License (GPL); 31 | 32 | generic 33 | 34 | type Value_Type is private; 35 | type Key_Type is private; 36 | 37 | with function "<" (Left, Right : Key_Type) return Boolean is <>; 38 | -- Note: Key_Type must be totally ordered. 39 | 40 | with function Image (Key : Key_Type) return String is <>; 41 | 42 | package Red_Black_Trees is 43 | 44 | type Dictionary_Type is limited private; 45 | 46 | Not_Found : exception; 47 | Already_Present : exception; 48 | 49 | procedure Init (Dictionary : in out Dictionary_Type); 50 | 51 | procedure Insert (Into : in out Dictionary_Type; 52 | Key : in Key_Type; 53 | Value : in Value_Type); 54 | 55 | procedure Delete (From : in out Dictionary_Type; 56 | Key : in Key_Type); 57 | 58 | function Delete (From : in Dictionary_Type; 59 | Key : in Key_Type) 60 | return Value_Type; 61 | 62 | function Delete_Min (From : in Dictionary_Type) 63 | return Value_Type; 64 | 65 | function Delete_Max (From : in Dictionary_Type) 66 | return Value_Type; 67 | 68 | function Lookup (From : in Dictionary_Type; 69 | Key : in Key_Type) 70 | return Value_Type; 71 | 72 | procedure Verify (Tree : in out Dictionary_Type; 73 | Print : in Boolean := False); 74 | 75 | private 76 | 77 | type Color_Type is (Red, Black); 78 | 79 | type Tree_Node; 80 | type Tree_Node_Access is access Tree_Node; 81 | 82 | type Tree_Node is 83 | record 84 | Key : Key_Type; 85 | Value : Value_Type; 86 | Color : Color_Type; 87 | Left, Right : Tree_Node_Access; 88 | end record; 89 | 90 | type Mutable_View (Self : access Dictionary_Type) is 91 | limited null record; 92 | 93 | type Dictionary_Type is 94 | record 95 | Root : Tree_Node_Access; 96 | Mutable : Mutable_View (Dictionary_Type'Access); 97 | end record; 98 | 99 | end Red_Black_Trees; 100 | -------------------------------------------------------------------------------- /src/benchmarks/Dictionaries/Red_Black_Trees/mutex-based/test_dictionaries.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Dicitionary Test - Test benchmark for lock-free dictionaries. 3 | -- 4 | -- Copyright (C) 2008 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : test_dictionaries.ads 23 | -- Description : Test application for the lock-free dictionaries. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Tue Feb 26 14:31:56 2008 26 | -- $Id: test_dictionaries.ads,v 1.1 2008/02/27 17:27:27 andersg Exp $ 27 | ------------------------------------------------------------------------------- 28 | 29 | pragma License (GPL); 30 | 31 | with Red_Black_Trees; 32 | with NBAda.Process_Identification; 33 | 34 | generic 35 | 36 | type Value_Type is private; 37 | type Key_Type is private; 38 | 39 | with function Hash (Key : Key_Type; 40 | Table_Size : Positive) return Natural; 41 | -- Note: Not used. 42 | with function "<" (Left, Right : Key_Type) return Boolean is <>; 43 | -- Note: Key_Type must be totally ordered. 44 | with function Image (Key : Key_Type) return String is <>; 45 | 46 | with package Process_Ids is 47 | new NBAda.Process_Identification (<>); 48 | 49 | package Test_Dictionaries is 50 | 51 | ---------------------------------------------------------------------------- 52 | -- Dictionary. 53 | ---------------------------------------------------------------------------- 54 | type Dictionary_Type is limited private; 55 | 56 | Not_Found : exception; 57 | Already_Present : exception; 58 | 59 | procedure Init (Dictionary : in out Dictionary_Type); 60 | 61 | procedure Insert (Into : in out Dictionary_Type; 62 | Key : in Key_Type; 63 | Value : in Value_Type); 64 | 65 | procedure Delete (From : in out Dictionary_Type; 66 | Key : in Key_Type); 67 | 68 | function Lookup (From : in Dictionary_Type; 69 | Key : in Key_Type) 70 | return Value_Type; 71 | 72 | procedure Verify (Dictionary : in out Dictionary_Type; 73 | Print : in Boolean := False); 74 | 75 | private 76 | 77 | package Trees is new Red_Black_Trees (Key_Type => Key_Type, 78 | Value_Type => Value_Type); 79 | 80 | protected type Mutex_Type is 81 | entry Acquire; 82 | procedure Release; 83 | private 84 | Locked : Boolean := False; 85 | end Mutex_Type; 86 | 87 | type Mutable_View (Self : access Dictionary_Type) is 88 | limited null record; 89 | 90 | type Dictionary_Type is 91 | record 92 | Dictionary : Trees.Dictionary_Type; 93 | Mutex : Mutex_Type; 94 | Mutable : Mutable_View (Dictionary_Type'Access); 95 | end record; 96 | 97 | end Test_Dictionaries; 98 | -------------------------------------------------------------------------------- /src/Lock-Free_Queue/nbada-lock_free_queues.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Queue - An implementation of Michael and Scott's lock-free queue. 3 | -- Copyright (C) 2006 - 2011 Anders Gidenstam 4 | -- 5 | -- This program is free software; you can redistribute it and/or modify 6 | -- it under the terms of the GNU General Public License as published by 7 | -- the Free Software Foundation; either version 2 of the License, or 8 | -- (at your option) any later version. 9 | -- 10 | -- This program is distributed in the hope that it will be useful, 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | -- GNU General Public License for more details. 14 | -- 15 | -- You should have received a copy of the GNU General Public License 16 | -- along with this program; if not, write to the Free Software 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | -- 19 | ------------------------------------------------------------------------------- 20 | -- Filename : nbada-lock_free_queues.ads 21 | -- Description : An Ada implementation of Michael and Scott's 22 | -- lock-free queue algorithm. Based on 23 | -- M. Michael and M. Scott, 24 | -- "Simple, fast, and practical non-blocking and 25 | -- blocking concurrent queue algorithms", 26 | -- Proceedings of the 15th Annual ACM Symposium on 27 | -- Principles of Distributed Computing (PODC 1996), 28 | -- pages 267 - 275, ACM, 1996. 29 | -- Author : Anders Gidenstam 30 | -- Created On : Tue Nov 28 10:55:38 2006 31 | ------------------------------------------------------------------------------- 32 | 33 | pragma License (GPL); 34 | 35 | with NBAda.Process_Identification; 36 | with NBAda.Interfaces.Exceptions; 37 | with NBAda.Lock_Free_Queues_Memory_Reclamation_Adapter; 38 | 39 | generic 40 | 41 | type Element_Type is private; 42 | -- Element type. 43 | 44 | with package Process_Ids is 45 | new Process_Identification (<>); 46 | -- Process identification. 47 | 48 | package NBAda.Lock_Free_Queues is 49 | 50 | ---------------------------------------------------------------------------- 51 | -- Lock-free Queue. 52 | ---------------------------------------------------------------------------- 53 | type Queue_Type is limited private; 54 | 55 | Queue_Empty : exception 56 | renames NBAda.Interfaces.Exceptions.Empty; 57 | 58 | procedure Init (Queue : in out Queue_Type); 59 | function Dequeue (From : access Queue_Type) return Element_Type; 60 | procedure Enqueue (On : in out Queue_Type; 61 | Element : in Element_Type); 62 | 63 | private 64 | 65 | package MR_Adapter is 66 | new Lock_Free_Queues_Memory_Reclamation_Adapter (Process_Ids); 67 | package MR renames MR_Adapter.Memory_Reclamation; 68 | 69 | type Queue_Node_Reference is new Memory_Reclamation.Shared_Reference_Base; 70 | 71 | type Queue_Node is 72 | new MR.Managed_Node_Base with 73 | record 74 | Element : Element_Type; 75 | Next : aliased Queue_Node_Reference; 76 | pragma Atomic (Next); 77 | end record; 78 | 79 | procedure Free (Node : access Queue_Node); 80 | 81 | package MR_Ops is new MR.Reference_Operations 82 | (Managed_Node => Queue_Node, 83 | Shared_Reference => Queue_Node_Reference); 84 | 85 | type Queue_Type is 86 | limited record 87 | MM : MR_Ops.Memory_Manager; 88 | Head : aliased Queue_Node_Reference; 89 | pragma Atomic (Head); 90 | Tail : aliased Queue_Node_Reference; 91 | pragma Atomic (Tail); 92 | end record; 93 | 94 | end NBAda.Lock_Free_Queues; 95 | -------------------------------------------------------------------------------- /src/Lock-Free_Dictionary/nbada-lock_free_dictionaries.ads: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-Free Dictionaries - An implementation of the lock-free hash table 3 | -- algorithm by M. Michael. 4 | -- 5 | -- Copyright (C) 2007 Anders Gidenstam 6 | -- 7 | -- This program is free software; you can redistribute it and/or modify 8 | -- it under the terms of the GNU General Public License as published by 9 | -- the Free Software Foundation; either version 2 of the License, or 10 | -- (at your option) any later version. 11 | -- 12 | -- This program is distributed in the hope that it will be useful, 13 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | -- GNU General Public License for more details. 16 | -- 17 | -- You should have received a copy of the GNU General Public License 18 | -- along with this program; if not, write to the Free Software 19 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | -- 21 | ------------------------------------------------------------------------------- 22 | pragma Style_Checks (OFF); 23 | ------------------------------------------------------------------------------- 24 | -- -*- Mode: Ada -*- 25 | -- Filename : lock_free_dictionaries.ads 26 | -- Description : Lock-free dictionary based on Maged Michael, 27 | -- "High Performance Dynamic Lock-Free Hash Tables and 28 | -- List-Based Sets", The 14th Annual ACM Symposium on 29 | -- Parallel Algorithms and Architectures (SPAA'02), 30 | -- pages 73-82, August 2002. 31 | -- Author : Anders Gidenstam 32 | -- Created On : Fri May 18 17:01:34 2007 33 | -- $Id: nbada-lock_free_dictionaries.ads,v 1.2 2007/09/03 09:56:27 andersg Exp $ 34 | ------------------------------------------------------------------------------- 35 | pragma Style_Checks (ALL_CHECKS); 36 | 37 | pragma License (GPL); 38 | 39 | with NBAda.Process_Identification; 40 | 41 | with NBAda.Lock_Free_Sets; 42 | 43 | generic 44 | 45 | type Value_Type is private; 46 | type Key_Type is private; 47 | 48 | with function Hash (Key : Key_Type; 49 | Table_Size : Positive) return Natural; 50 | 51 | with function "<" (Left, Right : Key_Type) return Boolean is <>; 52 | -- Note: Key_Type must be totally ordered. 53 | 54 | with package Process_Ids is 55 | new NBAda.Process_Identification (<>); 56 | -- Process identification. 57 | 58 | package NBAda.Lock_Free_Dictionaries is 59 | 60 | type Dictionary_Type (No_Buckets : Natural) is limited private; 61 | 62 | Not_Found : exception; 63 | Already_Present : exception; 64 | 65 | procedure Init (Dictionary : in out Dictionary_Type); 66 | 67 | procedure Insert (Into : in out Dictionary_Type; 68 | Key : in Key_Type; 69 | Value : in Value_Type); 70 | 71 | procedure Delete (From : in out Dictionary_Type; 72 | Key : in Key_Type); 73 | 74 | function Lookup (From : in Dictionary_Type; 75 | Key : in Key_Type) 76 | return Value_Type; 77 | 78 | private 79 | 80 | package Sets is new Lock_Free_Sets (Value_Type => Value_Type, 81 | Key_Type => Key_Type, 82 | "<" => "<", 83 | Process_Ids => Process_Ids); 84 | 85 | subtype Bucket_Index is Natural; 86 | 87 | type Set_Array is array (Bucket_Index range <>) of Sets.Set_Type; 88 | 89 | type Dictionary_Type (No_Buckets : Natural) is 90 | record 91 | Hash_Bucket : Set_Array (0 .. No_Buckets); 92 | end record; 93 | 94 | end NBAda.Lock_Free_Dictionaries; 95 | -------------------------------------------------------------------------------- /src/benchmarks/Queues/Lock-Free_Bounded_Queue/test_queues.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Queue Test - Test benchmark for lock-free queues. 3 | -- 4 | -- Copyright (C) 2007 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : test_queues.adb 23 | -- Description : Benchmark application for lock-free queues. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Wed Sep 12 16:35:41 2007 26 | -- $Id: test_queues.adb,v 1.1 2007/09/12 15:35:18 andersg Exp $ 27 | ------------------------------------------------------------------------------- 28 | 29 | pragma License (GPL); 30 | 31 | with Ada.Unchecked_Deallocation; 32 | with NBAda.Lock_Free_Growing_Storage_Pools; 33 | 34 | package body Test_Queues is 35 | 36 | ------------------------------------------------------------------------- 37 | -- Storage pool for the nodes. 38 | ------------------------------------------------------------------------- 39 | 40 | Node_Pool : NBAda.Lock_Free_Growing_Storage_Pools.Lock_Free_Storage_Pool 41 | (Block_Size => Element_Type'Max_Size_In_Storage_Elements); 42 | 43 | type New_Element_Access is access Element_Type; 44 | for New_Element_Access'Storage_Pool use Node_Pool; 45 | 46 | function To_New_Element_Access is 47 | new Ada.Unchecked_Conversion (Element_Access, 48 | New_Element_Access); 49 | 50 | ---------------------------------------------------------------------------- 51 | procedure Init (Queue : in out Queue_Type) is 52 | begin 53 | if Queue.Impl = null then 54 | Queue.Impl := new Queues.Lock_Free_Queue 55 | (Queues.Queue_Size (10_000 * 56 | Natural (Process_Ids.Process_ID_Type'Last))); 57 | end if; 58 | end Init; 59 | 60 | ---------------------------------------------------------------------------- 61 | function Dequeue (From : access Queue_Type) return Element_Type is 62 | procedure Free is new Ada.Unchecked_Deallocation (Element_Type, 63 | New_Element_Access); 64 | begin 65 | declare 66 | Item : New_Element_Access := 67 | To_New_Element_Access (Queues.Dequeue (From.Impl)); 68 | Element : constant Element_Type := Item.all; 69 | begin 70 | Free (Item); 71 | return Element; 72 | end; 73 | exception 74 | when Queues.Queue_Empty => 75 | raise Queue_Empty; 76 | end Dequeue; 77 | 78 | ---------------------------------------------------------------------------- 79 | procedure Enqueue (On : in out Queue_Type; 80 | Element : in Element_Type) is 81 | Item : constant New_Element_Access := new Element_Type'(Element); 82 | begin 83 | Queues.Enqueue (On.Impl.all, 84 | Element_Access (Item)); 85 | exception 86 | when Queues.Queue_Full => 87 | raise Queue_Full; 88 | end Enqueue; 89 | 90 | end Test_Queues; 91 | -------------------------------------------------------------------------------- /src/benchmarks/Queues/Lock-Free_Queue_3/test_queues.adb: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | -- Lock-free Queue Test - Test benchmark for lock-free queues. 3 | -- 4 | -- Copyright (C) 2007 - 2011 Anders Gidenstam 5 | -- 6 | -- This program is free software; you can redistribute it and/or modify 7 | -- it under the terms of the GNU General Public License as published by 8 | -- the Free Software Foundation; either version 2 of the License, or 9 | -- (at your option) any later version. 10 | -- 11 | -- This program is distributed in the hope that it will be useful, 12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | -- GNU General Public License for more details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License 17 | -- along with this program; if not, write to the Free Software 18 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | -- 20 | ------------------------------------------------------------------------------- 21 | -- -*- Mode: Ada -*- 22 | -- Filename : test_queues.adb 23 | -- Description : Benchmark application for lock-free queues. 24 | -- Author : Anders Gidenstam 25 | -- Created On : Wed Sep 12 16:35:41 2007 26 | ------------------------------------------------------------------------------- 27 | 28 | pragma License (GPL); 29 | 30 | with Ada.Unchecked_Deallocation; 31 | with NBAda.Lock_Free_Growing_Storage_Pools; 32 | 33 | package body Test_Queues is 34 | 35 | ------------------------------------------------------------------------- 36 | -- Storage pool for the nodes. 37 | ------------------------------------------------------------------------- 38 | 39 | Node_Pool : NBAda.Lock_Free_Growing_Storage_Pools.Lock_Free_Storage_Pool 40 | (Block_Size => Element_Type'Max_Size_In_Storage_Elements); 41 | 42 | type New_Element_Access is access Element_Type; 43 | for New_Element_Access'Storage_Pool use Node_Pool; 44 | 45 | function To_New_Element_Access is 46 | new Ada.Unchecked_Conversion (Element_Access, 47 | New_Element_Access); 48 | 49 | type Outer_Queue_Access is access all Queue_Type; 50 | type Queue_Access is access all Queues.Queue_Type; 51 | 52 | function To_Queue_Access is 53 | new Ada.Unchecked_Conversion (Outer_Queue_Access, 54 | Queue_Access); 55 | 56 | ---------------------------------------------------------------------------- 57 | procedure Init (Queue : in out Queue_Type) is 58 | begin 59 | Queues.Init (Queues.Queue_Type (Queue)); 60 | end Init; 61 | 62 | ---------------------------------------------------------------------------- 63 | function Dequeue (From : access Queue_Type) return Element_Type is 64 | procedure Free is new Ada.Unchecked_Deallocation (Element_Type, 65 | New_Element_Access); 66 | begin 67 | declare 68 | Item : New_Element_Access := 69 | To_New_Element_Access 70 | (Queues.Dequeue (To_Queue_Access (Outer_Queue_Access (From)))); 71 | Element : constant Element_Type := Item.all; 72 | begin 73 | Free (Item); 74 | return Element; 75 | end; 76 | exception 77 | when Queues.Queue_Empty => 78 | raise Queue_Empty; 79 | end Dequeue; 80 | 81 | ---------------------------------------------------------------------------- 82 | procedure Enqueue (On : in out Queue_Type; 83 | Element : in Element_Type) is 84 | Item : constant New_Element_Access := new Element_Type'(Element); 85 | begin 86 | Queues.Enqueue (Queues.Queue_Type (On), 87 | Element_Access (Item)); 88 | end Enqueue; 89 | 90 | end Test_Queues; 91 | --------------------------------------------------------------------------------