|
Packit |
b55c50 |
/*
|
|
Packit |
b55c50 |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit |
b55c50 |
*
|
|
Packit |
b55c50 |
* This program is free software; you can redistribute it and/or
|
|
Packit |
b55c50 |
* modify it under the terms of the GNU General Public License
|
|
Packit |
b55c50 |
* as published by the Free Software Foundation; either version 2
|
|
Packit |
b55c50 |
* of the License, or (at your option) any later version.
|
|
Packit |
b55c50 |
*
|
|
Packit |
b55c50 |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
b55c50 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
b55c50 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
b55c50 |
* GNU General Public License for more details.
|
|
Packit |
b55c50 |
*
|
|
Packit |
b55c50 |
* You should have received a copy of the GNU General Public License
|
|
Packit |
b55c50 |
* along with this program; if not, write to the Free Software
|
|
Packit |
b55c50 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit |
b55c50 |
* 02110-1301, USA.
|
|
Packit |
b55c50 |
*
|
|
Packit |
b55c50 |
* $Id: //eng/uds-releases/jasper/kernelLinux/uds/threadRegistry.h#1 $
|
|
Packit |
b55c50 |
*/
|
|
Packit |
b55c50 |
|
|
Packit |
b55c50 |
#ifndef THREAD_REGISTRY_H
|
|
Packit |
b55c50 |
#define THREAD_REGISTRY_H 1
|
|
Packit |
b55c50 |
|
|
Packit |
b55c50 |
#include <linux/list.h>
|
|
Packit |
b55c50 |
#include <linux/spinlock.h>
|
|
Packit |
b55c50 |
|
|
Packit |
b55c50 |
/*
|
|
Packit |
b55c50 |
* We don't expect this set to ever get really large, so a linked list
|
|
Packit |
b55c50 |
* is adequate.
|
|
Packit |
b55c50 |
*/
|
|
Packit |
b55c50 |
|
|
Packit |
b55c50 |
typedef struct threadRegistry {
|
|
Packit |
b55c50 |
struct list_head links;
|
|
Packit |
b55c50 |
rwlock_t lock;
|
|
Packit |
b55c50 |
} ThreadRegistry;
|
|
Packit |
b55c50 |
|
|
Packit |
b55c50 |
typedef struct registeredThread {
|
|
Packit |
b55c50 |
struct list_head links;
|
|
Packit |
b55c50 |
const void *pointer;
|
|
Packit |
b55c50 |
struct task_struct *task;
|
|
Packit |
b55c50 |
} RegisteredThread;
|
|
Packit |
b55c50 |
|
|
Packit |
b55c50 |
/*****************************************************************************/
|
|
Packit |
b55c50 |
|
|
Packit |
b55c50 |
/**
|
|
Packit |
b55c50 |
* Initialize a registry of threads and associated data pointers.
|
|
Packit |
b55c50 |
*
|
|
Packit |
b55c50 |
* @param registry The registry to initialize
|
|
Packit |
b55c50 |
**/
|
|
Packit |
b55c50 |
void initializeThreadRegistry(ThreadRegistry *registry);
|
|
Packit |
b55c50 |
|
|
Packit |
b55c50 |
/**
|
|
Packit |
b55c50 |
* Register the current thread and associate it with a data pointer.
|
|
Packit |
b55c50 |
*
|
|
Packit |
b55c50 |
* This call will log messages if the thread is already registered.
|
|
Packit |
b55c50 |
*
|
|
Packit |
b55c50 |
* @param registry The thread registry
|
|
Packit |
b55c50 |
* @param newThread RegisteredThread structure to use for the current thread
|
|
Packit |
b55c50 |
* @param pointer The value to associated with the current thread
|
|
Packit |
b55c50 |
**/
|
|
Packit |
b55c50 |
void registerThread(ThreadRegistry *registry,
|
|
Packit |
b55c50 |
RegisteredThread *newThread,
|
|
Packit |
b55c50 |
const void *pointer);
|
|
Packit |
b55c50 |
|
|
Packit |
b55c50 |
/**
|
|
Packit |
b55c50 |
* Remove the registration for the current thread.
|
|
Packit |
b55c50 |
*
|
|
Packit |
b55c50 |
* A message may be logged if the thread was not registered.
|
|
Packit |
b55c50 |
*
|
|
Packit |
b55c50 |
* @param registry The thread registry
|
|
Packit |
b55c50 |
**/
|
|
Packit |
b55c50 |
void unregisterThread(ThreadRegistry *registry);
|
|
Packit |
b55c50 |
|
|
Packit |
b55c50 |
/**
|
|
Packit |
b55c50 |
* Fetch a pointer that may have been registered for the current
|
|
Packit |
b55c50 |
* thread. If the thread is not registered, a null pointer is
|
|
Packit |
b55c50 |
* returned.
|
|
Packit |
b55c50 |
*
|
|
Packit |
b55c50 |
* @param registry The thread registry
|
|
Packit |
b55c50 |
*
|
|
Packit |
b55c50 |
* @return the registered pointer, if any, or NULL
|
|
Packit |
b55c50 |
**/
|
|
Packit |
b55c50 |
const void *lookupThread(ThreadRegistry *registry);
|
|
Packit |
b55c50 |
|
|
Packit |
b55c50 |
#endif /* THREAD_REGISTRY_H */
|