home *** CD-ROM | disk | FTP | other *** search
- /*
- * Filename: thread.c
- * Created : Sat Dec 21 00:24:36 1991
- * Author : Vince DeMarco
- * <vince@whatnxt.cuc.ab.ca>
- */
-
- /*
- Copyright (C) 1990 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <strings.h>
-
- #define THREAD
- #include "thread.h"
- #include "Freeze.h"
-
- void buffer_put ( char *ch, buffer_t *buffer)
- {
- mutex_lock(&buffer->lock);
- /* Enter Critical Section */
- while (buffer->count == BUFFER_SIZE){ /* Check if buffer is full, if it is wait
- * until it has some space in it
- */
- condition_wait(&buffer->not_full, &buffer->lock);
- }
- ASSERT(0 <= buffer->count && buffer->count < BUFFER_SIZE);
- strncpy(buffer->buf[buffer->start],ch,BUFFER_WIDTH);
- buffer->start = (buffer->start + 1) % BUFFER_SIZE;
- buffer->count++;
- condition_signal(&buffer->not_empty);
- /* Exit Critical Section */
- mutex_unlock(&buffer->lock);
- }
-
- void buffer_get ( buffer_t *buffer, char *ch )
- {
- mutex_lock(&buffer->lock);
- /* Enter Critical Section */
- while (buffer->count == 0){ /* Check if the buffer is empty, if it is
- * wait until somestuff has been placed in
- * the buffer
- */
- condition_wait(&buffer->not_empty, &buffer->lock);
- }
- strcpy(ch,buffer->buf[buffer->end]);
- buffer->buf[buffer->end][0] = '\000';
- buffer->end = (buffer->end + 1) % BUFFER_SIZE;
- buffer->count--;
- condition_signal(&buffer->not_full);
- /* Exit Critical Section */
- mutex_unlock(&buffer->lock);
- }
-
- /* Consumer process ie: background thread */
- void consumer(buffer_t *buffer)
- {
- char current[BUFFER_WIDTH];
- char *temp;
- int err_ret;
-
- while(1){
- buffer_get(buffer,current);
- temp = rindex(current,'.');
-
- /* Add check of Defaults database to see if the user
- * want to use greedy Freeze
- */
- if ((temp != NULL) && (!strcmp(temp,".F"))) {
- err_ret = Freeze( (FREEZE_FORCE | FREEZE_MELT_FILE),current);
- }else{
- err_ret = Freeze( (FREEZE_FORCE | FREEZE_FREZ_FILE),current);
- }
- switch (err_ret) { /* Since the Appkit isn't thread safe i can't print
- * out any errors if err_ret != FREEZE_OKAY
- * maybe when v3.0 is out.
- */
- case FREEZE_FILEGONE :
- break;
- case FREEZE_NOFREEZE :
- break;
- case FREEZE_ALREADY :
- break;
- case FREEZE_NOSAVINGS:
- break;
- case FREEZE_NOTFROZEN:
- break;
- case FREEZE_NOTREG :
- break;
- case FREEZE_OTHERLINK:
- break;
- case FREEZE_CANTOPEN :
- break;
- case FREEZE_OKAY :
- default :
- break;
- }
- }
- }
-