11#include <stdlib.h>
22#include <string.h>
33#include <stdio.h>
4- #include <pthread.h>
5- #include <stdatomic.h>
64
75#include "cmark_ctype.h"
86#include "cmark-gfm_config.h"
@@ -69,8 +67,7 @@ typedef struct subject{
6967// Extensions may populate this.
7068static int8_t SKIP_CHARS [256 ];
7169
72- pthread_mutex_t chars_lock ;
73- static atomic_int chars_latch = 0 ;
70+ CMARK_DEFINE_LOCK (chars );
7471
7572static CMARK_INLINE bool S_is_line_end_char (char c ) {
7673 return (c == '\n' || c == '\r' );
@@ -411,8 +408,7 @@ static int scan_delims(subject *subj, unsigned char c, bool *can_open,
411408 } else {
412409 before_char_pos = subj -> pos - 1 ;
413410
414- initialize_mutex_once (& chars_lock , & chars_latch );
415- pthread_mutex_lock (& chars_lock );
411+ CMARK_INITIALIZE_AND_LOCK (chars );
416412
417413 // walk back to the beginning of the UTF_8 sequence:
418414 while ((peek_at (subj , before_char_pos ) >> 6 == 2 || SKIP_CHARS [peek_at (subj , before_char_pos )]) && before_char_pos > 0 ) {
@@ -424,7 +420,7 @@ static int scan_delims(subject *subj, unsigned char c, bool *can_open,
424420 before_char = 10 ;
425421 }
426422
427- pthread_mutex_unlock ( & chars_lock );
423+ CMARK_UNLOCK ( chars );
428424 }
429425
430426 if (c == '\'' || c == '"' ) {
@@ -442,8 +438,7 @@ static int scan_delims(subject *subj, unsigned char c, bool *can_open,
442438 } else {
443439 after_char_pos = subj -> pos ;
444440
445- initialize_mutex_once (& chars_lock , & chars_latch );
446- pthread_mutex_lock (& chars_lock );
441+ CMARK_INITIALIZE_AND_LOCK (chars );
447442
448443 while (SKIP_CHARS [peek_at (subj , after_char_pos )] && after_char_pos < subj -> input .len ) {
449444 after_char_pos += 1 ;
@@ -454,7 +449,7 @@ static int scan_delims(subject *subj, unsigned char c, bool *can_open,
454449 after_char = 10 ;
455450 }
456451
457- pthread_mutex_unlock ( & chars_lock );
452+ CMARK_UNLOCK ( chars );
458453 }
459454
460455 left_flanking = numdelims > 0 && !cmark_utf8proc_is_space (after_char ) &&
@@ -1382,21 +1377,19 @@ static bufsize_t subject_find_special_char(subject *subj, int options) {
13821377}
13831378
13841379void cmark_inlines_add_special_character (unsigned char c , bool emphasis ) {
1385- initialize_mutex_once (& chars_lock , & chars_latch );
1386- pthread_mutex_lock (& chars_lock );
1380+ CMARK_INITIALIZE_AND_LOCK (chars );
13871381 SPECIAL_CHARS [c ] = 1 ;
13881382 if (emphasis )
13891383 SKIP_CHARS [c ] = 1 ;
1390- pthread_mutex_unlock ( & chars_lock );
1384+ CMARK_UNLOCK ( chars );
13911385}
13921386
13931387void cmark_inlines_remove_special_character (unsigned char c , bool emphasis ) {
1394- initialize_mutex_once (& chars_lock , & chars_latch );
1395- pthread_mutex_lock (& chars_lock );
1388+ CMARK_INITIALIZE_AND_LOCK (chars );
13961389 SPECIAL_CHARS [c ] = 0 ;
13971390 if (emphasis )
13981391 SKIP_CHARS [c ] = 0 ;
1399- pthread_mutex_unlock ( & chars_lock );
1392+ CMARK_UNLOCK ( chars );
14001393}
14011394
14021395static cmark_node * try_extensions (cmark_parser * parser ,
0 commit comments