#include <sys/types.h>
#define __USE_UNIX98
#include <pthread.h>
+#include <semaphore.h>
#include <stdio.h>
#include <string.h>
/* FRSH files */
+#include "frsh_cpp_macros.h"
#include "fosa.h"
+#include "frsh_core_types.h"
#include "frsh_error.h"
/* AQuoSA files */
#include "timespec_usec_ops.h"
static int aqcpu_initialized = 0; /* initialization flag */
+
/*
* Test whether Aquosa Cpu modue is initialized
- *
*/
-
static inline int aqcpu_is_initialized()
{
return (aqcpu_initialized == 1);
* code... For now it only calls the cleanup function of the AQuoSA
* Framework
*/
-static void aqcpu_cleanup_wrapper() {
- return qres_cleanup();
+static inline void aqcpu_cleanup_wrapper() {
+ qres_cleanup();
}
/*
* FRSH_ERR_INTERNAL_ERROR (something, different from the previous case, gone wrong)
*/
-
int aqcpu_init()
{
/* check FRSH is not already initialized */
/* check if the name service is available and ty to start it if not */
/* (try to) initialize the AQuoSA Framework */
if (qres_init() != QOS_OK || qsup_init() != QOS_OK)
- FRSH_ERR_RET(FRSH_ERR_INTERNAL_ERROR);
+ return(FRSH_ERR_INTERNAL_ERROR);
/* install the cleanup function of th AQuoSA framework as an exit
* handler function (quite futile but, for now, it's sufficent) */
if (atexit(aqcpu_cleanup_wrapper))
- FRSH_ERR_RET(FRSH_ERR_INTERNAL_ERROR);
+ return(FRSH_ERR_INTERNAL_ERROR);
return FRSH_NO_ERROR;
}
-
/*
* frsh_thread_bind(), create a new thread and bind it to a vres
* frsh_thread_create_in_background(), create a new thread and a new BACKGROUND contract and bind them
frsh_thread_code_t pthread_code;
void *pthread_arg;
sem_t *stopper;
+ int errcode;
} wrapper_pthread_arg_t;
/*
*/
static void* wrapper_pthread(void *arg)
{
- int rv;
-
wrapper_pthread_arg_t pth = *((wrapper_pthread_arg_t*) arg);
sem_wait(pth.stopper);
+ if (pth.errcode) /* vres binding was not successful */
+ return NULL;
/* (pth.thread_id) = fosa_thread_self(); */
return pth.pthread_code(pth.pthread_arg);
}
"can't create a thread with NULL thread_core or return it in a NULL thread");
*/
- wp.thread_code = thread_code;
- wp.thread_arg = arg;
+ wp.pthread_code = thread_code;
+ wp.pthread_arg = arg;
wp.stopper = &stopper;
/* create the wrapper thread */
rv = fosa_thread_create(thread, attr, wrapper_pthread, (void*)&wp);
if (rv != 0)
- FRSH_ERR_RET(rv);
-
- rv = frsh_thread_bind();
- if ( rv != FRSH_NO_ERROR) {
- FRSH_ERR_RET(FRSH_ERR_INVALID_SCHEDULER_REPLY);
- }
+ return(rv);
+ rv = frsh_thread_bind(vres, *thread);
+ wp.errcode = rv;
sem_post(&stopper);
- return FRSH_NO_ERROR;
+ return rv;
}
/*
--- /dev/null
+#ifndef __TIMESPEC_USEC_OPS_H__
+#define __TIMESPEC_USEC_OPS_H__
+
+/*
+ * timespec_usec_ops.h
+ *
+ * ...
+ */
+
+#include <time.h>
+
+#define equal_timespec(t1, t2) \
+ ( ( (t1)->tv_sec == (t2)->tv_sec ) && ( (t1)->tv_nsec == (t2)->tv_nsec ) )
+
+#define increment_timespec(t) \
+do { \
+ (t)->tv_nsec ++; \
+ if ((t)->tv_nsec >= 1000000000UL) { \
+ (t)->tv_sec ++; \
+ (t)->tv_nsec -= 1000000000UL; \
+ } \
+} while(0)
+
+#define decrement_timespec(t) \
+do { \
+ if ( (t)->tv_nsec == 0) { \
+ (t)->tv_nsec = 1000000000UL; \
+ (t)->tv_sec --; \
+ } \
+ else \
+ (t)->tv_nsec --; \
+} while(0)
+
+#define sum_timespec(t1, t2, ts) \
+do { \
+ (ts)->tv_sec = (t1)->tv_sec + (t2)->tv_sec; \
+ (ts)->tv_nsec = (t1)->tv_nsec + (t2)->tv_nsec; \
+ while ( (ts)->tv_nsec >= 1000000000UL) { \
+ (ts)->tv_sec ++; \
+ (ts)->tv_nsec -= 1000000000UL; \
+ } \
+} while(0)
+
+#define sub_timespec(t1, t2, ts) \
+do { \
+ if ( (t2)->tv_sec < (t1)->tv_sec || \
+ ((t2)->tv_sec == (t1)->tv_nsec && (t2)->tv_nsec < (t1)->tv_nsec) ) { \
+ (ts)->tv_sec = (t1)->tv_sec - (t2)->tv_sec; \
+ (ts)->tv_nsec = (t1)->tv_nsec - (t2)->tv_sec; \
+ while ( (ts)->tv_nsec < 0) { \
+ (ts)->tv_sec --; \
+ (ts)->tv_nsec = (ts)->tv_nsec + 1000000000UL; \
+ } \
+ } else { \
+ (ts)->tv_sec = 0UL; \
+ (ts)->tv_nsec = 0UL; \
+ } \
+} while(0)
+
+#define zero_timespec(t) \
+do { \
+ (t)->tv_sec = 0; \
+ (t)->tv_nsec = 0; \
+} while(0)
+
+#define is_zero_timespec(t) \
+( (t)->tv_sec == 0 && (t)->tv_nsec == 0 )
+
+#endif /* __TIMESPEC_USEC_OPS_H__ */