1 // C99 port from c++ is protected by a GNU Lesser GPLv3
2 // Copyright © 2013 Sylvain BERTRAND <sylvain.bertrand@gmail.com>
3 // <sylware@legeek.net>
8 #include "hb-private.h"
9 #include "hb-atomic-private.h"
10 #include "hb-shaper-private.h"
12 static struct hb_shaper_pair_t all_shapers
[] = {
14 {"graphite2", hb_graphite2_shape
},
19 {"fallback", hb_fallback_shape
}
22 //Thread-safe, lock-free, shapers
24 static struct hb_shaper_pair_t
*static_shapers
= NULL
;
26 struct hb_shaper_pair_t
*
30 struct hb_shaper_pair_t
*shapers
= hb_atomic_ptr_get(&static_shapers
);
34 char *env
= getenv("HB_SHAPER_LIST");
36 void *expected
= NULL
;
37 void *desired
= &all_shapers
[0];
38 hb_atomic_ptr_cmpexch(&static_shapers
, &expected
, &desired
);
42 //Not found; allocate one
43 shapers
= malloc(sizeof(all_shapers
));
45 void *expected
= NULL
;
46 void *desired
= &all_shapers
[0];
47 hb_atomic_ptr_cmpexch(&static_shapers
, &expected
, &desired
);
51 memcpy(shapers
, all_shapers
, sizeof(all_shapers
));
53 //Reorder shaper list to prefer requested shapers.
61 for (unsigned j
= i
; j
< ARRAY_LENGTH(all_shapers
); ++j
)
62 if (end
- p
== (int)strlen(shapers
[j
].name
) &&
63 0 == strncmp(shapers
[j
].name
, p
, end
- p
)) {
64 //Reorder this shaper to position i
65 struct hb_shaper_pair_t t
= shapers
[j
];
66 memmove(&shapers
[i
+ 1], &shapers
[i
], sizeof (shapers
[i
]) * (j
- i
));
77 void *expected
= NULL
;
78 if (hb_atomic_ptr_cmpexch(&static_shapers
, &expected
, &shapers
)) {