Loading...
Searching...
No Matches
as_thread.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2022 Aerospike, Inc.
3 *
4 * Portions may be licensed to Aerospike, Inc. under one or more contributor
5 * license agreements.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8 * use this file except in compliance with the License. You may obtain a copy of
9 * the License at http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17#pragma once
18
19#include <pthread.h>
20#include <stdio.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#define AS_THREAD_NAME_MAX 16
27
28/**
29 * Assign thread name. Must be called in the thread to be named.
30 */
31static inline void
32as_thread_set_name(const char* name)
33{
34#if defined(__APPLE__)
35 pthread_setname_np(name);
36#else
37 pthread_setname_np(pthread_self(), name);
38#endif
39}
40
41/**
42 * Assign thread name with index suffix. Must be called in the thread to be named.
43 */
44static inline void
45as_thread_set_name_index(const char* name, uint32_t index)
46{
47 char buf[AS_THREAD_NAME_MAX];
48 snprintf(buf, sizeof(buf), "%s%u", name, index);
50}
51
52#ifdef __cplusplus
53} // end extern "C"
54#endif
static void as_thread_set_name(const char *name)
Definition as_thread.h:32
#define AS_THREAD_NAME_MAX
Definition as_thread.h:26
static void as_thread_set_name_index(const char *name, uint32_t index)
Definition as_thread.h:45