-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththread_object.c
More file actions
55 lines (45 loc) · 1012 Bytes
/
thread_object.c
File metadata and controls
55 lines (45 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* Created: thread_object.c
* PROGRAMMING ASSIGNMENT 2
* CMPS 111 Spring 2013
* Authors: Andrew Bao, Konstantin Litovskiy, Tyler Esser & Nick Wood
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "thread_object.h"
typedef struct ThreadObject {
ucontext_t context;
int id;
int priority;
} ThreadObject;
/* Constructor */
TORef newThread(ucontext_t initCtx, int initID, int initPriority){
/* Allocate memory for the new thread objects */
TORef thread = malloc(sizeof(ThreadObject));
time_t tmpTime;
time(&tmpTime);
/* Set thread data values */
thread->context = initCtx;
thread->id = initID;
thread->priority = initPriority;
return(thread);
}
/* destructor */
void freeThread(TORef T){
TORef * pT = &T;
if(*pT != NULL && pT != NULL){
free(*pT);
*pT = NULL;
}
}
/* Accessors */
ucontext_t getContext(TORef T){
return T->context;
}
int getID(TORef T){
return T->id;
}
int getPriority(TORef T){
return T->priority;
}