Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

update test cases

  • Loading branch information...
commit 8e5a07e13a0b51e53a18d2b0ff18020cdf1acc56 1 parent 3f37107
Ben Blum authored

Showing 3 changed files with 44 additions and 55 deletions. Show diff stats Hide diff stats

  1. +19 25 contravariant.c
  2. +20 25 covariant.c
  3. +5 5 noob.c
44 contravariant.c
... ... @@ -1,56 +1,50 @@
1 1 #ifdef ATOMIC_ALL_NIGHTERS
2 2 /* function annotations */
3   -#define MIGHT_SLEEP __attribute__((might_sleep))
4   -#define DOESNT_SLEEP __attribute__((doesnt_sleep))
  3 +#define MAY_SLEEP __attribute__((atomic_all_nighters("might_sleep")))
  4 +#define WONT_SLEEP __attribute__((atomic_all_nighters("wont_sleep")))
5 5
6 6 /* context-changing annotations */
7   -#define ENTER_ATOMIC __attribute__((enter_atomic))
8   -#define EXIT_ATOMIC __attribute__((exit_atomic))
9   -#define ENTER_ATOMIC_NESTED __attribute__((enter_atomic_nested))
10   -#define EXIT_ATOMIC_NESTED __attribute__((exit_atomic_nested))
11   -
12   -
13   -/* context types (really, function pointer types.) */
14   -#define MUSTNT_SLEEP __attribute__((mustnt_sleep))
15   -#define MAY_SLEEP __attribute__((may_sleep))
16   -/* is MAY_SLEEP the default? what about function pointers that change the ctx? */
  7 +#define ENTER_ATOMIC __attribute__((atomic_all_nighters("wont_sleep","force_enable")))
  8 +#define EXIT_ATOMIC __attribute__((atomic_all_nighters("wont_sleep","force_disable")))
  9 +#define ENTER_ATOMIC_NESTED __attribute__((atomic_all_nighters("wont_sleep","enter_nested")))
  10 +#define EXIT_ATOMIC_NESTED __attribute__((atomic_all_nighters("wont_sleep","exit_nested")))
17 11
18 12 #else
19   -#define MIGHT_SLEEP
20   -#define DOESNT_SLEEP
  13 +#define MAY_SLEEP
  14 +#define WONT_SLEEP
21 15 #define ENTER_ATOMIC
22 16 #define EXIT_ATOMIC
23 17 #define ENTER_ATOMIC_NESTED
24 18 #define EXIT_ATOMIC_NESTED
25   -#define MUSTNT_SLEEP
26   -#define MAY_SLEEP
27 19 #endif
28 20
29 21 struct mutex;
30 22 struct spinlock;
31 23
32   -void mutex_lock(struct mutex *mp) MIGHT_SLEEP;
33   -void mutex_unlock(struct mutex *mp) MIGHT_SLEEP;
34   -void mutex_assert_is_locked(struct mutex *mp) DOESNT_SLEEP;
  24 +void MAY_SLEEP mutex_lock(struct mutex *mp);
  25 +void MAY_SLEEP mutex_unlock(struct mutex *mp);
  26 +void WONT_SLEEP mutex_assert_is_locked(struct mutex *mp);
35 27
36   -void spin_lock(struct spinlock *sp) ENTER_ATOMIC_NESTED;
37   -void spin_unlock(struct spinlock *sp) EXIT_ATOMIC_NESTED;
  28 +void ENTER_ATOMIC_NESTED spin_lock(struct spinlock *sp);
  29 +void EXIT_ATOMIC_NESTED spin_unlock(struct spinlock *sp);
38 30
39 31 struct spinlock *a;
40 32 struct mutex *m;
41 33
42 34 void (*h)(struct mutex *) MAY_SLEEP;
43 35
44   -void g(void (*x)(struct mutex *) MAY_SLEEP) DOESNT_SLEEP
  36 +void WONT_SLEEP g(void (*x)(struct mutex *) MAY_SLEEP)
45 37 {
46 38 h = x;
47 39 }
48 40
49   -int main() MIGHT_SLEEP {
50   - void (*f)(void (*)(struct mutex *) MUSTNT_SLEEP) MUSTNT_SLEEP = g;
  41 +int MAY_SLEEP main()
  42 +{
  43 + // This should succeed.
  44 + // Argument types contravary, so (may_sleep -> ()) <: (wont_sleep -> ())
  45 + void (*f)(void (*)(struct mutex *) WONT_SLEEP) WONT_SLEEP = g;
51 46 spin_lock(a);
52 47 f(mutex_assert_is_locked);
53 48 spin_unlock(a);
54 49 h(m);
55   - return 0;
56 50 }
45 covariant.c
... ... @@ -1,53 +1,48 @@
1 1 #ifdef ATOMIC_ALL_NIGHTERS
2 2 /* function annotations */
3   -#define MIGHT_SLEEP __attribute__((might_sleep))
4   -#define DOESNT_SLEEP __attribute__((doesnt_sleep))
  3 +#define MAY_SLEEP __attribute__((atomic_all_nighters("might_sleep")))
  4 +#define WONT_SLEEP __attribute__((atomic_all_nighters("wont_sleep")))
5 5
6 6 /* context-changing annotations */
7   -#define ENTER_ATOMIC __attribute__((enter_atomic))
8   -#define EXIT_ATOMIC __attribute__((exit_atomic))
9   -#define ENTER_ATOMIC_NESTED __attribute__((enter_atomic_nested))
10   -#define EXIT_ATOMIC_NESTED __attribute__((exit_atomic_nested))
11   -
12   -
13   -/* context types (really, function pointer types.) */
14   -#define MUSTNT_SLEEP __attribute__((mustnt_sleep))
15   -#define MAY_SLEEP __attribute__((may_sleep))
16   -/* is MAY_SLEEP the default? what about function pointers that change the ctx? */
  7 +#define ENTER_ATOMIC __attribute__((atomic_all_nighters("wont_sleep","force_enable")))
  8 +#define EXIT_ATOMIC __attribute__((atomic_all_nighters("wont_sleep","force_disable")))
  9 +#define ENTER_ATOMIC_NESTED __attribute__((atomic_all_nighters("wont_sleep","enter_nested")))
  10 +#define EXIT_ATOMIC_NESTED __attribute__((atomic_all_nighters("wont_sleep","exit_nested")))
17 11
18 12 #else
19   -#define MIGHT_SLEEP
20   -#define DOESNT_SLEEP
  13 +#define MAY_SLEEP
  14 +#define WONT_SLEEP
21 15 #define ENTER_ATOMIC
22 16 #define EXIT_ATOMIC
23 17 #define ENTER_ATOMIC_NESTED
24 18 #define EXIT_ATOMIC_NESTED
25   -#define MUSTNT_SLEEP
26   -#define MAY_SLEEP
27 19 #endif
28 20
29 21 struct mutex;
30 22 struct spinlock;
31 23
32   -void mutex_lock(struct mutex *mp) MIGHT_SLEEP;
33   -void mutex_unlock(struct mutex *mp) MIGHT_SLEEP;
34   -void mutex_assert_is_locked(struct mutex *mp) DOESNT_SLEEP;
  24 +void MAY_SLEEP mutex_lock(struct mutex *mp);
  25 +void MAY_SLEEP mutex_unlock(struct mutex *mp);
  26 +void WONT_SLEEP mutex_assert_is_locked(struct mutex *mp);
35 27
36   -void spin_lock(struct spinlock *sp) ENTER_ATOMIC_NESTED;
37   -void spin_unlock(struct spinlock *sp) EXIT_ATOMIC_NESTED;
  28 +void ENTER_ATOMIC_NESTED spin_lock(struct spinlock *sp);
  29 +void EXIT_ATOMIC_NESTED spin_unlock(struct spinlock *sp);
38 30
39 31 struct spinlock *a;
40 32 struct mutex *m;
41 33
42   -void g(void (*x)(struct mutex *) MUSTNT_SLEEP) DOESNT_SLEEP
  34 +void WONT_SLEEP g(void (*x)(struct mutex *) WONT_SLEEP)
43 35 {
44 36 spin_lock(a);
45 37 x(m);
46 38 spin_unlock(a);
47 39 }
48 40
49   -int main() MIGHT_SLEEP {
50   - void (*f)(void (*)(struct mutex *) MAY_SLEEP) MUSTNT_SLEEP = g;
  41 +int MAY_SLEEP main()
  42 +{
  43 + // This should fail.
  44 + // Argument types must contravary, not covary.
  45 + void (*f)(void (*)(struct mutex *) MAY_SLEEP) WONT_SLEEP = g;
51 46 f(mutex_lock);
52   - return 0;
  47 + // return 0;
53 48 }
10 noob.c
... ... @@ -1,6 +1,6 @@
1 1 #ifdef ATOMIC_ALL_NIGHTERS
2 2 /* function annotations */
3   -#define MIGHT_SLEEP __attribute__((atomic_all_nighters("might_sleep")))
  3 +#define MAY_SLEEP __attribute__((atomic_all_nighters("might_sleep")))
4 4
5 5 /* context-changing annotations */
6 6 #define ENTER_ATOMIC __attribute__((atomic_all_nighters("wont_sleep","force_disable")))
@@ -9,7 +9,7 @@
9 9 #define EXIT_ATOMIC_NESTED __attribute__((atomic_all_nighters("wont_sleep","exit_nested")))
10 10
11 11 #else
12   -#define MIGHT_SLEEP
  12 +#define MAY_SLEEP
13 13 #define ENTER_ATOMIC
14 14 #define EXIT_ATOMIC
15 15 #define ENTER_ATOMIC_NESTED
@@ -19,8 +19,8 @@
19 19 struct mutex;
20 20 struct spinlock;
21 21
22   -void mutex_lock(struct mutex *mp) MIGHT_SLEEP;
23   -void mutex_unlock(struct mutex *mp) MIGHT_SLEEP;
  22 +void mutex_lock(struct mutex *mp) MAY_SLEEP;
  23 +void mutex_unlock(struct mutex *mp) MAY_SLEEP;
24 24
25 25 void spin_lock(struct spinlock *sp) ENTER_ATOMIC_NESTED;
26 26 void spin_unlock(struct spinlock *sp) EXIT_ATOMIC_NESTED;
@@ -33,7 +33,7 @@ int x;
33 33 int y;
34 34 int z;
35 35
36   -int main() {
  36 +int MAY_SLEEP main() {
37 37 spin_lock(a);
38 38 x++;
39 39 spin_lock(b);

0 comments on commit 8e5a07e

Please sign in to comment.
Something went wrong with that request. Please try again.