You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
726 B
39 lines
726 B
4 years ago
|
/*
|
||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||
|
*
|
||
|
* This source code is licensed under the MIT license found in the
|
||
|
* LICENSE file in the root directory of this source tree.
|
||
|
*/
|
||
|
|
||
|
#ifndef TREIBER_STACK
|
||
|
#define TREIBER_STACK
|
||
|
|
||
|
#include <stdatomic.h>
|
||
|
#include <stdbool.h>
|
||
|
|
||
|
/**
|
||
|
* Treiber, R.K.: Systems programming: Coping with parallelism. Technical Report
|
||
|
* RJ 5118, IBM Almaden Research Center (1986)
|
||
|
*/
|
||
|
|
||
|
typedef int data_type;
|
||
|
#define EMPTY -1
|
||
|
|
||
|
typedef struct node_t {
|
||
|
data_type d;
|
||
|
struct node_t* n;
|
||
|
} node;
|
||
|
|
||
|
typedef struct stack_t {
|
||
|
_Atomic(node*) top;
|
||
|
} stack;
|
||
|
|
||
|
void init_stack(stack* s);
|
||
|
void push(stack* s, data_type v);
|
||
|
data_type pop(stack* s);
|
||
|
|
||
|
int unsafe_size(stack* s);
|
||
|
void print(stack* s);
|
||
|
|
||
|
#endif
|