mirror of
https://github.com/Hizenberg469/C1-Linux_SYS_Prog-AS-.git
synced 2026-04-20 02:42:23 +03:00
Changes in Assignment 3
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,49 +0,0 @@
|
|||||||
#ifndef __GLTHREADS__
|
|
||||||
#define __GLTHREADS__
|
|
||||||
|
|
||||||
typedef struct glthread_node_ {
|
|
||||||
|
|
||||||
struct glthread_node_ *left;
|
|
||||||
struct glthread_node_ *right;
|
|
||||||
} glthread_node_t;
|
|
||||||
|
|
||||||
typedef struct glthread_ {
|
|
||||||
|
|
||||||
glthread_node_t *head;
|
|
||||||
unsigned int offset;
|
|
||||||
} glthread_t;
|
|
||||||
|
|
||||||
void
|
|
||||||
glthread_add (glthread_t *lst, glthread_node_t *glnode);
|
|
||||||
|
|
||||||
void
|
|
||||||
glthread_remove(glthread_t *lst, glthread_node_t *glnode);
|
|
||||||
|
|
||||||
/*Iterative macro to Iterate Over GLTHhreads*/
|
|
||||||
#define ITERATE_GL_THREADS_BEGIN(lstptr, struct_type, ptr) \
|
|
||||||
{ \
|
|
||||||
glthread_node_t *_glnode = NULL, *_next = NULL; \
|
|
||||||
for(_glnode = lstptr->head; _glnode; _glnode = _next){ \
|
|
||||||
_next = _glnode->right; \
|
|
||||||
ptr = (struct_type *)((char *)_glnode - lstptr->offset);
|
|
||||||
|
|
||||||
#define ITERATE_GL_THREADS_ENDS }}
|
|
||||||
|
|
||||||
#define glthread_node_init(glnode) \
|
|
||||||
glnode->left = NULL; \
|
|
||||||
glnode->right = NULL;
|
|
||||||
|
|
||||||
void
|
|
||||||
init_glthread(glthread_t *glthread, unsigned int offset);
|
|
||||||
|
|
||||||
#define offsetof(struct_name, field_name) \
|
|
||||||
((unsigned long)&((struct_name *)0)->field_name)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define glthread_to_object(fn_name,struct_name,field_name) \
|
|
||||||
static inline struct_name *fn_name(glthread_node_t *field_name){ \
|
|
||||||
return (struct_name *)((unsigned int *)field_name - offsetof(struct_name, field_name)); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* __GLTHREADS__ */
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* =====================================================================================
|
|
||||||
*
|
|
||||||
* Filename: main.c
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
*
|
|
||||||
* Version: 1.0
|
|
||||||
* Created: 08/02/24 08:27:48 AM IST
|
|
||||||
* Revision: none
|
|
||||||
* Compiler: gcc
|
|
||||||
*
|
|
||||||
* Author: YOUR NAME (),
|
|
||||||
* Organization:
|
|
||||||
*
|
|
||||||
* =====================================================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "glthread.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <memory.h>
|
|
||||||
|
|
||||||
typedef struct emp_ {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char name[30];
|
|
||||||
|
|
||||||
unsigned int salary;
|
|
||||||
|
|
||||||
char designation[30];
|
|
||||||
|
|
||||||
unsigned int emp_id;
|
|
||||||
|
|
||||||
glthread_node_t glnode;
|
|
||||||
|
|
||||||
} emp_t ;
|
|
||||||
|
|
||||||
/*Function to print employee details*/
|
|
||||||
|
|
||||||
void
|
|
||||||
print_employee_info(emp_t *emp){
|
|
||||||
|
|
||||||
printf("Employee name = %s\n", emp->name);
|
|
||||||
|
|
||||||
printf("salary = %u\n", emp->salary);
|
|
||||||
|
|
||||||
printf("designation = %s\n", emp->designation);
|
|
||||||
|
|
||||||
printf("emp_id = %u\n", emp->emp_id);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
print_employee_details( glthread_node_t *glnode){
|
|
||||||
|
|
||||||
emp_t *emp = (emp_t *)((unsigned long)glnode - offsetof(emp_t,glnode));
|
|
||||||
|
|
||||||
print_employee_info(emp);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main( int argc , char** argv ){
|
|
||||||
|
|
||||||
/*Creating one employee object*/
|
|
||||||
|
|
||||||
emp_t *emp1 = calloc(1, sizeof(emp_t));
|
|
||||||
|
|
||||||
strncpy(emp1->name, "Neha", strlen("Neha"));
|
|
||||||
|
|
||||||
emp1->salary = 50000;
|
|
||||||
|
|
||||||
strncpy(emp1->designation, "HR", strlen("HR"));
|
|
||||||
|
|
||||||
emp1->emp_id = 21;
|
|
||||||
|
|
||||||
glthread_node_init((&emp1->glnode));
|
|
||||||
|
|
||||||
print_employee_details((&emp1->glnode));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
2225
Assignment3/main.i
2225
Assignment3/main.i
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Reference in New Issue
Block a user