1 #define refcount_gt_one (refcount > 1)
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 * Copyright (c) 2009 Mathieu Desnoyers
20 /* 16 CPUs max (byte has 8 bits, divided in two) */
22 #ifndef CONFIG_BITS_PER_BYTE
23 #define BITS_PER_BYTE 8
25 #define BITS_PER_BYTE CONFIG_BITS_PER_BYTE
28 #define HBPB (BITS_PER_BYTE / 2) /* 4 */
29 #define HMASK ((1 << HBPB) - 1) /* 0x0F */
32 #define LOW_HALF(val) ((val) & HMASK)
33 #define LOW_HALF_INC 1
35 #define HIGH_HALF(val) ((val) & (HMASK << HBPB))
36 #define HIGH_HALF_INC (1 << HBPB)
41 #define need_pause() (_pid == 1)
44 * Test weak fairness by either not pausing or cycling for any number of
46 * Models a slow thread. Should be added between each atomic steps.
47 * To test for wait-freedom (no starvation of a specific thread), add do_pause
48 * in threads other than the one we are checking for progress (and which
49 * contains the progress label).
50 * To test for lock-freedom (system-wide progress), add to all threads except
51 * one. All threads contain progress labels.
69 inline spin_lock(lock, ticket)
72 ticket = HIGH_HALF(lock) >> HBPB;
73 lock = lock + HIGH_HALF_INC; /* overflow expected */
79 :: (LOW_HALF(lock) == ticket) ->
87 inline spin_unlock(lock)
89 lock = HIGH_HALF(lock) | LOW_HALF(lock + LOW_HALF_INC);
98 spin_lock(lock, ticket);
100 refcount = refcount + 1;
102 refcount = refcount - 1;