Skip to content

Commit

Permalink
Do not export GC_call_with_reader_lock API symbol in single-threaded …
Browse files Browse the repository at this point in the history
…build

(fix of commit 08e4e25)

Issue #473 (bdwgc).

* include/gc/gc.h [!GC_THREADS] (GC_call_with_reader_lock): Define as
a macro.
* misc.c (GC_call_with_reader_lock): Do not define (implement) unless
THREADS macro is defined.
  • Loading branch information
ivmai committed Oct 11, 2023
1 parent b4970f8 commit 89a0bf4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
6 changes: 5 additions & 1 deletion include/gc/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1567,9 +1567,13 @@ GC_API void * GC_CALL GC_call_with_alloc_lock(GC_fn_type /* fn */,
/* (shared) mode. The 3rd argument (release), if non-zero, indicates */
/* that fn wrote some data that should be made visible to the thread */
/* which acquires the allocator lock in the exclusive mode later. */
GC_API void * GC_CALL GC_call_with_reader_lock(GC_fn_type /* fn */,
#ifdef GC_THREADS
GC_API void * GC_CALL GC_call_with_reader_lock(GC_fn_type /* fn */,
void * /* client_data */,
int /* release */) GC_ATTR_NONNULL(1);
#else
# define GC_call_with_reader_lock(fn, cd, r) ((void)(r), (fn)(cd))
#endif

/* These routines are intended to explicitly notify the collector */
/* of new threads. Often this is unnecessary because thread creation */
Expand Down
45 changes: 23 additions & 22 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2172,28 +2172,6 @@ GC_API unsigned GC_CALL GC_new_proc(GC_mark_proc proc)
return result;
}

GC_API void *GC_CALL GC_call_with_reader_lock(GC_fn_type fn,
void *client_data, int release)
{
void *result;

READER_LOCK();
result = fn(client_data);
# ifdef HAS_REAL_READER_LOCK
if (release) {
READER_UNLOCK_RELEASE();
# ifdef LINT2
GC_noop1((unsigned)release);
# endif
return result;
}
# else
UNUSED_ARG(release);
# endif
READER_UNLOCK();
return result;
}

GC_API void * GC_CALL GC_call_with_alloc_lock(GC_fn_type fn, void *client_data)
{
void * result;
Expand All @@ -2214,6 +2192,29 @@ GC_API void * GC_CALL GC_call_with_alloc_lock(GC_fn_type fn, void *client_data)
{
UNLOCK();
}

GC_API void *GC_CALL GC_call_with_reader_lock(GC_fn_type fn,
void *client_data,
int release)
{
void *result;

READER_LOCK();
result = fn(client_data);
# ifdef HAS_REAL_READER_LOCK
if (release) {
READER_UNLOCK_RELEASE();
# ifdef LINT2
GC_noop1((unsigned)release);
# endif
return result;
}
# else
UNUSED_ARG(release);
# endif
READER_UNLOCK();
return result;
}
#endif /* THREADS */

GC_API void * GC_CALL GC_call_with_stack_base(GC_stack_base_func fn, void *arg)
Expand Down

0 comments on commit 89a0bf4

Please sign in to comment.