Thread Synch AOSV 2020
1.2
LKM for exchanging messages between threads
|
Go to the documentation of this file.
12 #ifndef THREAD_SYNCH_H
13 #define THREAD_SYNCH_H
22 #include <sys/types.h>
23 #include <sys/ioctl.h>
34 #define ATTR_BUFF_SIZE 64
35 #define DEVICE_NAME_SIZE 64
37 #define GROUP_CLASS_NAME "group_synch"
38 #define CLASS_NAME "thread_synch"
40 #define D_DEV_NAME "main_thread_sync"
41 #define D_DEV_MAJOR (0)
42 #define D_DEV_MINOR (0)
46 #define GRP_MAX_ID 255
50 #define NO_MSG_PRESENT 1
53 #define USER_COPY_ERR -3
54 #define SEM_INIT_ERR -4
55 #define MSG_INVALID_FORMAT -11
56 #define MSG_SIZE_ERROR -12
57 #define MEMORY_ERROR -13
58 #define STORAGE_SIZE_ERR -14
63 #define TS_NOT_FOUND -50
64 #define TS_OPEN_ERR -51
65 #define UNAUTHORIZED -52
66 #define PERMISSION_ERR -53
67 #define GROUP_CLOSED -54
72 #define POLL_TIMEOUT 5
73 #define PARAM_NUMBER 3
78 #define IOCTL_GET_GROUP_DESC _IOR('Q', 1, group_t*)
81 #define IOCTL_SET_SEND_DELAY _IOW('Y', 0, long)
82 #define IOCTL_REVOKE_DELAYED_MESSAGES _IO('Y', 1)
83 #define IOCTL_CANCEL_DELAY _IO('Y', 2)
86 #define IOCTL_SLEEP_ON_BARRIER _IO('Z', 0)
87 #define IOCTL_AWAKE_BARRIER _IO('Z', 1)
89 #define IOCTL_INSTALL_GROUP _IOW('X', 99, group_t*)
90 #define IOCTL_GET_GROUP_ID _IOW('X', 100, group_t*)
92 #define IOCTL_CHANGE_OWNER _IOW('Q', 102, uid_t)
93 #define IOCTL_SET_STRICT_MODE _IOW('Q', 101, bool)
147 static const char *param_default_path =
"/sys/class/group_synch/synch!group%d/group_parameters/";
148 static const char *group_default_path =
"/dev/synch/group%d";
155 int readGroupInfo(thread_synch_t *main_syncher);
159 int readMessage(
void *buffer,
size_t len, thread_group_t *group);
160 int writeMessage(
const void *buffer,
size_t len, thread_group_t *group);
162 int setDelay(
const long _delay, thread_group_t *group);
180 int changeOwner(thread_group_t *group,
const uid_t new_owner);
191 #endif //THREAD_SYNCH_H
int openGroup(thread_group_t *group)
Open a group, the thread PID is added to group's active members.
Definition: thread_synch.c:404
int disableStrictMode(thread_group_t *group)
Disable strict mode on a group.
Definition: thread_synch.c:833
unsigned int group_id
Definition: thread_synch.h:136
int awakeBarrier(thread_group_t *group)
Awake all the process present in a wait queue for a given group.
Definition: thread_synch.c:639
int enableStrictMode(thread_group_t *group)
Enable strict mode on a group.
Definition: thread_synch.c:808
User-level handler of the thread-synch main device.
Definition: thread_synch.h:118
thread_group_t * loadGroupFromID(const int group_id)
Load a group structure given a group ID.
Definition: thread_synch.c:1000
int revokeDelay(thread_group_t *group)
Revoke all the delayed messaged on a given group and deliver it.
Definition: thread_synch.c:599
unsigned long getMaxStorageSize(thread_group_t *group)
Get the maximum storage size value for a given group.
Definition: thread_synch.c:683
int setGarbageCollectorRatio(thread_group_t *group, unsigned long val)
Set the garbage collector ratio value for a given group.
Definition: thread_synch.c:783
int main_file_descriptor
Definition: thread_synch.h:119
int changeOwner(thread_group_t *group, const uid_t new_owner)
Change the owner of a group.
Definition: thread_synch.c:887
int initThreadSyncher(thread_synch_t *main_syncher)
Initialize a 'thread_synch_t' structure.
Definition: thread_synch.c:356
thread_group_t * loadGroupFromDescriptor(const group_t *descriptor, thread_synch_t *main_syncher)
Load a group's structure given a group descriptor.
Definition: thread_synch.c:927
int setDelay(const long _delay, thread_group_t *group)
Set the delay value for a given group.
Definition: thread_synch.c:579
void * buffer
Definition: types.h:45
group_t descriptor
Definition: thread_synch.h:135
int writeMessage(const void *buffer, size_t len, thread_group_t *group)
Write a message in a given group.
Definition: thread_synch.c:557
int setMaxMessageSize(thread_group_t *group, unsigned long val)
Set the maximum message size value for a given group.
Definition: thread_synch.c:739
int sleepOnBarrier(thread_group_t *group)
Put the process which call this function on sleep.
Definition: thread_synch.c:619
short initialized
Definition: thread_synch.h:124
pid_t author
Definition: types.h:44
int setMaxStorageSize(thread_group_t *group, unsigned long val)
Set the maximum storage size value for a given group.
Definition: thread_synch.c:761
size_t path_len
Definition: thread_synch.h:122
char * group_path
Definition: thread_synch.h:138
int includeStructureSize(thread_group_t *group, const bool value)
Set a flag to count also supporting structure size in storage calculation.
Definition: thread_synch.c:860
User-level handler of a group.
Definition: thread_synch.h:131
size_t path_len
Definition: thread_synch.h:139
unsigned long getMaxMessageSize(thread_group_t *group)
Get the maximum message size value for a given group.
Definition: thread_synch.c:659
Basic structure to represent a message.
Definition: types.h:43
size_t size
Definition: types.h:46
int file_descriptor
Definition: thread_synch.h:133
System-wide descriptor of a group.
Definition: types.h:139
unsigned long getCurrentStorageSize(thread_group_t *group)
Get the current storage size value for a given group.
Definition: thread_synch.c:710
int becomeOwner(thread_group_t *group)
Change the owner of a group to the calling thread's UID.
Definition: thread_synch.c:912
int readMessage(void *buffer, size_t len, thread_group_t *group)
Read a message from a given group.
Definition: thread_synch.c:524
int cancelDelay(thread_group_t *group)
Deliver immediately all delayed messages.
Definition: thread_synch.c:1054
thread_group_t * installGroup(const group_t group_descriptor, thread_synch_t *main_synch)
Install a group in the system given a group descriptor.
Definition: thread_synch.c:442
char * main_device_path
Definition: thread_synch.h:121