Last active
August 29, 2015 14:14
Revisions
-
candeira revised this gist
Feb 3, 2015 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,14 +9,13 @@ // and the wrap-a-block version #define SPINLOCKME(lock, statement_or_block) \ do { \ lock_p * _mylock = &(lock); \ while (*_mylock) || ! __sync_bool_compare_and_swap(_mylock , 0 , 1)); \ statement_or_block; \ *_mylock = 0; \ } while(0) // for reference, my second attempt: -
candeira revised this gist
Feb 3, 2015 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,21 +1,21 @@ // macro-ize gallir's spinlock code from: // http://stackoverflow.com/questions/6704252/atomic-memcpy-suggestion/28286503#28286503 // third version, thanks to kragen for explains of expression/statement and do/while protective coding #define SPINLOCK(lock) do { while ((lock) || ! __sync_bool_compare_and_swap(&(lock) , 0 , 1));} while (0) #define SPINUNLOCK(lock) (lock) = 0; // and the wrap-a-block version #define SPINLOCKME(lock, block) { do { \ do { \ lock_p * _mylock = &(lock); \ while (*_mylock) || ! __sync_bool_compare_and_swap(_mylock , 0 , 1)); \ block; \ *_mylock = 0; \ } while (0) } // for reference, my second attempt: -
candeira revised this gist
Feb 3, 2015 . 1 changed file with 7 additions and 4 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,10 +9,13 @@ // still workin progress #define SPINLOCKME(lock, block) { do { \ do { \ lock_p * _mylock = &(lock); \ while (*_mylock) || ! __sync_bool_compare_and_swap(_mylock , 0 , 1)); \ block; \ *_mylock = 0; \ } while 0 } // for reference, my second attempt: -
candeira revised this gist
Feb 3, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ // third version, thanks to kragen for explains #define SPINLOCK(lock) do { while ((lock) || ! __sync_bool_compare_and_swap(&(lock) , 0 , 1));} while 0 #define SPINUNLOCK(lock) (lock) = 0; -
candeira revised this gist
Feb 3, 2015 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,8 @@ // macro-ize gallir's spinlock code from: // http://stackoverflow.com/questions/6704252/atomic-memcpy-suggestion/28286503#28286503 // third version, thanks to kragen for explains #define SPINLOCK(lock) do { while (lock || ! __sync_bool_compare_and_swap(&(lock) , 0 , 1));} while 0 #define SPINUNLOCK(lock) (lock) = 0; -
candeira revised this gist
Feb 3, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,7 @@ #define SPINUNLOCK(lock) (lock) = 0; // still workin progress #define SPINLOCKME(lock, block) { \ do { (lock || ! __sync_bool_compare_and_swap(&lock , 0 , 1)); \ -
candeira revised this gist
Feb 3, 2015 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,19 @@ // macro-ize gallir's spinlock code from: // http://stackoverflow.com/questions/6704252/atomic-memcpy-suggestion/28286503#28286503 #define SPINLOCK(lock) do { while (lock || ! __sync_bool_compare_and_swap(&(lock) , 0 , 1));} while 0 #define SPINUNLOCK(lock) (lock) = 0; #define SPINLOCKME(lock, block) { \ do { (lock || ! __sync_bool_compare_and_swap(&lock , 0 , 1)); \ block; \ lock = 0; \ } // for reference, my second attempt: #define SPINLOCK(lock) while (lock || ! __sync_bool_compare_and_swap(&lock , 0 , 1)); #define SPINUNLOCK(lock) lock = 0; -
candeira revised this gist
Feb 3, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ // macro-ize gallir's spinlock code from: // http://stackoverflow.com/questions/6704252/atomic-memcpy-suggestion/28286503#28286503 #define SPINLOCK(lock) while (lock || ! __sync_bool_compare_and_swap(&lock , 0 , 1)); #define SPINUNLOCK(lock) lock = 0; // -
candeira revised this gist
Feb 2, 2015 . 1 changed file with 9 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,17 @@ // macro-ize gallir's spinlock code from: // http://stackoverflow.com/questions/6704252/atomic-memcpy-suggestion/28286503#28286503 #define SPINLOCK(lock) (while (lock || ! __sync_bool_compare_and_swap(&lock , 0 , 1));) #define SPINUNLOCK(lock) (lock = 0;) // // for reference, my first attempt: will probably not work because of whitespace in code, but first attempt at a macro ever. #define SPINLOCKME(lock, code) { \ while (lock || ! __sync_bool_compare_and_swap(&lock , 0 , 1)); \ code; \ lock = 0; \ } -
candeira revised this gist
Feb 2, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ // http://stackoverflow.com/questions/6704252/atomic-memcpy-suggestion/28286503#28286503 #define SPINLOCKME(lock, code) { \ while (lock || ! __sync_bool_compare_and_swap(&lock , 0 , 1)); \ code; \ lock = 0; \ } -
candeira created this gist
Feb 2, 2015 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ // attempting to macro-ize gallir's spinlock code from: // http://stackoverflow.com/questions/6704252/atomic-memcpy-suggestion/28286503#28286503 #define SPINLOCKME(lock, code) { \ while (lock || ! __sync_bool_compare_and_swap(&lock , 0 , 1)); // spin \ code; \ lock = 0; \ } // will probably not work because of whitespace in code, but first attempt at a macro ever.