Skip to content

Remove protos and folding marks from .c files #5532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
107 changes: 53 additions & 54 deletions TSRM/TSRM.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ TSRM_TLS uint8_t is_thread_shutdown = 0;

/* Startup TSRM (call once for the entire process) */
TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, char *debug_filename)
{/*{{{*/
{
#if defined(TSRM_WIN32)
tls_key = TlsAlloc();
#else
Expand Down Expand Up @@ -159,12 +159,12 @@ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debu
tsrm_env_mutex = tsrm_mutex_alloc();

return 1;
}/*}}}*/
}


/* Shutdown TSRM (call once for the entire process) */
TSRM_API void tsrm_shutdown(void)
{/*{{{*/
{
int i;

if (is_thread_shutdown) {
Expand Down Expand Up @@ -224,21 +224,20 @@ TSRM_API void tsrm_shutdown(void)

tsrm_reserved_pos = 0;
tsrm_reserved_size = 0;
}/*}}}*/
}

/* {{{ */
/* environ lock api */
TSRM_API void tsrm_env_lock() {
tsrm_mutex_lock(tsrm_env_mutex);
}

TSRM_API void tsrm_env_unlock() {
tsrm_mutex_unlock(tsrm_env_mutex);
} /* }}} */
}

/* enlarge the arrays for the already active threads */
static void tsrm_update_active_threads(void)
{/*{{{*/
{
int i;

for (i=0; i<tsrm_tls_table_size; i++) {
Expand All @@ -264,12 +263,12 @@ static void tsrm_update_active_threads(void)
p = p->next;
}
}
}/*}}}*/
}


/* allocates a new thread-safe-resource id */
TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor)
{/*{{{*/
{
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Obtaining a new resource id, %d bytes", size));

tsrm_mutex_lock(tsmm_mutex);
Expand Down Expand Up @@ -302,20 +301,20 @@ TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate

TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Successfully allocated new resource id %d", *rsrc_id));
return *rsrc_id;
}/*}}}*/
}


/* Reserve space for fast thread-safe-resources */
TSRM_API void tsrm_reserve(size_t size)
{/*{{{*/
{
tsrm_reserved_pos = 0;
tsrm_reserved_size = TSRM_ALIGNED_SIZE(size);
}/*}}}*/
}


/* allocates a new fast thread-safe-resource id */
TSRM_API ts_rsrc_id ts_allocate_fast_id(ts_rsrc_id *rsrc_id, size_t *offset, size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor)
{/*{{{*/
{
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Obtaining a new fast resource id, %d bytes", size));

tsrm_mutex_lock(tsmm_mutex);
Expand Down Expand Up @@ -360,11 +359,11 @@ TSRM_API ts_rsrc_id ts_allocate_fast_id(ts_rsrc_id *rsrc_id, size_t *offset, siz

TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Successfully allocated new resource id %d", *rsrc_id));
return *rsrc_id;
}/*}}}*/
}


static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_T thread_id)
{/*{{{*/
{
int i;

TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Creating data structures for thread %x", thread_id));
Expand Down Expand Up @@ -404,12 +403,12 @@ static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_
}

tsrm_mutex_unlock(tsmm_mutex);
}/*}}}*/
}


/* fetches the requested resource for the current thread */
TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id)
{/*{{{*/
{
THREAD_T thread_id;
int hash_value;
tsrm_tls_entry *thread_resources;
Expand Down Expand Up @@ -467,12 +466,12 @@ TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id)
* changes to the structure as we read it.
*/
TSRM_SAFE_RETURN_RSRC(thread_resources->storage, id, thread_resources->count);
}/*}}}*/
}


/* frees all resources allocated for the current thread */
void ts_free_thread(void)
{/*{{{*/
{
tsrm_tls_entry *thread_resources;
int i;
THREAD_T thread_id = tsrm_thread_id();
Expand Down Expand Up @@ -513,11 +512,11 @@ void ts_free_thread(void)
thread_resources = thread_resources->next;
}
tsrm_mutex_unlock(tsmm_mutex);
}/*}}}*/
}

/* deallocates all occurrences of a given id */
void ts_free_id(ts_rsrc_id id)
{/*{{{*/
{
int i;
int j = TSRM_UNSHUFFLE_RSRC_ID(id);

Expand Down Expand Up @@ -548,7 +547,7 @@ void ts_free_id(ts_rsrc_id id)
tsrm_mutex_unlock(tsmm_mutex);

TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Successfully freed resource id %d", id));
}/*}}}*/
}


/*
Expand All @@ -557,18 +556,18 @@ void ts_free_id(ts_rsrc_id id)

/* Obtain the current thread id */
TSRM_API THREAD_T tsrm_thread_id(void)
{/*{{{*/
{
#ifdef TSRM_WIN32
return GetCurrentThreadId();
#else
return pthread_self();
#endif
}/*}}}*/
}


/* Allocate a mutex */
TSRM_API MUTEX_T tsrm_mutex_alloc(void)
{/*{{{*/
{
MUTEX_T mutexp;
#ifdef TSRM_WIN32
mutexp = malloc(sizeof(CRITICAL_SECTION));
Expand All @@ -581,12 +580,12 @@ TSRM_API MUTEX_T tsrm_mutex_alloc(void)
printf("Mutex created thread: %d\n",mythreadid());
#endif
return( mutexp );
}/*}}}*/
}


/* Free a mutex */
TSRM_API void tsrm_mutex_free(MUTEX_T mutexp)
{/*{{{*/
{
if (mutexp) {
#ifdef TSRM_WIN32
DeleteCriticalSection(mutexp);
Expand All @@ -599,78 +598,78 @@ TSRM_API void tsrm_mutex_free(MUTEX_T mutexp)
#ifdef THR_DEBUG
printf("Mutex freed thread: %d\n",mythreadid());
#endif
}/*}}}*/
}


/*
Lock a mutex.
A return value of 0 indicates success
*/
TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp)
{/*{{{*/
{
TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Mutex locked thread: %ld", tsrm_thread_id()));
#ifdef TSRM_WIN32
EnterCriticalSection(mutexp);
return 0;
#else
return pthread_mutex_lock(mutexp);
#endif
}/*}}}*/
}


/*
Unlock a mutex.
A return value of 0 indicates success
*/
TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp)
{/*{{{*/
{
TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Mutex unlocked thread: %ld", tsrm_thread_id()));
#ifdef TSRM_WIN32
LeaveCriticalSection(mutexp);
return 0;
#else
return pthread_mutex_unlock(mutexp);
#endif
}/*}}}*/
}

/*
Changes the signal mask of the calling thread
*/
#ifdef HAVE_SIGPROCMASK
TSRM_API int tsrm_sigmask(int how, const sigset_t *set, sigset_t *oldset)
{/*{{{*/
{
TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Changed sigmask in thread: %ld", tsrm_thread_id()));

return pthread_sigmask(how, set, oldset);
}/*}}}*/
}
#endif


TSRM_API void *tsrm_set_new_thread_begin_handler(tsrm_thread_begin_func_t new_thread_begin_handler)
{/*{{{*/
{
void *retval = (void *) tsrm_new_thread_begin_handler;

tsrm_new_thread_begin_handler = new_thread_begin_handler;
return retval;
}/*}}}*/
}


TSRM_API void *tsrm_set_new_thread_end_handler(tsrm_thread_end_func_t new_thread_end_handler)
{/*{{{*/
{
void *retval = (void *) tsrm_new_thread_end_handler;

tsrm_new_thread_end_handler = new_thread_end_handler;
return retval;
}/*}}}*/
}


TSRM_API void *tsrm_set_shutdown_handler(tsrm_shutdown_func_t shutdown_handler)
{/*{{{*/
{
void *retval = (void *) tsrm_shutdown_handler;

tsrm_shutdown_handler = shutdown_handler;
return retval;
}/*}}}*/
}


/*
Expand All @@ -679,7 +678,7 @@ TSRM_API void *tsrm_set_shutdown_handler(tsrm_shutdown_func_t shutdown_handler)

#if TSRM_DEBUG
int tsrm_error(int level, const char *format, ...)
{/*{{{*/
{
if (level<=tsrm_error_level) {
va_list args;
int size;
Expand All @@ -694,12 +693,12 @@ int tsrm_error(int level, const char *format, ...)
} else {
return 0;
}
}/*}}}*/
}
#endif


void tsrm_error_set(int level, char *debug_filename)
{/*{{{*/
{
tsrm_error_level = level;

#if TSRM_DEBUG
Expand All @@ -716,16 +715,16 @@ void tsrm_error_set(int level, char *debug_filename)
tsrm_error_file = stderr;
}
#endif
}/*}}}*/
}

TSRM_API void *tsrm_get_ls_cache(void)
{/*{{{*/
{
return tsrm_tls_get();
}/*}}}*/
}

/* Returns offset of tsrm_ls_cache slot from Thread Control Block address */
TSRM_API size_t tsrm_get_ls_cache_tcb_offset(void)
{/*{{{*/
{
#if defined(__APPLE__) && defined(__x86_64__)
// TODO: Implement support for fast JIT ZTS code ???
return 0;
Expand All @@ -744,25 +743,25 @@ TSRM_API size_t tsrm_get_ls_cache_tcb_offset(void)
#else
return 0;
#endif
}/*}}}*/
}

TSRM_API uint8_t tsrm_is_main_thread(void)
{/*{{{*/
{
return in_main_thread;
}/*}}}*/
}

TSRM_API uint8_t tsrm_is_shutdown(void)
{/*{{{*/
{
return is_thread_shutdown;
}/*}}}*/
}

TSRM_API const char *tsrm_api_name(void)
{/*{{{*/
{
#if defined(TSRM_WIN32)
return "Windows Threads";
#else
return "POSIX Threads";
#endif
}/*}}}*/
}

#endif /* ZTS */
Loading