This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Mysterious syntax error


Apologies in advance if this is a *really* stupid question.  I'm trying
to compile the code below on Fedora Core 3 (gcc-3.4.2-6.fc3), and it's
telling me I've got a syntax error that I just can't see.

[pilcher@home temp]$ gcc -c aarg.c
aarg.c: In function `alarm_thread':
aarg.c:82: error: syntax error at end of input

I've stared at this long enough to know that, if there is an error in
the code, I'm not going to find it.  I'd really appreciate it if someone
with smarter eyes could take a look.

Thanks!


#include <stdlib.h> #include <signal.h> #include <errno.h>

#include <unistd.h>
#include <pthread.h>
#include <sys/time.h>

typedef struct pt_alarm_s   	pt_alarm_t;
typedef struct pt_alarmattr_s 	pt_alarmattr_t;


enum pt_alarm_state { PT_ALARM_IDLE, PT_ALARM_SET, PT_ALARM_RUNNING, PT_ALARM_CANCELED, PT_ALARM_ERROR };

struct pt_alarm_s
{
    pthread_t	    	    target_tid;
    pthread_t	    	    alarm_tid;

    pthread_mutex_t 	    mutex;
    pthread_cond_t  	    cond;
    struct timespec    	    timeout;
    enum pt_alarm_state     state;
};

struct pt_alarmattr_s
{
    unsigned char   filler[1];
};


/*********************************************************************** * * alarm thread * **********************************************************************/

static void cleanup_alarm_mutex(void *arg)
{
    pt_alarm_t	*const alarm = arg;

    pthread_mutex_unlock(&alarm->mutex);
}

static void *alarm_thread(void *arg)
{
    pt_alarm_t	*const alarm = arg;

    pthread_cleanup_push(cleanup_alarm_mutex, arg);
    pthread_mutex_lock(&alarm->mutex);

    while (1)
    {
    	int 	pt_errno;

	while (alarm->state != PT_ALARM_SET)
    	     pthread_cond_wait(&alarm->cond, &alarm->mutex);
	
	alarm->state = PT_ALARM_RUNNING;
	
	pt_errno = 0;
	
	while (alarm->state != PT_ALARM_CANCELED &&
	    	pt_errno != ETIMEDOUT)
	{
	    pt_errno = pthread_cond_timedwait(&alarm->cond,
	    	    &alarm->mutex, &alarm->timeout);
	}
	
	if (alarm->state != PT_ALARM_CANCELED)
	    pthread_kill(alarm->target_tid, SIGALRM);
    }

    return NULL;    /* should never get here! */
}

--
========================================================================
Ian Pilcher                                        i.pilcher@comcast.net
========================================================================


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]