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 // test progress failure with shorter byte size. Will fail with 5 proc.
26 #define BITS_PER_BYTE CONFIG_BITS_PER_BYTE
29 #define HBPB (BITS_PER_BYTE / 2) /* 4 */
30 #define HMASK ((1 << HBPB) - 1) /* 0x0F */
33 #define LOW_HALF(val) ((val) & HMASK)
34 #define LOW_HALF_INC 1
36 #define HIGH_HALF(val) ((val) & (HMASK << HBPB))
37 #define HIGH_HALF_INC (1 << HBPB)
42 #define need_pause() (_pid == 2)
45 * Test weak fairness by either not pausing or cycling for any number of
47 * Models a slow thread. Should be added between each atomic steps.
48 * To test for wait-freedom (no starvation of a specific thread), add do_pause
49 * in threads other than the one we are checking for progress (and which
50 * contains the progress label).
51 * To test for lock-freedom (system-wide progress), add to all threads except
52 * one. All threads contain progress labels.
71 inline spin_lock(lock, ticket)
74 ticket = HIGH_HALF(lock) >> HBPB;
75 lock = lock + HIGH_HALF_INC; /* overflow expected */
81 :: (LOW_HALF(lock) == ticket) ->
89 inline spin_unlock(lock)
91 lock = HIGH_HALF(lock) | LOW_HALF(lock + LOW_HALF_INC);
101 spin_lock(lock, ticket);
102 refcount = refcount + 1;
103 refcount = refcount - 1;
115 spin_lock(lock, ticket);
116 refcount = refcount + 1;
118 refcount = refcount - 1;