2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 * Copyright (c) 2009 Mathieu Desnoyers
19 /* 16 CPUs max (byte has 8 bits, divided in two) */
21 #ifndef CONFIG_BITS_PER_BYTE
22 #define BITS_PER_BYTE 8
24 #define BITS_PER_BYTE CONFIG_BITS_PER_BYTE
27 #define HBPB (BITS_PER_BYTE / 2) /* 4 */
28 #define HMASK ((1 << HBPB) - 1) /* 0x0F */
31 #define LOW_HALF(val) ((val) & HMASK)
32 #define LOW_HALF_INC 1
34 #define HIGH_HALF(val) ((val) & (HMASK << HBPB))
35 #define HIGH_HALF_INC (1 << HBPB)
40 inline spin_lock(lock, ticket)
43 ticket = HIGH_HALF(lock) >> HBPB;
44 lock = lock + HIGH_HALF_INC; /* overflow expected */
50 :: (LOW_HALF(lock) == ticket) ->
58 inline spin_unlock(lock)
60 lock = HIGH_HALF(lock) | LOW_HALF(lock + LOW_HALF_INC);
69 spin_lock(lock, ticket);
70 refcount = refcount + 1;
71 refcount = refcount - 1;